local function RegisterEvent(e, f)
if not e or not f then
return error("没有传入事件或函数体")
end
local err, res = pcall(function()
return DoLuaScriptFunction(function()
ScriptSupportEvent:registerEvent(e, f)
end, "test")
end)
return nil
end
local function tabv(t)
local count = {}
for k, v in pairs(t) do
count[#count + 1] = k
end
return count
end
--全局设置
range={1,200000}--检索范围
Tag=true--搜索结果携带来源标签
Wait=0.05--搜索结果打印延迟
Tips=true--每次开始都打印指令列表
DESC=false--显示描述
SearchDESC=true--启用描述搜索
Screen=false--标签筛选开关
AdminList="1787329507"--管理员名单(房主默认为最高级管理员)
ProtectedAdminList={1787329507}--受保护的默认管理员名单
function CSH(event)
AdminAll=false
if event==true then
LastMsg={}
end
ItemList={NameList={},IdList={},AllList={},DescList={}}
LocalList={}
ItemTitle=0
for i=range[1],range[2] do
local result,name=Item:getItemName(i)
local result,desc=Item:getItemDesc(i)
if result==0 then
ItemTitle=ItemTitle+1
ItemList["AllList"][i]=i..""
ItemList["NameList"][""..name]=i
ItemList["IdList"][i]=name
ItemList["DescList"][i]=desc
end
end
print("┌初始化完成")
print("├检索范围:"..range[1].."~"..range[2])
print("└有效道具:"..#ItemList["AllList"].."个")
end
CSH(true)
function SearchTips(event)
print("┌指令列表:")
threadpool:wait(0.05)
print("├┬搜索物品")
threadpool:wait(0.05)
print("│├┬按名称/ID")
threadpool:wait(0.05)
print("││├/search [string]")
threadpool:wait(0.05)
print("││└string为道具名/ID;可模糊匹配")
threadpool:wait(0.05)
print("│└┬列表")
threadpool:wait(0.05)
print("│ ├/search [ID] [ID]")
threadpool:wait(0.05)
print("│ └(将搜索结果打印至控制台)")
threadpool:wait(0.05)
print("├┬添加物品")
threadpool:wait(0.05)
print("│├┬按ID")
threadpool:wait(0.05)
print("││└/give [string] [number]")
threadpool:wait(0.05)
print("│├┬批量")
threadpool:wait(0.05)
print("││└/give list [string] ... [string] [number]")
threadpool:wait(0.05)
print("││└/give list [string] to [string] [number]")
threadpool:wait(0.05)
print("│├┬按ID给某人")
threadpool:wait(0.05)
print("││└/give to [playerID] [string] [number]")
threadpool:wait(0.05)
print("│├┬批量给某人")
threadpool:wait(0.05)
print("││└/give list to [playerID] [string] ... [string] [number]")
threadpool:wait(0.05)
print("│└(string必须精准输入;number可忽略,默认为1)")
threadpool:wait(0.05)
print("├┬设置(不稳定,请谨慎使用)")
threadpool:wait(0.05)
print("│├┬调整检索范围")
threadpool:wait(0.05)
print("││└/range [number] [number]")
threadpool:wait(0.05)
print("│├┬调整等待时间")
threadpool:wait(0.05)
print("││└/wait [number]")
threadpool:wait(0.05)
print("│├┬是否启用描述搜索")
threadpool:wait(0.05)
print("││└/SearchDesc [true/false]")
threadpool:wait(0.05)
print("│├┬搜索结果显示描述")
threadpool:wait(0.05)
print("││└/desc [true/false]")
threadpool:wait(0.05)
print("│├┬搜索结果启用筛选")
threadpool:wait(0.05)
print("││└/screen [true/false]")
threadpool:wait(0.05)
print("│└┬是否携带标签")
threadpool:wait(0.05)
print("│ └/tag [true/false]")
threadpool:wait(0.05)
print("├┬查看指令列表")
threadpool:wait(0.05)
print("│└/help")
threadpool:wait(0.05)
print("├┬使用上一个指令(指令记忆功能)")
threadpool:wait(0.05)
print("│└/ [参数] 例:/ list 1 2 3 100")
threadpool:wait(0.05)
print("├┬设置管理员权限(仅房主可用)")
threadpool:wait(0.05)
print("│└/admin add/remove all/playerID")
threadpool:wait(0.05)
print("├┬查看脚本data")
threadpool:wait(0.05)
print("│└/data")
threadpool:wait(0.05)
print("└┬调试信息")
threadpool:wait(0.05)
print(" └/ItemList [key]")
end
if Tips==true then
SearchTips()
end
function SearchMain(event)
r,AdminA=Player:getHostUin()
--AdminList=AdminList..tostring(AdminA)..','
if string.find(AdminList,tostring(event.eventobjid))~=nil or AdminA==event.eventobjid or AdminAll==true then
msg=event.content
MsgTab={}
Separator=" "
msg=msg..Separator
MsgId=1
for i=1,#msg-1 do
string=string.sub(msg,i,i)
if string==Separator then
MsgId=MsgId+1
else
if MsgTab[MsgId]==nil or MsgTab[MsgId]=="" then
MsgTab[MsgId]=string
else
MsgTab[MsgId]=MsgTab[MsgId]..string
end
end
end
if MsgTab[1]=="/" and LastMsg[#LastMsg]~=nil then
MsgTab[1]=LastMsg[#LastMsg]
Player:notifyGameInfo2Self(event.eventobjid,"[指令记忆]["..LastMsg[#LastMsg].."][ok]")
elseif MsgTab[1]=="/" and LastMsg[#LastMsg]==nil then
Player:notifyGameInfo2Self(event.eventobjid,"[指令记忆][error][找不到上一个指令]")
end
if MsgTab[1]~="/" then
LastMsg[#LastMsg+1]=MsgTab[1]
end
if MsgTab[1]=="/search" then
if #MsgTab==2 then
Player:notifyGameInfo2Self(event.eventobjid,"[search][ok]")
print("搜索"..MsgTab[2].."的结果")
for i=range[1],range[2] do
if ItemList["IdList"][i]~=nil then
local s=string.find(ItemList["IdList"][i],MsgTab[2])
if s~=nil then
LocalList[#LocalList+1]=ItemList["IdList"][i]
if Wait>0 then
Trigger:wait(Wait)
end
if Tag==true then
if Screen==false then
print("ID:"..i.."丨名称:"..ItemList["IdList"][i])
else
UI:Print2WndWithTag('按名称',"ID:"..i.."丨名称:"..ItemList["IdList"][i])
end
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
elseif Tag==false then
print("ID:"..i.."丨名称:"..ItemList["IdList"][i])
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
end
end
end
----
if SearchDESC==true then
if ItemList["DescList"][i]~=nil then
local s=string.find(ItemList["DescList"][i],MsgTab[2])
if s~=nil then
LocalList[#LocalList+1]=ItemList["DescList"][i]
if Wait>0 then
Trigger:wait(Wait)
end
if Tag==true then
if Screen==false then
print("[按描述]ID:"..i.."丨名称:"..ItemList["IdList"][i])
else
UI:Print2WndWithTag('按描述',"ID:"..i.."丨名称:"..ItemList["IdList"][i])
end
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
elseif Tag==false then
print("ID:"..i.."丨名称:"..ItemList["IdList"][i])
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
end
end
end
end
----
if ItemList["AllList"][i]~=nil then
local s=string.find(ItemList["AllList"][i].."",""..MsgTab[2])
if s~=nil then
LocalList[#LocalList+1]=ItemList["IdList"][i]
if ItemList["IdList"][i]~=nil then
if Wait>0 then
Trigger:wait(Wait)
end
if Tag==true then
if Screen==false then
print("[按ID]ID:"..i.."丨名称:"..ItemList["IdList"][i])
else
UI:Print2WndWithTag('按ID',"ID:"..i.."丨名称:"..ItemList["IdList"][i])
end
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
elseif Tag==false then
print("ID:"..i.."丨名称:"..ItemList["IdList"][i])
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
end
end
end
end
end
print("共"..#LocalList.."个结果")
LocalList={}
end
if #MsgTab==3 then
if tonumber(MsgTab[2])~=nil and tonumber(MsgTab[3])~=nil then
if tonumber(MsgTab[2])>=range[1] and tonumber(MsgTab[2])<=range[2] then
if tonumber(MsgTab[3])<=range[2] and tonumber(MsgTab[3])>=range[1] then
if tonumber(MsgTab[2])<=tonumber(MsgTab[3]) then
Player:notifyGameInfo2Self(event.eventobjid,"[search][ok]")
print("从ID"..MsgTab[2].."~"..MsgTab[3].."的列表结果")
for i=tonumber(MsgTab[2]),tonumber(MsgTab[3]) do
if ItemList["IdList"][i]~=nil then
if Wait>0 then
Trigger:wait(Wait)
end
print("ID:"..i.."丨名称:"..ItemList["IdList"][i])
if DESC==true then
if Screen==false then
print("描述:"..ItemList["DescList"][i].."\n")
else
UI:Print2WndWithTag('描述',ItemList["DescList"][i].."\n")
end
end
LocalList[#LocalList+1]=ItemList["IdList"][i]
end
end
print("共"..#LocalList.."个结果")
LocalList={}
end
end
end
end
end
end
if MsgTab[1]=="/ItemList" and MsgTab[2]~=nil then
Player:notifyGameInfo2Self(event.eventobjid,"[ItemList][ok]")
print("ItemList数组中"..MsgTab[2].."为索引的数据")
print(ItemList[MsgTab[2]])
print("\n")
end
if MsgTab[1]=="/give" and MsgTab[2]~="list" and MsgTab[2]~="to" and MsgTab[4]~="to" then
if MsgTab[3]==nil then
num=1
else
num=tonumber(MsgTab[3])
end
if tonumber(MsgTab[2])==nil then
id=ItemList["NameList"][""..MsgTab[2]]
elseif tonumber(MsgTab[2])~=882828858540 then
id=tonumber(MsgTab[2])
end
local r,success=Backpack:addItem(event.eventobjid,id,num)
if success<num then
local r,x,y,z=Actor:getPosition(event.eventobjid)
World:spawnItem(x,y,z,id,num-success)
end
if r==0 then
Player:notifyGameInfo2Self(event.eventobjid,"[give][ok]")
id,num=nil,nil
end
end
if MsgTab[1]=="/range" then
if #MsgTab==3 then
if tonumber(MsgTab[2])~=nil and tonumber(MsgTab[3])~=nil then
if tonumber(MsgTab[2])<=tonumber(MsgTab[3]) then
range[1],range[2]=tonumber(MsgTab[2]),tonumber(MsgTab[3])
CSH(false)
Player:notifyGameInfo2Self(event.eventobjid,"[set][range][ok]")
end
end
end
end
if MsgTab[1]=="/help" then
SearchTips()
Player:notifyGameInfo2Self(event.eventobjid,"[help][ok]")
end
if MsgTab[1]=="/wait" then
if tonumber(MsgTab[2])~=nil then
Wait=tonumber(MsgTab[2])
Player:notifyGameInfo2Self(event.eventobjid,"[set][wait][ok]")
end
end
if MsgTab[1]=="/tag" then
if MsgTab[2]=="true" then
Tag=true
else
Tag=false
end
Player:notifyGameInfo2Self(event.eventobjid,"[set][tag][ok]")
end
if MsgTab[1]=="/desc" then
if MsgTab[2]=="true" then
DESC=true
else
DESC=false
end
Player:notifyGameInfo2Self(event.eventobjid,"[set][desc][ok]")
end
if MsgTab[1]=="/screen" then
if MsgTab[2]=="true" then
Screen=true
else
Screen=false
end
Player:notifyGameInfo2Self(event.eventobjid,"[set][screen][ok]")
end
if MsgTab[1]=="/SearchDesc" then
if MsgTab[2]=="true" then
SearchDESC=true
else
SearchDESC=false
end
Player:notifyGameInfo2Self(event.eventobjid,"[set][SearchDesc][ok]")
end
if MsgTab[1]=="/admin" then
if event.eventobjid==AdminA then
if MsgTab[2]=="add" then
if MsgTab[3]=="all" then
AdminAll=true
Player:notifyGameInfo2Self(event.eventobjid,"[set][Admin][AddAll][ok]")
else
if ProtectedAdminList[MsgTab[3]] then
Player:notifyGameInfo2Self(event.eventobjid,"[set][Admin][add][error][该管理员受保护,无法添加]")
else
AdminList=AdminList..MsgTab[3]..','
Player:notifyGameInfo2Self(event.eventobjid,"[set][Admin][add][ok]")
end
end
elseif MsgTab[2]=='remove' then
if MsgTab[3]=="all" then
AdminAll=false
Player:notifyGameInfo2Self(event.eventobjid,"[set][Admin][RemoveAll][ok]")
AdminList=''
else
if ProtectedAdminList[MsgTab[3]] then
Player:notifyGameInfo2Self(event.eventobjid, "[set][Admin][Remove][error][该管理员受保护,无法移除]")
else
AdminList = string.gsub(AdminList, MsgTab[3] .. ',', '')
Player:notifyGameInfo2Self(event.eventobjid, "[set][Admin][Remove][ok]")
end
end
end
else
Player:notifyGameInfo2Self(event.eventobjid, "[set][Admin][err][没有最高管理权限]")
end
end
if MsgTab[1] == "/give" and MsgTab[2] == "to" and MsgTab[4] ~= "to" then
if MsgTab[5] == nil then
num = 1
else
num = tonumber(MsgTab[5])
end
if tonumber(MsgTab[4]) == nil then
id = ItemList["NameList"]["" .. MsgTab[4]]
elseif tonumber(MsgTab[4]) ~= 882828858540 then
id = tonumber(MsgTab[4])
end
if tonumber(MsgTab[3]) ~= nil then
objid = tonumber(MsgTab[3])
end
local r, success = Backpack:addItem(objid, id, num)
if success < num then
local r, x, y, z = Actor:getPosition(objid)
World:spawnItem(x, y, z, id, num - success)
end
if r == 0 then
Player:notifyGameInfo2Self(event.eventobjid, "[give][ok]")
objid, id, num = nil, nil, nil
end
end
if MsgTab[1] == "/give" and MsgTab[2] == "list" and MsgTab[3] ~= "to" and MsgTab[4] ~= "to" then
for i = 3, #MsgTab - 1 do
if MsgTab[#MsgTab] == nil then
num = 1
else
num = tonumber(MsgTab[#MsgTab])
end
if tonumber(MsgTab[i]) == nil then
id = ItemList["NameList"]["" .. MsgTab[i]]
elseif tonumber(MsgTab[i]) ~= 882828858540 then
id = tonumber(MsgTab[i])
end
local r, success = Backpack:addItem(event.eventobjid, id, num)
if success < num then
local r, x, y, z = Actor:getPosition(event.eventobjid)
World:spawnItem(x, y, z, id, num - success)
end
if r == 0 then
Player:notifyGameInfo2Self(event.eventobjid, "[give][ok]")
id, num = nil, nil
end
end
end
if MsgTab[1] == "/give" and MsgTab[2] == "list" and MsgTab[3] == "to" and MsgTab[4] ~= "to" then
if tonumber(MsgTab[4]) ~= nil then
objid = tonumber(MsgTab[4])
end
for i = 5, #MsgTab - 1 do
if MsgTab[#MsgTab] == nil then
num = 1
else
num = tonumber(MsgTab[#MsgTab])
end
if tonumber(MsgTab[i]) == nil then
id = ItemList["NameList"]["" .. MsgTab[i]]
elseif tonumber(MsgTab[i]) ~= 882828858540 then
id = tonumber(MsgTab[i])
end
local r, success = Backpack:addItem(objid, id, num)
if success < num then
local r, x, y, z = Actor:getPosition(objid)
World:spawnItem(x, y, z, id, num - success)
end
if r == 0 then
Player:notifyGameInfo2Self(event.eventobjid, "[give][ok]")
id, num = nil, nil
end
end
end
if MsgTab[1] == "/give" and MsgTab[2] == "list" and tonumber(MsgTab[3]) ~= nil and MsgTab[4] == "to" and tonumber(MsgTab[5]) ~= nil and tonumber(MsgTab[6]) ~= nil then
for i = tonumber(MsgTab[3]), tonumber(MsgTab[5]) do
local r, success = Backpack:addItem(event.eventobjid, i, tonumber(MsgTab[6]))
if success < tonumber(MsgTab[6]) then
local r, x, y, z = Actor:getPosition(event.eventobjid)
World:spawnItem(x, y, z, i, tonumber(MsgTab[6]) - success)
end
if r == 0 then
Player:notifyGameInfo2Self(event.eventobjid, "[give][ok]")
id, num = nil, nil
end
end
end
if MsgTab[1] == "/data" then
Player:notifyGameInfo2Self(event.eventobjid, "[data][ok]")
print("┌脚本data")
print("├检索范围 >>> " .. range[1] .. "~" .. range[2] .. ",可用的道具共" .. #ItemList["AllList"] .. "个")
print("├是否携带标签 >>> " .. tostring(Tag))
print("├是否启用搜索描述 >>> " .. tostring(SearchDESC))
print("├是否显示描述 >>> " .. tostring(DESC))
print("├是否启用筛选 >>> " .. tostring(Screen))
print("├管理员权限 >>> " .. tostring(AdminList))
print("├记录的指令数量 >>> " .. #LastMsg)
print("└等待时间 >>> " .. tostring(Wait) .. "s")
end
elseif string.sub(event.content, 0, 1) == '/' then
Player:notifyGameInfo2Self(event.eventobjid, "[NoPermission][无权限,请向最高级管理员索要指令权限]")
end
end
RegisterEvent([=[Player.NewInputContent]=], SearchMain)
-- version: 2022-04-20
-- mini: 1787329507
-- version: 2022-04-20
-- mini: 1787329507
--此脚本为print打印至ChatBox
PrintToChat=true
local newprint={}
newprint.back=print
print=function(...)
local printtable={}
for i,v in ipairs({...}) do
v=string.gsub(tostring(v),'#cff0000','#R')
printtable[i]=tostring(v)
end
local printstr=table.concat(printtable,' ')
if PrintToChat==true then
--调试用:UI:Print2WndWithTag('printtable',printtable)
Chat:sendSystemMsg(printstr)
else
UI:Print2WndWithTag('global',printstr)
end
return printstr
end