From f69142dd45a9aaa8a318237a5b78185caa9c8c0b Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 20 May 2016 11:23:14 -0500 Subject: [PATCH] Hearing - New XEH, Fix dead effects, Medical var (#3802) * Hearing - New XEH, Fix dead effects, Medical var * Use setHearingCapability * Cleanup dead player vol update * Don't change global hearing in medical * Fix exitWith --- addons/common/XEH_preInit.sqf | 2 + .../functions/fnc_setHearingCapability.sqf | 56 +++++++++---------- addons/hearing/CfgEventHandlers.hpp | 16 ------ addons/hearing/XEH_postInit.sqf | 4 ++ .../hearing/functions/fnc_explosionNear.sqf | 3 - addons/hearing/functions/fnc_firedNear.sqf | 3 - addons/hearing/functions/fnc_updateVolume.sqf | 13 +++-- addons/medical/XEH_postInit.sqf | 4 -- 8 files changed, 39 insertions(+), 62 deletions(-) diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 16e0a65159..dea4e64538 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -46,6 +46,8 @@ if (isServer) then { GVAR(statusEffect_Names) = []; GVAR(statusEffect_isGlobal) = []; +GVAR(setHearingCapabilityMap) = []; + ////////////////////////////////////////////////// // Set up PlayerChanged eventhandler for pre init (EH is installed in postInit) ////////////////////////////////////////////////// diff --git a/addons/common/functions/fnc_setHearingCapability.sqf b/addons/common/functions/fnc_setHearingCapability.sqf index 2366081ec1..5b1e7a5a3a 100644 --- a/addons/common/functions/fnc_setHearingCapability.sqf +++ b/addons/common/functions/fnc_setHearingCapability.sqf @@ -5,48 +5,44 @@ * Arguments: * 0: id * 1: settings - * 2: add (default: true) + * 2: add [true] OR remove [false] (default: true) * * Return Value: * None * - * Public: Yes + * Example: + * ["earwax", 0.5, true] call ace_common_fnc_setHearingCapability * - * Note: uses player + * Public: Yes */ #include "script_component.hpp" -params ["_id", "_settings", ["_add", true]]; - -private _map = missionNamespace getVariable [QGVAR(setHearingCapabilityMap),[]]; +params ["_id", "_setting", ["_add", true]]; private _exists = false; - -{ - if (_id == _x select 0) exitWith { - _exists = true; - if (_add) then { - _x set [1, _settings]; - } else { - _map set [_forEachIndex, 0]; - _map = _map - [0]; - }; - }; -} forEach _map; - -if (!_exists && _add) then { - _map pushBack [_id, _settings]; -}; - -missionNamespace setVariable [QGVAR(setHearingCapabilityMap), _map]; - -// find lowest volume private _lowestVolume = 1; -{ - _lowestVolume = (_x select 1) min _lowestVolume; - false -} count _map; +GVAR(setHearingCapabilityMap) = GVAR(setHearingCapabilityMap) select { + _x params ["_xID", "_xSetting"]; + if (_id == _xID) then { + _exists = true; + if (_add) then { + _x set [1, _setting]; + _lowestVolume = _lowestVolume min _setting; + true + } else { + false + }; + } else { + _lowestVolume = _lowestVolume min _xSetting; + true + }; +}; + +if (!_exists && _add) then { + _lowestVolume = _lowestVolume min _setting; + GVAR(setHearingCapabilityMap) pushBack [_id, _setting]; +}; // in game sounds 0 fadeSound _lowestVolume; diff --git a/addons/hearing/CfgEventHandlers.hpp b/addons/hearing/CfgEventHandlers.hpp index 352f802435..aa8dbf5134 100644 --- a/addons/hearing/CfgEventHandlers.hpp +++ b/addons/hearing/CfgEventHandlers.hpp @@ -25,22 +25,6 @@ class Extended_Init_EventHandlers { }; }; -class Extended_FiredNear_EventHandlers { - class AllVehicles { - class GVAR(FiredNear) { - clientFiredNear = QUOTE(_this call FUNC(firedNear);); - }; - }; -}; - -class Extended_Explosion_EventHandlers { - class CAManBase { - class GVAR(ExplosionNear) { - clientExplosion = QUOTE(_this call FUNC(explosionNear);); - }; - }; -}; - class Extended_Respawn_EventHandlers { class CAManBase { class ADDON { diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index cbae40dee0..fdd61ccfde 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -17,6 +17,10 @@ GVAR(volumeAttenuation) = 1; // Only run PFEH and install event handlers if combat deafness is enabled if (!GVAR(EnableCombatDeafness)) exitWith {}; + //Add XEH: + ["CAManBase", "FiredNear", FUNC(firedNear)] call CBA_fnc_addClassEventHandler; + ["CAManBase", "Explosion", FUNC(explosionNear)] call CBA_fnc_addClassEventHandler; + // Update hearing protection now: [] call FUNC(updateHearingProtection); diff --git a/addons/hearing/functions/fnc_explosionNear.sqf b/addons/hearing/functions/fnc_explosionNear.sqf index 799de52320..76c6707de5 100644 --- a/addons/hearing/functions/fnc_explosionNear.sqf +++ b/addons/hearing/functions/fnc_explosionNear.sqf @@ -16,9 +16,6 @@ */ #include "script_component.hpp" -// Only run if combat deafness is enabled -if (!GVAR(EnableCombatDeafness)) exitWith {}; - params ["_unit", "_damage"]; if (_unit != ACE_player) exitWith {}; diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index f583ab0050..46bbee4fae 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -22,9 +22,6 @@ */ #include "script_component.hpp" -// Only run if combat deafness is enabled -if (!GVAR(EnableCombatDeafness)) exitWith {}; - params ["_object", "_firer", "_distance", "_weapon", "", "", "_ammo"]; //Only run if firedNear object is player or player's vehicle: diff --git a/addons/hearing/functions/fnc_updateVolume.sqf b/addons/hearing/functions/fnc_updateVolume.sqf index 58eedc7b39..2212bd6222 100644 --- a/addons/hearing/functions/fnc_updateVolume.sqf +++ b/addons/hearing/functions/fnc_updateVolume.sqf @@ -16,6 +16,12 @@ */ #include "script_component.hpp" +if (!alive ACE_player) exitWith { + if (missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) exitWith {}; + TRACE_1("dead - removing hearing effects",ACE_player); + [QUOTE(ADDON), 1, true] call EFUNC(common,setHearingCapability); +}; + (_this select 0) params ["_justUpdateVolume"]; GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0; @@ -54,9 +60,4 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then { _volume = _volume min GVAR(UnconsciousnessVolume); }; -private _soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1}; - -_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;}; +[QUOTE(ADDON), _volume, true] call EFUNC(common,setHearingCapability); diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index 8d8911a6bf..f0d3b907f6 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -37,19 +37,15 @@ if (isServer) then {["placedInBodyBag", FUNC(serverRemoveBody)] call EFUNC(commo params ["_unit", "_status"]; if (local _unit) then { if (_status) then { - _unit setVariable ["tf_globalVolume", 0.4]; _unit setVariable ["tf_voiceVolume", 0, true]; _unit setVariable ["tf_unable_to_use_radio", true, true]; _unit setVariable ["acre_sys_core_isDisabled", true, true]; - if (!isNil "acre_api_fnc_setGlobalVolume") then { [0.4^0.33] call acre_api_fnc_setGlobalVolume; }; } else { - _unit setVariable ["tf_globalVolume", 1]; _unit setVariable ["tf_voiceVolume", 1, true]; _unit setVariable ["tf_unable_to_use_radio", false, true]; _unit setVariable ["acre_sys_core_isDisabled", false, true]; - if (!isNil "acre_api_fnc_setGlobalVolume") then { [1] call acre_api_fnc_setGlobalVolume; }; }; }; }] call EFUNC(common,addEventHandler);