Lệnh tùy chỉnh¶
Hook OnCommandManager cho phép bạn chặn các lệnh tùy chỉnh. Trả về 1 để chỉ ra lệnh đã được xử lý (chặn xử lý mặc định), hoặc 0 để cho qua.
Bộ xử lý lệnh cơ bản¶
local COMMAND_ONLINE = 100 -- Mã lệnh tùy chỉnh của bạn
local function OnCommand(aIndex, code, arg)
if code == COMMAND_ONLINE then
-- Đếm người chơi trực tuyến
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 -- Lệnh đã xử lý
end
return 0 -- Không phải lệnh của chúng ta, cho qua
end
BridgeFunctionAttach("OnCommandManager", OnCommand)
Lệnh dịch chuyển dành cho GM¶
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
-- Chỉ cho phép GM (quyền hạn >= 32)
if player.Authority < 32 then
GCNoticeSend(aIndex, 1, "You don't have permission to use this command.")
return 1
end
-- Phân tích "map x y" từ 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)
Lệnh xem thông tin người chơi¶
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)