OnPlayerCommandText

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:53, 6 August 2017
OstGot (Talk | contribs)

← Previous diff
Current revision
OstGot (Talk | contribs)

Line 8: Line 8:
{{Returns|Return '''1''' if the command was processed, otherwise '''0'''; If the command was not found both in filterscripts and in gamemode, the player will be received a message: 'SERVER: Unknown command'. {{Returns|Return '''1''' if the command was processed, otherwise '''0'''; If the command was not found both in filterscripts and in gamemode, the player will be received a message: 'SERVER: Unknown command'.
-* It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it.}}+* It is always called first in filterscripts so returning 1 there blocks other scripts from seeing it.}}
{{Example}} {{Example}}

Current revision



Description:

This callback is called when a player enters a command into the client chat window. Commands are anything that start with a forward slash, e.g. /help.


Parameters:
(playerid, cmdtext[])
playeridThe ID of the player that entered a command.
cmdtext[]The command that was entered (including the forward slash).


Return Values:

Return 1 if the command was processed, otherwise 0; If the command was not found both in filterscripts and in gamemode, the player will be received a message: 'SERVER: Unknown command'.
  • It is always called first in filterscripts so returning 1 there blocks other scripts from seeing it.


Example Usage:

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/help", true))
    {
        SendClientMessage(playerid, -1, "SERVER: This is the /help command!");
        return 1;
        // Returning 1 informs the server that the command has been processed.
        // OnPlayerCommandText won't be called in other scripts.
    }
    return 0;
    // Returning 0 informs the server that the command hasn't been processed by this script.
    // OnPlayerCommandText will be called in other scripts until one returns 1.
    // If no scripts return 1, the 'SERVER: Unknown Command' message will be shown to the player.
}

Related Callbacks

The following callbacks might be useful as well, as they are related to this callback in one way or another.

  • OnPlayerText: Called when a player sends a message via the chat.


Related Functions

The following functions might be useful, as they're related to this callback in one way or another.

Personal tools