From e87f491470fc9b8a928470779f6887fed2051afd Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 12 Apr 2015 11:17:58 +0200 Subject: [PATCH] mute implementation in noradio, handle post init on remote units --- addons/common/CfgEventHandlers.hpp | 3 ++ addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_muteUnit.sqf | 2 +- .../functions/fnc_muteUnitHandleInitPost.sqf | 11 +++++++ addons/noradio/XEH_post_initClient.sqf | 32 +++++++++---------- addons/noradio/XEH_post_initServer.sqf | 6 +--- 6 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 addons/common/functions/fnc_muteUnitHandleInitPost.sqf diff --git a/addons/common/CfgEventHandlers.hpp b/addons/common/CfgEventHandlers.hpp index b31785cfaf..ce0938f063 100644 --- a/addons/common/CfgEventHandlers.hpp +++ b/addons/common/CfgEventHandlers.hpp @@ -26,6 +26,9 @@ class Extended_InitPost_EventHandlers { class GVAR(forceWalk) { init = QUOTE(if (local (_this select 0)) then {_this call FUNC(applyForceWalkStatus);};); }; + class GVAR(muteUnit) { + init = QUOTE(_this call FUNC(muteUnitHandleInitPost)); + }; }; }; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index d013138759..b5382d0b5e 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -124,6 +124,7 @@ PREP(moduleCheckPBOs); PREP(moduleLSDVehicles); PREP(moveToTempGroup); PREP(muteUnit); +PREP(muteUnitHandleInitPost); PREP(muteUnitHandleRespawn); PREP(numberToDigits); PREP(numberToDigitsString); diff --git a/addons/common/functions/fnc_muteUnit.sqf b/addons/common/functions/fnc_muteUnit.sqf index f3c5dcff9d..5c496ea58e 100644 --- a/addons/common/functions/fnc_muteUnit.sqf +++ b/addons/common/functions/fnc_muteUnit.sqf @@ -33,6 +33,6 @@ _speaker = speaker _unit; if (_speaker == "ACE_NoVoice") exitWith {}; -["setSpeaker", _unit, [_unit, "ACE_NoVoice"]] call FUNC(targetEvent); +["setSpeaker", [_unit, "ACE_NoVoice"]] call FUNC(globalEvent); _unit setVariable ["ACE_OriginalSpeaker", _speaker, true]; diff --git a/addons/common/functions/fnc_muteUnitHandleInitPost.sqf b/addons/common/functions/fnc_muteUnitHandleInitPost.sqf new file mode 100644 index 0000000000..f0abcfcf01 --- /dev/null +++ b/addons/common/functions/fnc_muteUnitHandleInitPost.sqf @@ -0,0 +1,11 @@ +// by commy2 +#include "script_component.hpp" + +private "_unit"; + +_unit = _this select 0; + +// setSpeaker gets overwritten after init on remote units; if unit is muted, setSpeaker again +if (count (_unit getVariable [QGVAR(muteUnitReasons), []]) > 0) then { + ["setSpeaker", [_unit, "ACE_NoVoice"]] call FUNC(localEvent); +}; diff --git a/addons/noradio/XEH_post_initClient.sqf b/addons/noradio/XEH_post_initClient.sqf index e192a101f8..4f35a1ced9 100644 --- a/addons/noradio/XEH_post_initClient.sqf +++ b/addons/noradio/XEH_post_initClient.sqf @@ -1,31 +1,29 @@ // by commy2 - #include "script_component.hpp" +/* _setupPlayer = { - if (!isNull ACE_player) then { - [(_this select 1)] call cba_fnc_removePerFrameHandler; + if (!isNull ACE_player) then { + [(_this select 1)] call cba_fnc_removePerFrameHandler; - [ACE_player] call EFUNC(common,muteUnit); - ACE_player setVariable [QGVAR(isMuted), true, true]; - }; + [ACE_player, "isPlayer"] call EFUNC(common,muteUnit); + }; }; [_setupPlayer, 0, []] call CBA_fnc_addPerFrameHandler; +*/ + +if (!hasInterface) exitWith {}; // Mutes/unmutes units when the player changes ["playerChanged", { - EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer); + EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer); - // On player change mute the new player - [_newPlayer] call EFUNC(common,muteUnit); - _newPlayer setVariable [QGVAR(isMuted), true, true]; - - // Unmute the old player - //@todo: sort interaction with medical system - if (!(_oldPlayer getVariable ["ACE_isUnconscious", false]) && {alive _oldPlayer}) then { - [_oldPlayer] call EFUNC(common,unMuteUnit); - }; - _oldPlayer setVariable [QGVAR(isMuted), false, true]; + // On player change mute the new player + [_newPlayer, "isPlayer"] call EFUNC(common,muteUnit); + // Unmute the old player + if (alive _oldPlayer) then { + [_oldPlayer, "isPlayer"] call EFUNC(common,unmuteUnit); + }; }] call EFUNC(common,addEventhandler); diff --git a/addons/noradio/XEH_post_initServer.sqf b/addons/noradio/XEH_post_initServer.sqf index 90b7473144..ae2dc16ec1 100644 --- a/addons/noradio/XEH_post_initServer.sqf +++ b/addons/noradio/XEH_post_initServer.sqf @@ -1,10 +1,6 @@ // by commy2 - #include "script_component.hpp" addMissionEventHandler ["HandleDisconnect", { - if !((_this select 0) getVariable ["ACE_isUnconscious", false]) then { //@ToDo: ai waking up will be silent? - _this call EFUNC(common,unMuteUnit); - }; - (_this select 0) setVariable [QGVAR(isMuted), false, true]; + [_this select 0, "isPlayer"] call EFUNC(common,unmuteUnit); }];