diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index f9fb2043334..3866902c3ac 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -74,7 +74,7 @@ GVAR(lastPlayerVehicle) = objNull; }; if ((!isNull _vehicle) && {_player != _vehicle}) then { - private _firedEH = _vehicle addEventHandler ["FiredNear", {call FUNC(firedNear)}]; + private _firedEH = _vehicle addEventHandler ["FiredNear", LINKFUNC(firedNear)]; _vehicle setVariable [QGVAR(firedEH), _firedEH]; GVAR(lastPlayerVehicle) = _vehicle; TRACE_2("added veh eh",_firedEH,GVAR(lastPlayerVehicle)); @@ -83,35 +83,15 @@ GVAR(lastPlayerVehicle) = objNull; ["turret", LINKFUNC(updatePlayerVehAttenuation), false] call CBA_fnc_addPlayerEventHandler; + [QGVAR(firedNear), "FiredNear", LINKFUNC(firedNear), true] call CBA_fnc_addBISPlayerEventHandler; + [QGVAR(slotItemChanged), "SlotItemChanged", {(_this select 2) call FUNC(updateHearingProtection)}, true] call CBA_fnc_addBISPlayerEventHandler; + // Reset deafness on respawn (or remote control player switch) ["unit", { - params ["_player", "_oldPlayer"]; - TRACE_2("unit change",_player,_oldPlayer); - - if (!isNull _oldPlayer) then { - private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1]; - _oldPlayer removeEventHandler ["FiredNear", _firedEH]; - _oldPlayer setVariable [QGVAR(firedEH), nil]; - TRACE_2("removed unit eh",_oldPlayer,_firedEH); - }; - // Don't add a new EH if the unit respawned - if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then { - if ((getNumber (configOf _player >> "isPlayableLogic")) == 1) exitWith { - TRACE_1("skipping playable logic",typeOf _player); // VirtualMan_F (placeable logic zeus / spectator) - }; - - private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}]; - _player setVariable [QGVAR(firedEH), _firedEH]; - TRACE_2("added unit eh",_player,_firedEH); - }; - 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 aa2166a112f..535ad7af01d 100644 --- a/addons/hearing/functions/fnc_putInEarplugs.sqf +++ b/addons/hearing/functions/fnc_putInEarplugs.sqf @@ -32,4 +32,4 @@ if (_displayHint) then { // Force an immediate volume update true call FUNC(updateVolume); -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 743e89ef531..2d6cffb02e9 100644 --- a/addons/hearing/functions/fnc_removeEarplugs.sqf +++ b/addons/hearing/functions/fnc_removeEarplugs.sqf @@ -37,4 +37,4 @@ if (_displayHint) then { // Force an immediate 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 b9d7f1f9a0b..b4584a567a8 100644 --- a/addons/hearing/functions/fnc_updateHearingProtection.sqf +++ b/addons/hearing/functions/fnc_updateHearingProtection.sqf @@ -4,13 +4,13 @@ * 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 */ @@ -22,6 +22,11 @@ if (isNull ACE_player) exitWith { 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 178310cd209..a211922087d 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" + +#define UPDATE_HEARING_EARPLUGS -1 diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 7ca3793586c..42d110f1338 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -10,8 +10,8 @@ #define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD // MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 2.16 -#define REQUIRED_CBA_VERSION {3,16,0} +#define REQUIRED_VERSION 2.18 +#define REQUIRED_CBA_VERSION {3,18,0} #ifndef COMPONENT_BEAUTIFIED #define COMPONENT_BEAUTIFIED COMPONENT