MJOLNIRArmorMkVI 电量计时器:每分钟检测并提示
-- 定义一个本地函数 PlayerGetShell local function PlayerGetShell() -- 定义变量 Wearing 为空 local Wearing = nil -- 调用 IsWearingShell 函数,将返回值赋给 Wearing Wearing = IsWearingShell()
-- 如果 Wearing 为空,则返回
if Wearing == nil then
return
end
-- 调用 TimeTickReduceMinute 函数,传入 Wearing 作为参数
TimeTickReduceMinute(Wearing)
end
-- 定义函数 IsWearingShell function IsWearingShell() -- 获取玩家对象 local pl = getPlayer() -- 获取玩家穿戴的物品 local wornItems = pl:getWornItems() -- 如果没有穿戴物品,则返回空 if not wornItems then return nil end -- 遍历穿戴物品 for i = 0, wornItems:size() - 1 do -- 获取当前穿戴物品 local wornitem = wornItems:get(i) -- 如果当前穿戴物品是 MJOLNIRArmorMkVI,则执行以下操作 if wornitem:getItem():getType() == 'MJOLNIRArmorMkVI' then -- 获取物品对象 local item = wornitem:getItem() -- 如果物品的 ModData 中没有 Shellbattery 字段,则设置初始值为 10 if item:getModData().Shellbattery == nil then item:getModData().Shellbattery = 10 end -- 返回物品对象 return item end end -- 如果没有找到 MJOLNIRArmorMkVI,则返回空 return nil end
-- 定义函数 TimeTickReduceMinute,传入一个物品对象作为参数 function TimeTickReduceMinute(item) -- 如果物品的 ModData 中有 Shellbattery 字段,且大于等于 0,则执行以下操作 if item:getModData().Shellbattery ~= nil and item:getModData().Shellbattery >= 0 then -- 将物品的 Shellbattery 字段减 1 item:getModData().Shellbattery = item:getModData().Shellbattery - 1 -- 打印当前 Shellbattery 值 print(item:getModData().Shellbattery) -- 如果 Shellbattery 大于 0 且等于 60,则提示低电量警告 if item:getModData().Shellbattery > 0 and item:getModData().Shellbattery == 60 then getPlayer():Say(getText('UI_ContextMenu_LowPowerWarn') .. tostring(item:getModData().Shellbattery / 12) .. getText('UI_ContextMenu_HourUnit')) end -- 如果 Shellbattery 小于等于 0,则从玩家身上移除该物品,并提示电量过低 if item:getModData().Shellbattery <= 0 then getPlayer():removeWornItem(item) getPlayer():Say(getText('UI_ContextMenu_LowPowr')) end end -- 如果物品的 ModData 中有 Shellbattery 字段,且小于等于 0,则从玩家身上移除该物品,并提示电量过低 if item:getModData().Shellbattery ~= nil and item:getModData().Shellbattery <= 0 then getPlayer():removeWornItem(item) getPlayer():Say(getText('UI_ContextMenu_LowPowr')) end end
-- 注册事件,每隔一分钟执行一次 PlayerGetShell 函数 Events.EveryOneMinute.Add(PlayerGetShell)
原文地址: https://www.cveoy.top/t/topic/nk7r 著作权归作者所有。请勿转载和采集!