SA-MP Forums Archive
SSCANF - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SSCANF (/showthread.php?tid=77644)



SSCANF - Jefff - 13.05.2009

It's possible to do ? for example i have this cmd
Код:
dcmd_givecash(playerid, params[])
{
	new giveplayerid;
	new amount;
	
	if (sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
	else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
	else
	{
		GivePlayerMoney(giveplayerid, amount);
		GivePlayerMoney(playerid, 0 - amount);
		SendClientMessage(playerid, 0x00FF00AA, "Money sent");
		SendClientMessage(giveplayerid, 0x00FF00AA, "Money recieved");
	}
	return 1;
}
and I want /givecash [giveplayerid] [amount / all] and if if I write 'all' it get my all moneys and gives the id what I type?


Re: SSCANF - Weirdosport - 13.05.2009

Yes, let me just check what I used for this...

If you use an s instead of a d (string instead of integer), you can then strcmp this integer to see if it is "all". If it isn't, use strval on it to turn the string to a number, and use this number as you currently do.


Re: SSCANF - Jefff - 13.05.2009

But there isnt a other way to not use strval? because its bugged when someone write more [ than 49


Re: SSCANF - Weirdosport - 13.05.2009

Well you could have something to check if params = all (strcmp) before you get to the sscanf, then sscanf can have the same setup you have at the moment. The only problem I can see is that you have multiple params, and so you'll be looking for the word all amongst other stuff..

i.e if a play wanted to pay money to a guy called overall.. he might accidentally pay everything he owns..


Re: SSCANF - Ignas1337 - 21.05.2009

in that case it would be wise to use ids