Givemoney command issue
#1

Guys, I got this command, and it compiles with no errors/warnings:

Код:
COMMAND:givemoney(playerid, params[])
{
	if (IsPlayerAdmin(playerid))
	{
		new
		  toplayerid,
		  amount;
		if (!sscanf(params, "ii", toplayerid, amount))
		{
		    new
		      message[40];
		    GivePlayerMoney(toplayerid, amount);
		    format(message, sizeof(message), "You got $%d from admin!", amount);
		    SendClientMessage(toplayerid, 0x00FF00FF, message);
		  }
		else SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");
	}
	else SendClientMessage(playerid, 0xFF0000FF, "Only admins can use this command!");
	return 1;
}
But in game, it always responds with "Usage: /givemoney <playerid> <amount>".
I'm using the command correctly in game: /givemoney 1 200
The admin check is working fine.

Could you please let me know if there is something wrong with the command? Thanks!
Reply
#2

First of all you should make your commands like that because it's easier to read (you don't need to, but it looks better in my opinion):
Код:
if (!...)
     return...

if (!...)
     return...

...all good, rest of the command here
Second use "u" specifier for toplayerid. "u" specifier is meant for players, you can either type in the id of the player or their name. Also check if the specified player is invalid like that:
Код:
if (toplayerid == INVALID_PLAYER_ID)
But if for some reason you still want to use "i" or "d" then you can check if the player is invalid like that:
Код:
if (!IsPlayerConnected(toplayerid))
So the command should look like that:
Код:
COMMAND:givemoney(playerid, params[])
{
	if (!IsPlayerAdmin(playerid))
		return SendClientMessage(playerid, 0xFF0000FF, "Only admins can use this command!");

	new toplayerid, amount;

	if (sscanf(params, "ui", toplayerid, amount))
		return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /givemoney <playerid> <amount>");

        if (toplayerid == INVALID_PLAYER_ID)
                return SendClientMessage(playerid, -1, "Invalid player.");

        GivePlayerMoney(toplayerid, amount);
	format(message, sizeof(message), "You got $%d from admin!", amount);
	SendClientMessage(toplayerid, 0x00FF00FF, message);
	return 1;
}
Reply
#3

Thanks for the help mate, the in game issue is still the same but now I'm getting responded with: sscanf error: System not initialised (in the console and server log file). I have sscanf2 in my includes folder and sscanf in my plugins folder, both linked in the gamemode and server config file. I'm going to look around the forum about this error, but if you know what is causing this please let me know.
Reply
#4

do you have the latest version of sscanf2?
Reply
#5

Update sscanf.
Reply
#6

Use #include sscanf not #include sscanf2 and itll be done.
Reply
#7

I have updated sscanf and it's working now. Thanks for all your help boys, have a great day!
Reply
#8

You're welcome!
Reply
#9

good to know that i helped you, enjoy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)