-- 定义本地函数SilencerCheck,用于检查武器是否有消音器
local SilencerCheck = function(player, item)
	-- 如果物品为空则返回
    if item == nil then return end
	
	-- 如果物品类别为武器
	 if item:getCategory() == 'Weapon' then 
		-- 如果武器子类别为火器
		 if item:getSubCategory() == 'Firearm' then 
			-- 获取武器的脚本物品
			 local scriptItem = item:getScriptItem()

			-- 获取武器的声音音量、半径和挥动声音
			 local soundVolume = scriptItem:getSoundVolume();
			 local soundRadius = scriptItem:getSoundRadius();
			 local swingSound = scriptItem:getSwingSound();
			
			-- 如果武器没有枪管
			 if item:getCanon() == nil then
				-- Do nothing
			-- 如果武器有消音器
			 elseif item:getCanon():getType() == 'RESilencer'
			 or item:getCanon():getType() == 'RESSilencer' then
				-- 降低声音音量和半径,设置挥动声音为'RESilencer'
				 local reduce = 0.1; -- 降低到10% 
				
				 if item:getCanon():getType() == 'RESSilencer' then
					 reduce = 0.2;
				 end
				
				 soundVolume = soundVolume * reduce;
				 soundRadius = soundRadius * reduce;
				 swingSound = 'RESilencer';
			 end
			-- 设置武器的声音音量、半径和挥动声音
			 item:setSoundVolume(soundVolume);
			 item:setSoundRadius(soundRadius);
			 item:setSwingSound(swingSound);
		 end 
	 end
end

-- 添加新的事件钩子
-- 当玩家装备主手武器时,调用SilencerCheck函数
Events.OnEquipPrimary.Add(SilencerCheck)
-- 当游戏开始时,为玩家设置消音器
Events.OnGameStart.Add(
	function()
		-- 获取玩家对象
		 local player = getPlayer()
		-- 调用SilencerCheck函数,对玩家的主手武器进行检查
		 SilencerCheck(player, player:getPrimaryHandItem())
	 end
)

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

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