diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 37fa87036c..ad73ed55d5 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -4,6 +4,7 @@ if (!hasInterface) exitWith {}; GVAR(deafnessDV) = 0; GVAR(deafnessPrior) = 0; +GVAR(volume) = 1; GVAR(playerVehAttenuation) = 1; GVAR(beep) = false; @@ -13,12 +14,8 @@ GVAR(time3) = 0; GVAR(time4) = 0; ["SettingsInitialized", { - //If not enabled, dont't add draw eventhandler or PFEH (for performance) - if (!GVAR(enableCombatDeafness)) exitWith {}; - // Spawn volume updating process - [FUNC(updateVolume), 1, [] ] call CBA_fnc_addPerFrameHandler; - + [FUNC(updateVolume), 1, [false] ] call CBA_fnc_addPerFrameHandler; }] call EFUNC(common,addEventHandler); //Update veh attunation when player veh changes diff --git a/addons/hearing/functions/fnc_earRinging.sqf b/addons/hearing/functions/fnc_earRinging.sqf index 138750c147..218db873d1 100644 --- a/addons/hearing/functions/fnc_earRinging.sqf +++ b/addons/hearing/functions/fnc_earRinging.sqf @@ -16,8 +16,6 @@ */ #include "script_component.hpp" -if (!GVAR(enableCombatDeafness)) exitWith {}; - PARAMS_2(_unit,_strength); if (_unit != ACE_player) exitWith {}; diff --git a/addons/hearing/functions/fnc_explosionNear.sqf b/addons/hearing/functions/fnc_explosionNear.sqf index e269aad997..dde9bc50cc 100644 --- a/addons/hearing/functions/fnc_explosionNear.sqf +++ b/addons/hearing/functions/fnc_explosionNear.sqf @@ -16,8 +16,8 @@ */ #include "script_component.hpp" -//Only run if combatDeafness enabled: -if (!GVAR(enableCombatDeafness)) exitWith {}; +//Only run if deafness or ear ringing is enabled: +if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; PARAMS_2(_unit,_damage); diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index d42e1ee308..6fc48b27fa 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -21,8 +21,8 @@ */ #include "script_component.hpp" -//Only run if combatDeafness enabled: -if (!GVAR(enableCombatDeafness)) exitWith {}; +//Only run if deafness or ear ringing is enabled: +if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo); diff --git a/addons/hearing/functions/fnc_putInEarplugs.sqf b/addons/hearing/functions/fnc_putInEarplugs.sqf index e979360945..8b11e6ba25 100644 --- a/addons/hearing/functions/fnc_putInEarplugs.sqf +++ b/addons/hearing/functions/fnc_putInEarplugs.sqf @@ -24,5 +24,8 @@ _player setVariable ["ACE_hasEarPlugsIn", true, true]; [localize LSTRING(EarPlugs_Are_On)] call EFUNC(common,displayTextStructured); +//Force an immediate fast volume update: +[[true]] call FUNC(updateVolume); + /*// No Earplugs in inventory, telling user [localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);*/ diff --git a/addons/hearing/functions/fnc_removeEarplugs.sqf b/addons/hearing/functions/fnc_removeEarplugs.sqf index bee3517235..19a34831cd 100644 --- a/addons/hearing/functions/fnc_removeEarplugs.sqf +++ b/addons/hearing/functions/fnc_removeEarplugs.sqf @@ -27,3 +27,6 @@ _player addItem "ACE_EarPlugs"; _player setVariable ["ACE_hasEarPlugsIn", false, true]; [localize LSTRING(EarPlugs_Are_Off)] call EFUNC(common,displayTextStructured); + +//Force an immediate fast volume update: +[[true]] call FUNC(updateVolume); diff --git a/addons/hearing/functions/fnc_updateVolume.sqf b/addons/hearing/functions/fnc_updateVolume.sqf index 6799d73266..3a72e8eb3b 100644 --- a/addons/hearing/functions/fnc_updateVolume.sqf +++ b/addons/hearing/functions/fnc_updateVolume.sqf @@ -3,7 +3,8 @@ * Updates and applys the current deafness. Called every 0.1 sec from a PFEH. * * Arguments: - * None + * 0: Args + * -----0: Just update volume (skip ringing/recovery) * * Return Value: * None @@ -15,53 +16,60 @@ */ #include "script_component.hpp" -private["_Volume"]; +//Only run if deafness or ear ringing is enabled: +if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; + +EXPLODE_1_PVT((_this select 0),_justUpdateVolume); + +private["_volume", "_soundTransitionTime"]; GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0; - -//If we got a big increase in the last second: -if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then { - if (ACE_time > GVAR(time3)) then { - GVAR(beep2) = false; - }; - if ((!GVAR(DisableEarRinging)) && {!GVAR(beep2)}) then { - playSound "ACE_Combat_Deafness"; - GVAR(beep2) = true; - GVAR(time3) = ACE_time + 5; - }; -}; - -GVAR(deafnessPrior) = GVAR(deafnessDV); GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0; -if (GVAR(deafnessDV) > 19.75) then { - ACE_player setvariable [QGVAR(deaf), true]; - if ((!GVAR(DisableEarRinging)) && {ACE_time > GVAR(time4)}) then { - playSound "ACE_Combat_Deafness"; - GVAR(beep2) = true; - GVAR(time3) = ACE_time + 10; - GVAR(time4) = ACE_time + 30; +if (!_justUpdateVolume) then { + //If we got a big increase in the last second: + if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then { + if (ACE_time > GVAR(time3)) then { + GVAR(beep2) = false; + }; + if ((!GVAR(DisableEarRinging)) && {!GVAR(beep2)}) then { + playSound "ACE_Combat_Deafness"; + GVAR(beep2) = true; + GVAR(time3) = ACE_time + 5; + }; }; -} else { - ACE_player setvariable [QGVAR(deaf), false]; + + GVAR(deafnessPrior) = GVAR(deafnessDV); + + if (GVAR(deafnessDV) > 19.75) then { + ACE_player setvariable [QGVAR(deaf), true]; + if ((!GVAR(DisableEarRinging)) && {ACE_time > GVAR(time4)}) then { + playSound "ACE_Combat_Deafness"; + GVAR(beep2) = true; + GVAR(time3) = ACE_time + 10; + GVAR(time4) = ACE_time + 30; + }; + } else { + ACE_player setvariable [QGVAR(deaf), false]; + }; + + if (GVAR(deafnessDV) > 10) then { + //check if the ringing is already being played + if (ACE_time > GVAR(time2)) then { + GVAR(beep) = false; + }; + if ((!GVAR(DisableEarRinging)) && {!GVAR(beep)}) then { + playSound "ACE_Ring_Backblast"; + GVAR(time2) = ACE_time + 22; + GVAR(beep) = true; + }; + }; + + // Hearing takes longer to return to normal after it hits rock bottom + GVAR(deafnessDV) = (GVAR(deafnessDV) - (0.5 * (GVAR(volume) max 0.1))) max 0; }; -if (GVAR(deafnessDV) > 10) then { - //check if the ringing is already being played - if (ACE_time > GVAR(time2)) then { - GVAR(beep) = false; - }; - if ((!GVAR(DisableEarRinging)) && {!GVAR(beep)}) then { - playSound "ACE_Ring_Backblast"; - GVAR(time2) = ACE_time + 22; - GVAR(beep) = true; - }; -}; - -// Hearing takes longer to return to normal after it hits rock bottom -GVAR(deafnessDV) = (GVAR(deafnessDV) - (0.5 * (GVAR(volume) max 0.1))) max 0; - -TRACE_3("tick", GVAR(deafnessPrior), GVAR(deafnessDV), GVAR(volume)); +if ((missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) || {!GVAR(enableCombatDeafness)}) exitWith {}; _volume = GVAR(volume); @@ -84,11 +92,9 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then { _volume = _volume min GVAR(UnconsciousnessVolume); }; -if (!(missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false])) then { - 1 fadeSound _volume; - 1 fadeSpeech _volume; - ACE_player setVariable ["tf_globalVolume", _volume]; - if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;}; -}; +_soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1}; -//hintSilent format ["GVAR(currentDeafness), _Volume = %1, %2", GVAR(currentDeafness), _volume]; +_soundTransitionTime fadeSound _volume; +_soundTransitionTime fadeSpeech _volume; +ACE_player setVariable ["tf_globalVolume", _volume]; +if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;};