M MY Multiplayer: Wiki
Side
Kind

addCommandHandler

Shared

Registers a function that runs when the command is typed in the console. The arguments arrive as space-separated strings.

bool addCommandHandler(string commandName, function handlerFunction)

Parameters

NameTypeDescription
commandNamestringThe command's name, without a slash. Case matters.
handlerFunctionfunctionThe function called. On the server it receives (player, command, ...), where the player is the console when the command comes from the server console. On the client it receives (command, ...).

Returns

true if it was registered. false if the name is empty or this resource already has a handler for that command.

Several resources can handle the same command, and all of them run. On the client, a command no client script handles is sent to the server, where onPlayerCommand fires before the handlers. A resource's handlers go away when it stops.

Example

addCommandHandler("vida", function(player, command, amount)
    local health = tonumber(amount)
    if health then
        setElementHealth(player, health)
    end
end)

See also