Skip to content

OnPlayerCommandText

A / command - return true when the mode answered it.

/tp 1 2 3 arrives as cmd = "tp", args = "1 2 3": the word after the slash as typed (compare it lower-cased if you want to be lenient) and the rest of the line, trimmed. Return true to say the mode answered - even when the answer was “you may not”. Return false (or nothing) and the server’s built-in commands get the line, then Unknown command: /x. A mode takes a built-in over by answering its name; a /help that prints a line and returns false is followed by the server’s own list. Commands are never echoed to the chat.

function OnPlayerCommandText(pid, cmd, args)
-- ...
end
Parameter Type
pid number who typed it
cmd string the command without the slash, as typed
args string everything after the command, trimmed; "" when nothing

true = handled; false or nothing = the server’s built-ins, then “Unknown command”

function OnPlayerCommandText(pid, cmd, args)
if cmd == "help" then
SendClientMessage(pid, COLOUR_SERVER, "arena: /duel, /leave, /score")
return false -- the server appends its own list
elseif cmd == "duel" then
queue[#queue + 1] = pid
SendClientMessage(pid, COLOUR_SERVER, "queued (" .. #queue .. " waiting)")
return true
elseif cmd == "give" then
SendClientMessage(pid, COLOUR_RED, "No /give in the arena.")
return true -- the built-in /give never runs here
elseif cmd == "pay" then
local target, amount = sscanf(args, "ud") -- a player and a whole number, typed and checked in one line
if target == false then
SendClientMessage(pid, COLOUR_RED, "usage: /pay <player> <amount> (" .. amount .. ")")
return true
end
pay(pid, target, amount)
return true
end
return false
end

OnPlayerText · SendClientMessage · sscanf · GetPlayerId · IsPlayerAdmin · the Chat and commands group of the index