From ff4fce39501ab0938f8d791b4a59d2da4a4bf1d7 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 3 Jul 2015 00:53:26 +0100 Subject: [PATCH] Initial enter/exit function implementation --- addons/spectator/XEH_postInit.sqf | 37 +--------- addons/spectator/XEH_preInit.sqf | 1 + .../spectator/functions/fnc_setSpectator.sqf | 71 +++++++++++++++++++ 3 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 addons/spectator/functions/fnc_setSpectator.sqf diff --git a/addons/spectator/XEH_postInit.sqf b/addons/spectator/XEH_postInit.sqf index 337c8803a7..e59c4daf2e 100644 --- a/addons/spectator/XEH_postInit.sqf +++ b/addons/spectator/XEH_postInit.sqf @@ -42,41 +42,6 @@ 999999 cutText ["", "BLACK", _delay]; }]; - player addEventHandler ["Respawn", { - // Move the player ASAP - player setPosATL GVAR(penPos); - - if (!isNil QGVAR(cam)) then {["Exit"] call FUNC(camera)}; - if (isClass (configFile >> "CfgPatches" >> "ace_hearing")) then {EGVAR(hearing,disableVolumeUpdate) = true}; - if (isClass (configFile >> "CfgPatches" >> "acre_sys_radio")) then {[true] call acre_api_fnc_setSpectator}; - if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then {[player, true] call TFAR_fnc_forceSpectator}; - - if !GVAR(modulePos) then { - _corpse = _this select 1; - if (!isNil "_corpse") then { - if (!isNull _corpse) then { - GVAR(startingPos) = getPosATL _corpse; - }; - }; - }; - - // Disable damage (vanilla and ace_medical) - player allowDamage false; - player setVariable ["ace_medical_allowDamage", false]; - - // Hide the player - [player] joinSilent grpNull; - hideObjectGlobal player; - - // Prevent drowning and vision blur - if (surfaceisWater GVAR(penPos)) then { - player forceAddUniform "U_B_Wetsuit"; - player addVest "V_RebreatherB"; - }; - - 0 fadeSound 0; - 999999 cutText ["", "BLACK FADED", 0]; - ["Init", [true]] call FUNC(camera); - }]; + player addEventHandler ["Respawn", FUNC(setSpectator)]; }] call EFUNC(common,addEventHandler); diff --git a/addons/spectator/XEH_preInit.sqf b/addons/spectator/XEH_preInit.sqf index e5243a921b..c4d1205776 100644 --- a/addons/spectator/XEH_preInit.sqf +++ b/addons/spectator/XEH_preInit.sqf @@ -19,6 +19,7 @@ PREP(map); PREP(moduleSpectator); PREP(overlay); PREP(respawn); +PREP(setSpectator); PREP(sideColour); PREP(status); PREP(trackUnits); diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf new file mode 100644 index 0000000000..424769b1a8 --- /dev/null +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -0,0 +1,71 @@ +/* + * Author: voiper, SilentSpike + * Sets local player to the given spectator state + * + * Arguments: + * 0: Player unit (unused, result of EH) + * 1: Spectator camera target + * 2: New spectator state + * + * Return Value: + * nil + * + * Example: + * [player, _killer] call ace_spectator_fnc_setSpectator + * + * Public: Yes + */ + +#include "script_component.hpp" + +_unit = player; +_target = _this select 1; +_set = if (count _this > 2) then {_this select 2} else {true}; + +if (_set isEqualTo (_unit getVariable [QGVAR(isSpectator), false])) exitWith {}; + +// Spectators aren't physical entities (todo: this command has to be executed on the server) +_unit hideObjectGlobal _set; + +if (isClass (configFile >> "CfgPatches" >> "ace_hearing")) then {EGVAR(hearing,disableVolumeUpdate) = _set}; +if (isClass (configFile >> "CfgPatches" >> "acre_sys_radio")) then {[_set] call acre_api_fnc_setSpectator}; +if (isClass (configFile >> "CfgPatches" >> "task_force_radio")) then {[_unit, _set] call TFAR_fnc_forceSpectator}; + +if (_set) then { + // Move the player ASAP to avoid being seen + _unit setPosATL GVAR(penPos); + + if !(GVAR(modulePos)) then { + if !(isNull _target) then { + GVAR(startingPos) = getPosATL _target; + }; + }; + + // Spectators shouldn't show in group UI + [_unit] joinSilent grpNull; + + // Prevent drowning and vision blur + if (surfaceisWater GVAR(penPos)) then { + _unit forceAddUniform "U_B_Wetsuit"; + _unit addVest "V_RebreatherB"; + }; + + // Dead men can't talk + [_unit, "isSpectator"] call EFUNC(common,muteUnit); + + 0 fadeSound 0; + 999999 cutText ["", "BLACK FADED", 0]; + ["Init", [true]] call FUNC(camera); +} else { + // Code to exit spectator and "respawn" player goes here (WIP) + ["Exit"] call FUNC(camera); +}; + +// Spectators ignore damage (vanilla and ace_medical) +_unit allowDamage !_set; +_unit setVariable ["ace_medical_allowDamage", !_set]; + +// Mark spectator state for external reference +[_unit,QGVAR(isSpectator),_set] call EFUNC(common,setVariableJIP); + +["spectatorChanged",[_set]] call EFUNC(common,localEvent);