AddCommandHandler: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Automatyczna aktualizacja dokumentacji funkcji
 
Complete Lua function catalog
 
Line 34: Line 34:
* A command message is handled privately and is not broadcast as normal chat.
* A command message is handled privately and is not broadcast as normal chat.


[[Category:Lua Functions]]
[[Category:Server Functions]]
[[Category:Server Functions]]
[[Category:Command Functions]]
[[Category:Command Functions]]
[[Category:Chat Functions]]
[[Category:Chat Functions]]

Latest revision as of 09:52, 15 August 2026

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.