Need a little help with this small variables problem (putting into a string)
#1

So I got this code:
Код:
CMD:orderproduct(playerid, params[])
{
	new
	    ProductID,
	    Product[128],
	    AmountDeProduct,
	    ProductSlot,
	    ProductPrice,
	    x,
	    string[128];
   	x = getPlayerBusinessID(playerid);
	if(playerVariables[playerid][pNormalName] == businessVariables[x][bOwner])
	{
	    if(sscanf(params, "dddd", ProductID, AmountDeProduct, ProductPrice, ProductSlot)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/orderproduct [Product ID] [Amount] [Product Price] [ProductSlot]");
		if(businessVariables[x][bType] == 1)
		{
			if(systemItems[ProductID][iType] > 5) return SendClientMessage(playerid, COLOR_GREY, "You can only order products from Type 1-5, check /itemslist to see which products you can order");
			if(ProductSlot == 1)
			{
				systemItems[ProductID][iName] = Product;
				Product = businessVariables[x][bProduct1];
			    businessVariables[x][bProductAmount1] = AmountDeProduct;
			    businessVariables[x][bProductPrice1] = ProductPrice;
			    saveBusiness(x);
                format(string, sizeof(string), "You have ordered [ %d ] of %s  on slot %d and set their price to $ %d", businessVariables[x][bProductAmount1], Product, ProductSlot, businessVariables[x][bProductPrice1]);
                SendClientMessage(playerid, COLOR_GREY, string);
			}
			else
			{
			    SendClientMessage(playerid, COLOR_GREY, "you dumb as hell");
			}
		}
	}
	else
	{
	    SendClientMessage(playerid, COLOR_GREY,"You do not own any businesses");
	}
	return 1;
}
But when doing it ingame all I get is:
"You have ordered [ 40 ] of"
and it stopts there. So there's something wrong with "Product" or %s. I can't really figure that so I hope someone can help me with it.
Reply
#2

pawn Код:
print(Product);
See the result.
Reply
#3

Tried it, but doesn't show anything IG and in server.exe it returned (null)
also tried print(systemItems[ProductID][iName]); and also returned (null)

but then tried this (removing the variables equalling eachother) And looked if the systemItems[ProductID][iName] actually worked, and it did. 'Cause it said: Beer, Cigar, Sprunk. (my 3 testers in the mySQL database)

so the problem really comes in when I equal the two or three like:
Код:
businessVariables[x][bProduct1] = systemItems[ProductID][iName];
or

Код:
systemItems[ProductID][iName] = Product;
Product = businessVariables[x][bProduct1];
Reply
#4

pawn Код:
systemItems[ProductID][iName] = Product;
Because you just create Product variable without setting it's value.
Reply
#5

Oh wait, think I messed up, I meant

Код:
Product = systemItems[ProductID][iName];
That way the value of Product will be set the same as systemItems[ProductID[iName] right?
but then I get (null)
Reply
#6

pawn Код:
format(Product, sizeof(Product), "%s", Product);
Give that a shot.
Reply
#7

Don't see why I should that, because the whole meaning of this thing is to set Product, the value of systemItems[ProductID][iName]. and formatting, would set the value of Product to that string message, inside the format, if I'm correct.
So in SendClientMessage you'd either get: the string message or "iName" (Cigar, Beer, Sprunk)
Reply
#8

Oh sorry, I wrote that wrong. Try
pawn Код:
format(Product, sizeof(Product), "%s", systemItems[ProductID][iName);
Reply
#9

Nevermind, thanks for helping though! I found the solution.

You can't compare 2 string variables. Just isn't made like that. to do that you have to use strmid

So final code:
Код:
CMD:orderproduct(playerid, params[])
{
	new
	    ProductID,
	    AmountDeProduct,
	    ProductSlot,
	    ProductPrice,
	    x,
	    string[128];
   	x = getPlayerBusinessID(playerid);
	if(playerVariables[playerid][pNormalName] == businessVariables[x][bOwner])
	{
	    if(sscanf(params, "dddd", ProductID, AmountDeProduct, ProductPrice, ProductSlot)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/orderproduct [Product ID] [Amount] [Product Price] [ProductSlot]");

		if(businessVariables[x][bType] == 1)
		{
			if(systemItems[ProductID][iType] > 5) return SendClientMessage(playerid, COLOR_GREY, "You can only order products from Type 1-5, check /itemslist to see which products you can order");
			if(ProductSlot == 1)
			{
				strmid(businessVariables[x][bProduct1], systemItems[ProductID][iName], false, 128, 128);

			    businessVariables[x][bProductAmount1] = AmountDeProduct;
			    businessVariables[x][bProductPrice1] = ProductPrice;
			    saveBusiness(x);
			    print(systemItems[ProductID][iName]);
                format(string, sizeof(string), "You have ordered [ %d ] of %s  on slot %d and set their price to $ %d", businessVariables[x][bProductAmount1], businessVariables[x][bProduct1], ProductSlot, businessVariables[x][bProductPrice1]);
                SendClientMessage(playerid, COLOR_GREY, string);
			}
			else
			{
			    SendClientMessage(playerid, COLOR_GREY, "you dumb as hell");
			}
		}
	}
Reply
#10

pawn Код:
strmid(businessVariables[x][bProduct1], systemItems[ProductID][iName], false, 128, 128);
??
https://sampwiki.blast.hk/wiki/Strmid
Actually you can just use strcat
https://sampwiki.blast.hk/wiki/Strcat

For compariong, use strcmp
https://sampwiki.blast.hk/wiki/Strcmp
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)