Purpose
Type /test 5 hello in the game and the player receives the line Hello <name>! number = 5, text = hello. The module is only a template for you to copy into your own command.
How to enable
- The command is already declared in
Data\Commands\LuaCommands.xml:<Command ID="2000" name="test" Description="" Authority="0"/>. - The line
LoadModule("CmdCommands\\Commands")inMain.lua(enabled by default). - Click Reload LuaAPI.
The module has no Config.lua and needs no SQL. The code file is Includes\CmdCommands\Commands.lua, which attaches the function Commands_OnCommandManager to OnCommandManager.
Adding a new command
- Add the line
<Command ID="..." name="..." Authority="0"/>toLuaCommands.xml.Authority = 0means everyone; non-0is only for administrator accounts that have the permission enabled. Choose anIDthat no module uses yet. - Handle that
IDin a function attached withBridgeFunctionAttach("OnCommandManager", ...). The function returns1when the command is its own,0when it is not. - Click Reload LuaAPI.
local CMD_TEST = 2000
function Commands_OnCommandManager(aIndex, cmdtype, code, arg)
if code ~= CMD_TEST then
return 0
end
local number = math.floor(Util.ArgNumber(arg, 0))
local text = Util.ArgString(arg, 1)
Message.Send(aIndex, 1, string.format("Hello %s! number = %d, text = %s", Player.GetName(aIndex), number, text))
return 1
end
BridgeFunctionAttach("OnCommandManager", "Commands_OnCommandManager")
A command that exists in
LuaCommands.xml but has the same name as a built-in server command will run the built-in command and never reach Lua. See Events.