addCommandHandler | Multi Theft Auto: Wiki Skip to content

addCommandHandler

Client-side
Server-side
Shared

Manual Review Required

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

bool addCommandHandler ( )

Returns

  • bool: value

Returns true if the command handler was added successfully, false otherwise.

Code Examples

client

Example 1:This example warps the local player to a random nearby location (useful for when a player gets stuck somewhere).

function escapeMe ( commandName )
local x, y, z = getElementPosition ( localPlayer ) --Get player's position
setElementPosition ( localPlayer, x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.
end
addCommandHandler ( "escape", escapeMe ) --When player types "/escape" in chatbox or "escape" in console