04.12.2016, 17:50
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):
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:
But if for some reason you still want to use "i" or "d" then you can check if the player is invalid like that:
So the command should look like that:
Код:
if (!...) return... if (!...) return... ...all good, rest of the command here
Код:
if (toplayerid == INVALID_PLAYER_ID)
Код:
if (!IsPlayerConnected(toplayerid))
Код:
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; }