diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 4a2ca90992..2658c4de6e 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -67,10 +67,16 @@ GVAR(lastPlayerVehicle) = objNull; private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1]; _oldPlayer removeEventHandler ["FiredNear", _firedEH]; _oldPlayer setVariable [QGVAR(firedEH), nil]; + private _explosionEH = _oldPlayer getVariable [QGVAR(explosionEH), -1]; _oldPlayer removeEventHandler ["Explosion", _explosionEH]; _oldPlayer setVariable [QGVAR(explosionEH), nil]; - TRACE_3("removed unit eh",_oldPlayer,_firedEH,_explosionEH); + + private _slotItemChangedEH = _oldPlayer getVariable [QGVAR(slotItemChangedEH), -1]; + _oldPlayer removeEventHandler ["SlotItemChanged", _slotItemChangedEH]; + _oldPlayer setVariable [QGVAR(slotItemChangedEH), nil]; + + TRACE_4("removed unit eh",_oldPlayer,_firedEH,_explosionEH,_slotItemChangedEH); }; // Don't add a new EH if the unit respawned if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then { @@ -79,17 +85,20 @@ GVAR(lastPlayerVehicle) = objNull; }; private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}]; _player setVariable [QGVAR(firedEH), _firedEH]; + private _explosionEH = _player addEventHandler ["Explosion", {call FUNC(explosionNear)}]; _player setVariable [QGVAR(explosionEH), _explosionEH]; - TRACE_3("added unit eh",_player,_firedEH,_explosionEH); + + // Update protection on possible helmet change + private _slotItemChangedEH = _player addEventHandler ["SlotItemChanged", {(_this select 2) call FUNC(updateHearingProtection)}]; + _player setVariable [QGVAR(slotItemChangedEH), _slotItemChangedEH]; + + TRACE_4("added unit eh",_player,_firedEH,_explosionEH,_slotItemChangedEH); }; GVAR(deafnessDV) = 0; GVAR(deafnessPrior) = 0; GVAR(time3) = 0; - [] call FUNC(updateHearingProtection); + UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection); }, true] call CBA_fnc_addPlayerEventHandler; - - // Update protection on possible helmet change - ["loadout", LINKFUNC(updateHearingProtection), false] call CBA_fnc_addPlayerEventHandler; }] call CBA_fnc_addEventHandler; diff --git a/addons/hearing/functions/fnc_putInEarplugs.sqf b/addons/hearing/functions/fnc_putInEarplugs.sqf index 2af4df8e86..bd2e137743 100644 --- a/addons/hearing/functions/fnc_putInEarplugs.sqf +++ b/addons/hearing/functions/fnc_putInEarplugs.sqf @@ -35,4 +35,4 @@ if (_displayHint) then { // No Earplugs in inventory, telling user //[localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured); -[] call FUNC(updateHearingProtection); +UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection); diff --git a/addons/hearing/functions/fnc_removeEarplugs.sqf b/addons/hearing/functions/fnc_removeEarplugs.sqf index 20a49bb530..8c6d4fb940 100644 --- a/addons/hearing/functions/fnc_removeEarplugs.sqf +++ b/addons/hearing/functions/fnc_removeEarplugs.sqf @@ -36,4 +36,4 @@ if (_displayHint) then { //Force an immediate fast volume update: [[true]] call FUNC(updateVolume); -[] call FUNC(updateHearingProtection); +UPDATE_HEARING_EARPLUGS call FUNC(updateHearingProtection); diff --git a/addons/hearing/functions/fnc_updateHearingProtection.sqf b/addons/hearing/functions/fnc_updateHearingProtection.sqf index 15973b73a9..4db2fe449f 100644 --- a/addons/hearing/functions/fnc_updateHearingProtection.sqf +++ b/addons/hearing/functions/fnc_updateHearingProtection.sqf @@ -4,24 +4,27 @@ * Updates the hearing protection and volume attenuation for player on earbuds/helmet change * * Arguments: - * None + * 0: Slot * * Return Value: * None * * Example: - * [] call ace_hearing_fnc_updateHearingProtection + * UPDATE_HEARING_EARPLUGS call ace_hearing_fnc_updateHearingProtection * * Public: No */ -TRACE_1("params",_this); - if (isNull ACE_player) exitWith { GVAR(damageCoefficent) = 0; GVAR(volumeAttenuation) = 1; }; +params ["_slot"]; +TRACE_1("",_slot); + +if !(_slot in [UPDATE_HEARING_EARPLUGS, TYPE_GOGGLE, TYPE_HEADGEAR]) exitWith {}; + // Handle Earplugs private _hasEarPlugsIn = [ACE_player] call FUNC(hasEarPlugsIn); GVAR(damageCoefficent) = [1, 0.25] select _hasEarPlugsIn; diff --git a/addons/hearing/script_component.hpp b/addons/hearing/script_component.hpp index 178310cd20..ed9052a0a1 100644 --- a/addons/hearing/script_component.hpp +++ b/addons/hearing/script_component.hpp @@ -16,3 +16,5 @@ #include "\z\ace\addons\main\script_macros.hpp" #include "\z\ace\addons\hearing\script_macros_hearingProtection.hpp" + +#defined UPDATE_HEARING_EARPLUGS -1