Can't get IF statement to work properly
#1

So I'm trying to make this command:

Код:
COMMAND:savemats(playerid, params[])
{
	new amount;

	if (sscanf(params, "i", amount))
		return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /savemats <amount>");
		
	if (amount <= PlayerInfo[playerid][Mats])
	    return SendClientMessage(playerid, 0xFFFFFFFF, "You don't have that much mats.");
    if (amount <= 0)
	    return SendClientMessage(playerid, 0xFFFFFFFF, "You can't save 0 or less mats.");

    new message[40];
	PlayerInfo[playerid][Mats] = PlayerInfo[playerid][Mats] - amount;
	format(message, sizeof(message), "You saved %d mats to the team safe.", amount);
	SendClientMessage(playerid, 0x00FF00FF, message);
	return 1;
}
So In game I give myself 200 mats and try /savemats 50, but it always responds with "You don't have that much mats." I'm sure I made a dumb mistake but I just can't find it.
Reply
#2

https://sampwiki.blast.hk/wiki/Control_Structures#Operators

You need to check if amount > Mats to return the error.
Reply
#3

Thank you sir, I knew I have made a dumb mistake :=)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)