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

  1. The command is already declared in Data\Commands\LuaCommands.xml: <Command ID="2000" name="test" Description="" Authority="0"/>.
  2. The line LoadModule("CmdCommands\\Commands") in Main.lua (enabled by default).
  3. 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

  1. Add the line <Command ID="..." name="..." Authority="0"/> to LuaCommands.xml. Authority = 0 means everyone; non-0 is only for administrator accounts that have the permission enabled. Choose an ID that no module uses yet.
  2. Handle that ID in a function attached with BridgeFunctionAttach("OnCommandManager", ...). The function returns 1 when the command is its own, 0 when it is not.
  3. 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.