sm.game.bindChatCommand

Binds a chat command to a callback function. The callback function receives an array of parameters. The first parameter is the command itself.

Kind: Function

Environments: Game

Game

sm.game.bindChatCommand( command, params, callback, help )

Open the full Game reference

Example:

sm.game.bindChatCommand( "/enable_client_toilet",
                         { { "bool", "enabled", false } },
                         "onChatCommand",
                         "Enables or disables client toilet." )
function MyGameScript.onChatCommand( self, params )
    if params[1] == "/enable_client_toilet" then
        self.settings.enable_client_toilet = params[2]
    end
end

Parameters:

Name Type Description
command string The command.
params table An array of parameters the callback function expects in the form of { { type, name (, optional, autocomplete ) }, ... }. The first is the type name of the parameter as a string. Valid types are "bool", "int", "number" and "string". The second is the name in the help text. Defaults to automatic naming ("p1", "p2", "p3", ...). The third is a bool value where true means that this parameter is optional (Optional, defaults to false). The fourth is a list of values that can be auto-completed to by pressing tab (Optional).
callback string The name of the Lua function to bind.
help string Help text.