From 3b5747423aeb238de12eeb64e44fda489a592596 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 20 Jul 2018 22:23:48 +0100 Subject: [PATCH] Improve unconscious volume handling (#6455) * Lower player hearing upon entering unconscious * Fix potential for unconscious units to use radio * Evaluate player's volume upon changing unit * Reset player volume on death * Remove unnecessary public variable --- addons/medical_feedback/XEH_postInit.sqf | 33 +++++++++++++++---- addons/medical_feedback/script_component.hpp | 2 ++ addons/medical_statemachine/Statemachine.hpp | 5 ++- addons/medical_statemachine/XEH_PREP.hpp | 1 + .../functions/fnc_enteredStateDeath.sqf | 22 +++++++++++++ 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf diff --git a/addons/medical_feedback/XEH_postInit.sqf b/addons/medical_feedback/XEH_postInit.sqf index 948bf1d9a8..0dac59dd28 100644 --- a/addons/medical_feedback/XEH_postInit.sqf +++ b/addons/medical_feedback/XEH_postInit.sqf @@ -21,21 +21,42 @@ GVAR(heartBeatEffectRunning) = false; ["ace_unconscious", { params ["_unit", "_unconscious"]; - if (local _unit) then { - _unit setVariable ["tf_voiceVolume", [1, 0] select _unconscious, true]; - _unit setVariable ["tf_unable_to_use_radio", _unconscious, true]; - _unit setVariable ["acre_sys_core_isDisabled", _unconscious, true]; - }; - if (_unit != ACE_player) exitWith {}; + // Toggle unconscious player's ability to talk in radio addons + _unit setVariable ["tf_voiceVolume", [1, 0] select _unconscious, true]; + _unit setVariable ["tf_unable_to_use_radio", _unconscious]; // Only used locally + _unit setVariable ["acre_sys_core_isDisabled", _unconscious, true]; + + // Greatly reduce player's hearing ability while unconscious (affects radio addons) + [QUOTE(ADDON), VOL_UNCONSCIOUS, _unconscious] call EFUNC(common,setHearingCapability); + [_unconscious, 1] call FUNC(effectUnconscious); ["unconscious", _unconscious] call EFUNC(common,setDisableUserInputStatus); }] call CBA_fnc_addEventHandler; +// Reset volume upon death for spectators +[QEGVAR(medical,death), { + params ["_unit"]; + + if (_unit != ACE_player) exitWith {}; + + _unit setVariable ["tf_voiceVolume", 1, true]; + _unit setVariable ["tf_unable_to_use_radio", false]; + _unit setVariable ["acre_sys_core_isDisabled", false, true]; + [QUOTE(ADDON), 1, false] call EFUNC(common,setHearingCapability); +}] call CBA_fnc_addEventHandler; + +// Update effects to match new unit's current status (this also handles respawn) ["unit", { params ["_new", "_old"]; + private _status = _new getVariable ["ace_unconscious", false]; + + _new setVariable ["tf_voiceVolume", [1, 0] select _status, true]; + _new setVariable ["tf_unable_to_use_radio", _status]; + _new setVariable ["acre_sys_core_isDisabled", _status, true]; + [QUOTE(ADDON), VOL_UNCONSCIOUS, _status] call EFUNC(common,setHearingCapability); [_status, 0] call FUNC(effectUnconscious); ["unconscious", _status] call EFUNC(common,setDisableUserInputStatus); }] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/medical_feedback/script_component.hpp b/addons/medical_feedback/script_component.hpp index a86c1592f9..939e8b3379 100644 --- a/addons/medical_feedback/script_component.hpp +++ b/addons/medical_feedback/script_component.hpp @@ -34,3 +34,5 @@ #define SND_HEARBEAT_FAST (selectRandom ["ACE_heartbeat_fast_1", "ACE_heartbeat_fast_2", "ACE_heartbeat_fast_3"]) #define SND_HEARBEAT_NORMAL (selectRandom ["ACE_heartbeat_norm_1", "ACE_heartbeat_norm_2"]) #define SND_HEARBEAT_SLOW (selectRandom ["ACE_heartbeat_slow_1", "ACE_heartbeat_slow_2"]) + +#define VOL_UNCONSCIOUS 0.25 diff --git a/addons/medical_statemachine/Statemachine.hpp b/addons/medical_statemachine/Statemachine.hpp index 925bac6276..c3c7d9c490 100644 --- a/addons/medical_statemachine/Statemachine.hpp +++ b/addons/medical_statemachine/Statemachine.hpp @@ -107,8 +107,7 @@ class ACE_Medical_StateMachine { }; }; class Dead { - // TODO: this needs to be handled by a function instead of inline scripts - // Probably also needs additional logic to deal with edge cases - onStateEntered = "_this setDamage 1"; // killing a unit also exits the state machine for this unit + // When the unit is killed it's no longer handled by the statemachine + onStateEntered = QFUNC(enteredStateDeath); }; }; diff --git a/addons/medical_statemachine/XEH_PREP.hpp b/addons/medical_statemachine/XEH_PREP.hpp index 9e8b75be99..c0825099af 100644 --- a/addons/medical_statemachine/XEH_PREP.hpp +++ b/addons/medical_statemachine/XEH_PREP.hpp @@ -1,6 +1,7 @@ PREP(conditionCardiacArrestTimer); PREP(conditionExecutionDeath); PREP(enteredStateCardiacArrest); +PREP(enteredStateDeath); PREP(enteredStateFatalInjury); PREP(handleStateDefault); PREP(handleStateInjured); diff --git a/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf new file mode 100644 index 0000000000..bda158a08f --- /dev/null +++ b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf @@ -0,0 +1,22 @@ +#include "script_component.hpp" +/* + * Author: SilentSpike + * Handles a unit reaching the point of death. + * + * Arguments: + * 0: The Unit + * + * Return Value: + * None + * + * Public: No + */ + +params ["_unit"]; + +// TODO: Probably also needs additional logic to deal with edge cases + +// Send a local event before death +[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent; + +_unit setDamage 1;