PDA

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


matje
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.

Konstantinos
05/12/2016, 06:43 PM
http://wiki.sa-mp.com/wiki/Control_Structures#Operators

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

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