View Full Version : Can't get IF statement to work properly

05/12/2016, 06:28 PM
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.

05/12/2016, 06:43 PM

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

05/12/2016, 10:36 PM
Thank you sir, I knew I have made a dumb mistake :=)