From 9cf44b1d3235e782b49e80abdda83ea4173baf18 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Apr 2015 15:46:41 +0200 Subject: [PATCH 1/4] initial commit --- addons/common/functions/fnc_muteUnit.sqf | 17 +++++++++++++++-- addons/common/functions/fnc_unmuteUnit.sqf | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/addons/common/functions/fnc_muteUnit.sqf b/addons/common/functions/fnc_muteUnit.sqf index 8edf9df391..f3c5dcff9d 100644 --- a/addons/common/functions/fnc_muteUnit.sqf +++ b/addons/common/functions/fnc_muteUnit.sqf @@ -5,21 +5,34 @@ * * Argument: * 0: Unit (Object) + * 1: Reason to mute the unit (String) * * Return value: * Nothing */ #include "script_component.hpp" -private ["_unit", "_speaker"]; +private ["_unit", "_reason"]; _unit = _this select 0; +_reason = _this select 1; if (isNull _unit) exitWith {}; +// add reason to mute to the unit +private "_muteUnitReasons"; +_muteUnitReasons = _unit getVariable [QGVAR(muteUnitReasons), []]; + +if !(_reason in _muteUnitReasons) then { + _muteUnitReasons pushBack _reason; + _unit setVariable [QGVAR(muteUnitReasons), _muteUnitReasons, true]; +}; + +private "_speaker"; _speaker = speaker _unit; + if (_speaker == "ACE_NoVoice") exitWith {}; -[0, "{(_this select 1) setSpeaker 'ACE_NoVoice'}", _unit, "ACE_Speaker"] call FUNC(execPersistentFnc); +["setSpeaker", _unit, [_unit, "ACE_NoVoice"]] call FUNC(targetEvent); _unit setVariable ["ACE_OriginalSpeaker", _speaker, true]; diff --git a/addons/common/functions/fnc_unmuteUnit.sqf b/addons/common/functions/fnc_unmuteUnit.sqf index 8de7708d4b..14ecef290b 100644 --- a/addons/common/functions/fnc_unmuteUnit.sqf +++ b/addons/common/functions/fnc_unmuteUnit.sqf @@ -1,23 +1,36 @@ /* * Author: commy2 * - * Unmutes the unit. + * Unmutes the unit. Only unmutes if the last reason was removed. * * Argument: * 0: Unit (Object) + * 1: Reason to unmute the unit. (String) * * Return value: * Nothing */ #include "script_component.hpp" -private ["_unit", "_speaker"]; +private ["_unit", "_reason"]; _unit = _this select 0; +_reason = _this select 1; if (isNull _unit) exitWith {}; +// remove reason to mute to the unit +private "_muteUnitReasons"; +_muteUnitReasons = _unit getVariable [QGVAR(muteUnitReasons), []]; + +if (_reason in _muteUnitReasons) then { + _muteUnitReasons deleteAt (_muteUnitReasons find _reason); + _unit setVariable [QGVAR(muteUnitReasons), _muteUnitReasons, true]; +}; + +private "_speaker"; _speaker = _unit getVariable ["ACE_OriginalSpeaker", ""]; + if (_speaker == "") exitWith {}; -[0, format ["{(_this select 1) setSpeaker '%1'}", _speaker], _unit, "ACE_Speaker"] call FUNC(execPersistentFnc); +["setSpeaker", _unit, [_unit, _speaker]] call FUNC(targetEvent); From b9077888aafeb25848c1de7aba5dd2fe15fe0c07 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Apr 2015 20:26:43 +0200 Subject: [PATCH 2/4] unmute handleing --- addons/common/functions/fnc_unmuteUnit.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/common/functions/fnc_unmuteUnit.sqf b/addons/common/functions/fnc_unmuteUnit.sqf index 14ecef290b..94ba72f5a4 100644 --- a/addons/common/functions/fnc_unmuteUnit.sqf +++ b/addons/common/functions/fnc_unmuteUnit.sqf @@ -28,6 +28,9 @@ if (_reason in _muteUnitReasons) then { _unit setVariable [QGVAR(muteUnitReasons), _muteUnitReasons, true]; }; +// don't unmute if there is another mute reason! +if (count _muteUnitReasons > 0) exitWith {}; + private "_speaker"; _speaker = _unit getVariable ["ACE_OriginalSpeaker", ""]; From 54f29d75f51c18708540cb82cedc9b1fe1d7c3af Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 12 Apr 2015 10:05:49 +0200 Subject: [PATCH 3/4] functions to mute unit --- addons/common/CfgEventHandlers.hpp | 5 +++++ addons/common/XEH_postInit.sqf | 1 + addons/common/XEH_preInit.sqf | 1 + .../common/functions/fnc_muteUnitHandleRespawn.sqf | 12 ++++++++++++ addons/common/functions/fnc_restoreVariablesJIP.sqf | 3 --- 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 addons/common/functions/fnc_muteUnitHandleRespawn.sqf diff --git a/addons/common/CfgEventHandlers.hpp b/addons/common/CfgEventHandlers.hpp index eef90451ae..b31785cfaf 100644 --- a/addons/common/CfgEventHandlers.hpp +++ b/addons/common/CfgEventHandlers.hpp @@ -41,4 +41,9 @@ class Extended_Respawn_EventHandlers { respawn = QUOTE(_this call FUNC(resetAllDefaults)); }; }; + class CAManBase { + class GVAR(muteUnit) { + respawn = QUOTE(_this call FUNC(muteUnitHandleRespawn)); + }; + }; }; diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index f09dae0eb3..e470e91c95 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -35,6 +35,7 @@ if (hasInterface) then { ["setDir", {(_this select 0) setDir (_this select 1)}] call FUNC(addEventhandler); ["setFuel", {(_this select 0) setFuel (_this select 1)}] call FUNC(addEventhandler); +["setSpeaker", {(_this select 0) setSpeaker (_this select 1)}] call FUNC(addEventhandler); // hack to get PFH to work in briefing [QGVAR(onBriefingPFH), "onEachFrame", { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 8d62e9df70..d013138759 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(muteUnitHandleRespawn); PREP(numberToDigits); PREP(numberToDigitsString); PREP(numberToString); diff --git a/addons/common/functions/fnc_muteUnitHandleRespawn.sqf b/addons/common/functions/fnc_muteUnitHandleRespawn.sqf new file mode 100644 index 0000000000..021b083bfd --- /dev/null +++ b/addons/common/functions/fnc_muteUnitHandleRespawn.sqf @@ -0,0 +1,12 @@ +// by commy2 +#include "script_component.hpp" + +private "_unit"; + +_unit = _this select 0; + +// setVariable is broken on JIP after respawn +_unit setVariable [QGVAR(muteUnitReasons), _unit getVariable [QGVAR(muteUnitReasons), []], true]; + +// fix mp issues with respawning and the speaker +["setSpeaker", [_unit, speaker _unit]] call FUNC(globalEvent); diff --git a/addons/common/functions/fnc_restoreVariablesJIP.sqf b/addons/common/functions/fnc_restoreVariablesJIP.sqf index 2c173a054c..ca185082cb 100644 --- a/addons/common/functions/fnc_restoreVariablesJIP.sqf +++ b/addons/common/functions/fnc_restoreVariablesJIP.sqf @@ -23,6 +23,3 @@ _respawnVariables pushBack "ACE_PersistentFunctions"; { _unit setVariable [_x, _unit getVariable _x, true]; } forEach _respawnVariables; - -// fix speaker after respawn -[_unit, format ["{_this setSpeaker '%1'}", speaker _unit], 2] call FUNC(execRemoteFnc); From e87f491470fc9b8a928470779f6887fed2051afd Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 12 Apr 2015 11:17:58 +0200 Subject: [PATCH 4/4] 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); }];