addCommandHandler

From GTA Connected
Jump to: navigation, search

Function Server and Client All Games Online and Offline

Server 1.0.0, Client 1.0.0

bool addCommandHandler(string command, function handler, [ bool replace = false ])

Description

The addCommandHandler function is used to set a function to call when a player types the specified command in-game.
Command names are case-insensitive.
If a function is already added for the command, the function is only set for the command if replace is bool true.

Parameters

Type Name Presence Default Value Description
string command required n/a The command name to be typed in-game in the chat box.
function handler required n/a The scripting function to be called when a player types the command in-game in the chat box.
bool replace optional false Whether to replace the handler for the command if one is already bound to the command.

Returns

Success Returns

Type Description
bool Whether the handler was bound to the command.

Failure Returns

Type Value
bool false

Callbacks

Server:
function(string command, string parameters, Client client)
Client:
function(string command, string parameters)

Notes

  • If replace is true, the existing callback function is replaced with the new callback function specified.

Examples

Example 1 - JavaScript - Server-Side:

addCommandHandler('test', function(command, text, client)
{
    console.log('test message'); // shown in server console
});


Example 2 - JavaScript - Client-Side:

addCommandHandler('test', function(command, text)
{
    console.log('test message'); // shown in client console
});

Compatibility

There isn't any compatibility information for this function.

Related

Server Related

addCommandHandler
consoleCommand
removeCommandHandler


Client Related

addCommandHandler
consoleCommand
removeCommandHandler