跳转至

自定义指令

OnCommandManager 钩子可以拦截自定义指令。返回 1 表示指令已处理(阻止默认处理),返回 0 则继续传递。

基础指令处理

local COMMAND_ONLINE = 100  -- 你的自定义指令代码

local function OnCommand(aIndex, code, arg)
    if code == COMMAND_ONLINE then
        -- 统计在线玩家数
        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  -- 指令已处理
    end

    return 0  -- 不是我们的指令,继续传递
end

BridgeFunctionAttach("OnCommandManager", OnCommand)

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

        -- 仅允许 GM(权限 >= 32)
        if player.Authority < 32 then
            GCNoticeSend(aIndex, 1, "You don't have permission to use this command.")
            return 1
        end

        -- 从 arg 中解析 "map x y"
        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)

玩家信息指令

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)