OnPlayerCommandText
From SA-MP Wiki
OnPlayerCommandText
This callback is called when a player enters a command into the client chat window, e.g. /help.
(playerid,cmdtext[])
| playerid | The ID of the player that executed the command. |
| cmdtext[] | The command that was executed (includes the slash). |
| Returns | Returning 0 in this callback will pass the command to another script or display 'SERVER: Unknown command' if there are no scripts to pass it on to |
public OnPlayerCommandText(playerid, cmdtext[]) { if(!strcmp(cmdtext, "/help", true)) { SendClientMessage(playerid, 0xFFFFFFFF, "SERVER: This is the /help command!"); return 1; /* Returning '1' is used to notify the server that the command has successfully been processed. If you return true here you won't get that 'SERVER: Unknown Command.', and any conflicts will be avoided. */ } return 0; /* Returning '0' is used to inform the server that the command has not been successfully processed, and passes it to other scripts. If there hasn't been a successful process, then you will get that 'SERVER: Unknown Command.' error. */ }
Related Callbacks
The following callbacks might be useful as well, as they're related to this callback in one way or another.
- OnPlayerText: Called when a player sends a message via the chat.
- OnRconCommand: Called when an RCON command is sent.
Related Functions
The following functions might be useful, as they're related to this callback in one way or another.
- SendRconCommand: Sends an RCON command via the script.
- OnRconCommand: Called when an RCON command is sent.
