addCommandHandler
Client-side
Server-side
Shared
This page is incomplete! Help wanted!
Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.
This function will attach a scripting function (handler) to a console command, so that whenever a player or administrator uses the command the function is called.
Note
You can't use "check", "list", "test" and "help" as a command name.
Important
Do NOT use the same name for your handler function as the command name, as this can lead to confusion if multiple handler functions are used. Use a name that describes your handler's purpose more specifically.
Syntax
addCommandHandler ( )Code Examples
server
Example 1:This example defines a command handler for the commandcreatemarker. This will create a red marker at the position of the player player who uses it.
-- Define our function that will handle this commandfunction consoleCreateMarker ( playerSource, commandName ) -- If a player triggered it (rather than the admin) then if ( playerSource ) then -- Get that player's position local x, y, z = getElementPosition ( playerSource ) -- Create a size 2, red checkpoint marker at their position createMarker ( x, y, z, "checkpoint", 2, 255, 0, 0, 255 ) -- Output it in his chat box outputChatBox ( "You got a red marker", playerSource ) endend-- Attach the 'consoleCreateMarker' function to the "createmarker" commandaddCommandHandler ( "createmarker", consoleCreateMarker )See Also
Input Functions
- addCommandHandler
- bindKey
- executeCommandHandler
- getAnalogControlState
- getBoundKeys
- getCommandHandlers
- getCommandsBoundToKey
- getFunctionsBoundToKey
- getKeyBoundToCommand
- getKeyBoundToFunction
- getKeyState
- isCapsLockEnabled
- isControlEnabled
- isKeyBound
- removeCommandHandler
- setAnalogControlState
- toggleAllControls
- toggleControl
- unbindKey
Input Events
- onClientCharacter
- onClientClick
- onClientCursorMove
- onClientDoubleClick
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientKey
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
- onClientPaste