From 63c034e348421d22a01e84f923841b48e76deebc Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 2 Aug 2015 12:47:26 +0100 Subject: [PATCH] Differentiate between staged and set spectators Existing variable "ace_spectator_isSpectator" split into counterparts "ace_spectator_isSet" and "ace_spectator_isStaged" in order to better manage spectator events --- addons/spectator/XEH_postInit.sqf | 2 +- .../spectator/functions/fnc_setSpectator.sqf | 11 ++++++++++- .../spectator/functions/fnc_stageSpectator.sqf | 18 +++++++++--------- addons/spectator/functions/fnc_updateUnits.sqf | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index bad3758c19..45ac78e89c 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -2,7 +2,7 @@ //#include "initKeybinds.sqf"; // Add interaction menu exception -["isNotSpectating", {!((_this select 0) getVariable [QGVAR(isSpectator), false])}] call EFUNC(common,addCanInteractWithCondition); +["isNotSpectating", {!(GETVAR((_this select 0),GVAR(isStaged),false))}] call EFUNC(common,addCanInteractWithCondition); ["SettingsInitialized", { GVAR(availableModes) = [[0,1,2], [1,2], [0], [1], [2]] select GVAR(restrictModes); diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index f4dc86c3da..2f8e1d3c2d 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -23,6 +23,9 @@ params ["_unit", ["_set",true,[true]]]; +// No change, no service (but allow spectators to be reset) +if !(_set || (GETVAR(_unit,GVAR(isSet),false))) exitWith {}; + // Only run for player units if !(isPlayer _unit) exitWith {}; @@ -41,4 +44,10 @@ if (["ace_hearing"] call EFUNC(common,isModLoaded)) then {EGVAR(hearing,disableV if (["acre_sys_radio"] call EFUNC(common,isModLoaded)) then {[_set] call acre_api_fnc_setSpectator}; if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {[_unit, _set] call TFAR_fnc_forceSpectator}; -["spectatorSet",[_set]] call EFUNC(common,localEvent); +// No theoretical change if an existing spectator was reset +if !(_set isEqualTo (GETVAR(_unit,GVAR(isSet),false))) then { + // Mark spectator state for reference + _unit setVariable [QGVAR(isSet), _set, true]; + + ["spectatorSet",[_set]] call EFUNC(common,localEvent); +}; diff --git a/addons/spectator/functions/fnc_stageSpectator.sqf b/addons/spectator/functions/fnc_stageSpectator.sqf index 2f6741e35a..84bd6ffced 100644 --- a/addons/spectator/functions/fnc_stageSpectator.sqf +++ b/addons/spectator/functions/fnc_stageSpectator.sqf @@ -23,8 +23,8 @@ params ["_unit", ["_set",true,[true]]]; -// No change, no service (but allow spectators who respawn to be reset) -if !(_set || (GETVAR(_unit,GVAR(isSpectator),false))) exitWith {}; +// No change, no service (but allow spectators to be reset) +if !(_set || (GETVAR(_unit,GVAR(isStaged),false))) exitWith {}; // Only run for player units if !(isPlayer _unit) exitWith {}; @@ -37,7 +37,7 @@ if !(local _unit) exitwith { _unit enableSimulation !_set; // Move to/from group as appropriate -[_unit, _set, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide); +[_unit, _set, QGVAR(isStaged), side group _unit] call EFUNC(common,switchToGroupSide); if (_set) then { // Move and hide the player ASAP to avoid being seen @@ -45,12 +45,12 @@ if (_set) then { _unit setPos (getMarkerPos QGVAR(respawn)); // Ghosts can't talk - [_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit); - [_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit); + [_unit, QGVAR(isStaged)] call EFUNC(common,hideUnit); + [_unit, QGVAR(isStaged)] call EFUNC(common,muteUnit); } else { // Physical beings can talk - [_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit); - [_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit); + [_unit, QGVAR(isStaged)] call EFUNC(common,unhideUnit); + [_unit, QGVAR(isStaged)] call EFUNC(common,unmuteUnit); _unit setPosATL GVAR(oldPos); }; @@ -60,9 +60,9 @@ _unit allowDamage !_set; _unit setVariable [QEGVAR(medical,allowDamage), !_set]; // No theoretical change if an existing spectator was reset -if !(_set isEqualTo (GETVAR(_unit,GVAR(isSpectator),false))) then { +if !(_set isEqualTo (GETVAR(_unit,GVAR(isStaged),false))) then { // Mark spectator state for reference - _unit setVariable [QGVAR(isSpectator), _set, true]; + _unit setVariable [QGVAR(isStaged), _set, true]; ["spectatorStaged",[_set]] call EFUNC(common,localEvent); }; diff --git a/addons/spectator/functions/fnc_updateUnits.sqf b/addons/spectator/functions/fnc_updateUnits.sqf index 0393fa0e36..ef8fc3b4f1 100644 --- a/addons/spectator/functions/fnc_updateUnits.sqf +++ b/addons/spectator/functions/fnc_updateUnits.sqf @@ -55,7 +55,7 @@ _filteredUnits = []; {(_x isKindOf "CAManBase")} && {(side group _x) in _sides} && // Side filter {simulationEnabled _x} && - {!(_x getVariable [QGVAR(isSpectator), false])} // Who watches the watchmen? + {!(_x getVariable [QGVAR(isStaged), false])} // Who watches the watchmen? ) then { _filteredUnits pushBack _x; };