-- 定义一个本地函数 PlayerGetShell local function PlayerGetShell() -- 获取玩家是否佩戴外壳装置 local Wearing = nil Wearing = IsWearingShell()

-- 如果没有佩戴外壳装置则返回
if Wearing == nil then
    return
end
-- 减少外壳装置电池电量
TimeTickReduceMinute(Wearing)

end

-- 判断玩家是否佩戴外壳装置 function IsWearingShell() -- 获取玩家 local pl = getPlayer() -- 获取玩家佩戴的物品 local wornItems = pl:getWornItems() -- 如果玩家没有佩戴物品则返回nil if not wornItems then return nil end -- 遍历玩家佩戴的物品 for i = 0, wornItems:size() - 1 do local wornitem = wornItems:get(i) -- 判断玩家是否佩戴外壳装置 if wornitem:getItem():getType() == 'MJOLNIRArmorMkVI' then local item = wornitem:getItem() -- 如果外壳装置电池电量为nil,则设置为10 if item:getModData().Shellbattery == nil then item:getModData().Shellbattery = 10 end -- 返回外壳装置 return item end end -- 如果没有佩戴外壳装置则返回nil return nil end

-- 减少外壳装置电池电量 function TimeTickReduceMinute(item) -- 如果外壳装置电池电量不为nil并且大于等于0 if item:getModData().Shellbattery ~= nil and item:getModData().Shellbattery >= 0 then -- 减少外壳装置电池电量 item:getModData().Shellbattery = item:getModData().Shellbattery - 1 -- 打印外壳装置电池电量 print(item:getModData().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 -- 如果外壳装置电池电量小于等于0 if item:getModData().Shellbattery <= 0 then -- 移除外壳装置 getPlayer():removeWornItem(item) -- 提示玩家外壳装置电量枯竭 getPlayer():Say(getText('UI_ContextMenu_LowPowr')) end end -- 如果外壳装置电池电量不为nil并且小于等于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)

MJOLNIRArmorMkVI 外壳装置电池电量管理 LUA 代码

原文地址: https://www.cveoy.top/t/topic/nk7C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录