实例为获取生物名称以及对应id,可以改成其他的,采用分段输出结果,不会造成卡顿。默认为玩家使用道具执行代码。
local function exportItemsBatched(e)
-- 设定配置
local startID = 0
local endID = 600000 -- 遍历次数
local maxChars = 7000 -- 单次 print上限
local buffer = "" -- 用于暂存文本的“容器”
print("========== 开始批量导出 (ID " .. startID .. " - " .. endID .. ") ==========")
for ID = startID, endID do
local result, name = Creature:GetMonsterDefName(ID)
if result == 0 and name ~= nil then
local line = "[" .. ID .. "] " .. name .. "\n"
-- 检查长度:如果 (当前缓存长度 + 新行长度) 超过限制
if (#buffer + #line) >= maxChars then
print(buffer) -- 先把攒好的打印出来
buffer = "" -- 清空缓存,准备存下一批
end
-- 将新行加入缓存
buffer = buffer .. line
end
end
if #buffer > 0 then
print(buffer)
end
print("========== 导出全部完成 ==========")
end
ScriptSupportEvent:registerEvent([=[Player.UseItem]=], exportItemsBatched)