DayZ 手电筒修复脚本 - 优化枪械上的战术灯功能
-- 定义一个名为FlashlightFix的表 FlashlightFix = {};
-- 当按下键盘上的特定键时执行的函数 FlashlightFix.onKeyPressed = function(key) -- 获取玩家对象 local Player = getSpecificPlayer(0); -- 如果按下的键是打开/关闭光源的键 if key == getCore():getKey('Equip/Turn On/Off Light Source') then -- 获取玩家手上的物品 local Item = Player:getPrimaryHandItem(); -- 如果手上的物品是手持武器且耐久度大于0并且有弹药 if (instanceof(Item, 'HandWeapon') and Item:getCondition() > 0) and Item:getStock() then -- 如果物品的类型是GTL(Gun Tactical Light) if Item:getStock():getType() == 'GTL' then -- 如果物品没有被激活,则设置光源的亮度和范围并激活光源 if not Item:isActivated() then Item:setTorchCone(true); Item:setLightStrength(1); Item:setLightDistance(30); Item:setActivated(true); else -- 如果物品已经被激活,则关闭光源 Item:setTorchCone(true); Item:setLightStrength(0); Item:setLightDistance(0); Item:setActivated(false); end end end end end
-- 当装备主手武器时执行的函数 FlashlightFix.checkGTL = function(player, item) -- 如果物品为空,则返回 if item == nil then return end
-- 如果物品的类别是武器且子类别是火器
if item:getCategory() == 'Weapon' then
if item:getSubCategory() == 'Firearm' then
-- 如果武器有弹药
if item:getStock() then
-- 如果武器的类型是GTL,则不做任何操作
if item:getStock():getType() == 'GTL' then
else
-- 如果武器的类型不是GTL,则关闭光源
item:setTorchCone(true);
item:setLightStrength(0);
item:setLightDistance(0);
item:setActivated(false);
end
else
-- 如果武器没有弹药,则关闭光源
item:setTorchCone(true);
item:setLightStrength(0);
item:setLightDistance(0);
item:setActivated(false);
end
end
end
end
-- 注册按键按下事件和装备主手武器事件 Events.OnKeyPressed.Add(FlashlightFix.onKeyPressed); Events.OnEquipPrimary.Add(FlashlightFix.checkGTL);
原文地址: http://www.cveoy.top/t/topic/nI74 著作权归作者所有。请勿转载和采集!