AddCommandHandler
Jump to navigation
Jump to search
addCommandHandler
Registers a server-side slash command handler for the current resource.
Syntax
bool addCommandHandler(string commandName, function handler)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
commandName |
string |
yes | Command name without the leading slash. |
handler |
function |
yes | Callback receiving player id, command name and string arguments. |
Returns
Returns true when the handler is registered; otherwise returns false.
Examples
Create a /heal command:
addCommandHandler("heal", function(playerId, commandName, amountText)
local amount = tonumber(amountText) or 10
addPlayerStat(playerId, "health", amount)
outputChatBox("You were healed by " .. amount, playerId)
end)
Notes
- Available only in server-side resource scripts.
- A command message is handled privately and is not broadcast as normal chat.