SA-MP Forums Archive
Can't get IF statement to work properly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Can't get IF statement to work properly (/showthread.php?tid=623807)



Can't get IF statement to work properly - matje - 05.12.2016

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.


Re: Can't get IF statement to work properly - Konstantinos - 05.12.2016

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

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


Re: Can't get IF statement to work properly - matje - 05.12.2016

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