-- 定义一个本地函数PlayerGetShell -- 函数的作用是获取玩家正在佩戴的装备,并减少装备的电池寿命 local function PlayerGetShell() -- 定义一个变量Wearing,并将其初始值设为nil local Wearing = nil -- 调用IsWearingShell函数,获取玩家正在佩戴的装备 Wearing = IsWearingShell()

-- 如果Wearing为nil,则直接返回
if Wearing == nil then
    return
end
-- 调用TimeTickReduceMinute函数,减少装备的电池寿命
TimeTickReduceMinute(Wearing)

end

-- 定义一个函数IsWearingShell -- 函数的作用是获取玩家正在佩戴的装备 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) -- 判断装备的类型,如果不是'MJOLNIRArmorMkVI'或'rPowerArmor1Common',则返回该装备 if wornitem:getItem():getType() == 'MJOLNIRArmorMkVI' == nil or wornitem:getItem():getType() == 'rPowerArmor1Common' == nil then local item = wornitem:getItem() -- 如果装备没有Shellbattery这个字段,则将其初始化为10 if item:getModData().Shellbattery == nil then item:getModData().Shellbattery = 10 end return item end end -- 如果没有找到符合条件的装备,则返回nil return nil end

-- 定义一个函数TimeTickReduceMinute -- 函数的作用是减少装备的电池寿命 function TimeTickReduceMinute(item) -- 如果装备的Shellbattery字段不为nil,并且大于等于0,则继续执行 if item:getModData().Shellbattery ~= nil and item:getModData().Shellbattery >= 0 then -- 将装备的Shellbattery字段减1 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 -- 如果装备的Shellbattery字段不为nil,并且小于等于0,则从玩家的佩戴装备中移除该装备,并向玩家发送警告信息 if item:getModData().Shellbattery ~= nil and item:getModData().Shellbattery <= 0 then getPlayer():removeWornItem(item) getPlayer():Say(getText('UI_ContextMenu_LowPowr')) end end

-- 事件监听函数,每1分钟执行一次PlayerGetShell函数 Events.EveryOneMinute.Add(PlayerGetShell)


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

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