addCommandHandler: Difference between revisions
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
|name = addCommandHandler | |name = addCommandHandler | ||
|usage = set a function to call when a player types the specified command in-game. | |usage = set a function to call when a player types the specified command in-game. | ||
|parameters = string command, function handler, [ bool replace = false ] | |parameters = string command, function handler, [ bool replace = false ] | ||
|parameter1 = string command The command name to be typed in-game in the chat box. | |parameter1 = string command The command name to be typed in-game in the chat box. | ||
Line 19: | Line 18: | ||
|callback2ParameterCS2 = string parameters The parameters string that was typed. | |callback2ParameterCS2 = 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. | |notes = If replace is true, the existing callback function is replaced with the new callback function specified. | ||
|note2 = Command names are case-insensitive.<br>If a function is already added for the command, the function is only set for the command if '''replace''' is '''bool true''' | |||
|exampleJSSS = addCommandHandler('test', function(command, text, client) | |exampleJSSS = addCommandHandler('test', function(command, text, client) | ||
{ | { |
Revision as of 22:28, 17 November 2022
Function
Server and Client
Online and Offline
bool addCommandHandler(string command, function handler, [ bool replace = false ])
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.
- 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.
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
hasCommandHandler
removeCommandHandler
Client Related
addCommandHandler
consoleCommand
hasCommandHandler
removeCommandHandler