Custom Commands¶
The OnCommandManager hook lets you intercept custom commands. Return 1 to indicate the command was handled (block default processing), or 0 to pass through.
Basic Command Handler¶
local COMMAND_ONLINE = 100 -- Your custom command code
local function OnCommand(aIndex, code, arg)
if code == COMMAND_ONLINE then
-- Count online players
local count = 0
local startUser = OBJECT_START_USER()
local maxObj = MAX_OBJECT()
for i = startUser, maxObj - 1 do
if gObjIsConnectedGP(i) then
count = count + 1
end
end
GCNoticeSend(aIndex, 1, "Players online: " .. count)
return 1 -- Command handled
end
return 0 -- Not our command, pass through
end
BridgeFunctionAttach("OnCommandManager", OnCommand)
GM Teleport Command¶
local COMMAND_TELE = 101
local function OnCommand(aIndex, code, arg)
if code == COMMAND_TELE then
local player = GetUser(aIndex)
if player == nil then return 0 end
-- Only allow GMs (authority >= 32)
if player.Authority < 32 then
GCNoticeSend(aIndex, 1, "You don't have permission to use this command.")
return 1
end
-- Parse "map x y" from arg
local map, x, y = arg:match("(%d+)%s+(%d+)%s+(%d+)")
if map and x and y then
gObjTeleport(aIndex, tonumber(map), tonumber(x), tonumber(y))
GCNoticeSend(aIndex, 1, "Teleported to map " .. map)
else
GCNoticeSend(aIndex, 1, "Usage: /tele <map> <x> <y>")
end
return 1
end
return 0
end
BridgeFunctionAttach("OnCommandManager", OnCommand)
Player Info Command¶
local COMMAND_STATS = 102
local function OnCommand(aIndex, code, arg)
if code == COMMAND_STATS then
local player = GetUser(aIndex)
if player == nil then return 0 end
GCNoticeSend(aIndex, 1, "--- Your Stats ---")
GCNoticeSend(aIndex, 1, "STR: " .. player.Strength .. " DEX: " .. player.Dexterity)
GCNoticeSend(aIndex, 1, "VIT: " .. player.Vitality .. " ENE: " .. player.Energy)
GCNoticeSend(aIndex, 1, "Resets: " .. player.Reset .. " MR: " .. player.MasterReset)
GCNoticeSend(aIndex, 1, "Zen: " .. player.Money)
return 1
end
return 0
end
BridgeFunctionAttach("OnCommandManager", OnCommand)