addCommandHandler

From GTA Connected
Revision as of 20:11, 8 May 2020 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Server and Client icon-iii.png icon-vc.png icon-sa.png icon-iv.png Online and Offline

Available since Server 1.0.0, Client 1.0.0

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

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

1) string command The command name to be typed in-game in the chat box.
2) function handler The scripting function to be called when a player types the command in-game in the chat box.
3) bool replace Optional, defaults to false. Whether to replace the handler for the command if one is already bound to the command.

Return

bool Whether the handler was bound to the command.

Callbacks

Server-Side Callbacks

function handler(string command, string parameters, Client client)

1) string command The command that was typed.
2) string parameters The parameters string that was typed.
3) Client client The client that typed the command.


Client-Side Callbacks

function handler(string command, string parameters)

1) string command The command that was typed.
2) string parameters The parameters string that was typed.


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

icon-iii.png icon-vc.png icon-sa.png icon-iv.png addCommandHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png consoleCommand
icon-iii.png icon-vc.png icon-sa.png icon-iv.png hasCommandHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png removeCommandHandler


Client Related

icon-iii.png icon-vc.png icon-sa.png icon-iv.png addCommandHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png consoleCommand
icon-iii.png icon-vc.png icon-sa.png icon-iv.png hasCommandHandler
icon-iii.png icon-vc.png icon-sa.png icon-iv.png removeCommandHandler