悬赏已过期 后悬赏过期

指令取物(带模糊查找)

邀请:

如何使用指令取物:

/give 数量 物品名称

/give 星星礼盒 可以获得1个星星礼盒

/give 10 星星礼盒 可以获得10个星星礼盒

源码:

-- 扫描道具ID
getItemId = {} -- 用来存储道具名称对应ID的全局变量
function get_Item_Id(e)
    -- 只执行一次在房主进入游戏时
    local result, uin = Player:getHostUin()
    if e.eventobjid == uin then
        -- 扫描道具代码最大值(过高卡顿)
        local a = 1
        while a ~= 540567 do
            result, item_name = Item:getItemName(a)
            if item_name then
                getItemId[item_name] = a
            end
            a = a + 1
        end
    end
end
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.EnterGame]=], get_Item_Id)

-- 管理员添加道具
local function give(e)
    -- 管理员迷你号
    local result, uin = Player:getHostUin()
    if e.eventobjid == uin then
        -- 是否为 "/give 道具数量 道具名称" 命令
        local content = e.content
        local num, item_name = content:match("^/give%s+(%d*)%s*(%S+)")
        if num == "" then num = "1" end -- 数量为空时默认1个
        -- 命令匹配
        if item_name then
            if getItemId[item_name] then
                -- 添加道具
                Player:gainItems(e.eventobjid, getItemId[item_name], num, 1)
                Chat:sendSystemMsg('添加成功!' .. num .. '个' .. item_name)
            else
                -- 遍历表,查找匹配的道具
                Chat:sendSystemMsg('你想找的是?')
                local result = {}
                for item, _ in pairs(getItemId) do
                    if string.match(item, item_name) then
                        table.insert(result, item)
                        if #result == 10 then break end -- 模糊匹配10个道具
                    end
                end
                -- 输出匹配的结果
                Chat:sendSystemMsg(#result > 0 and table.concat(result, ", ") or '没有找到。')
            end
        end
    end
end
ScriptSupportEvent:registerEvent([=[Player.NewInputContent]=], give)
您的回复

回复

默认排序 时间排序
图片审查中...
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索