diff --git a/addons/spectator/functions/fnc_handleKilled.sqf b/addons/spectator/functions/fnc_handleKilled.sqf index acaa4429d3..a69cce79f9 100644 --- a/addons/spectator/functions/fnc_handleKilled.sqf +++ b/addons/spectator/functions/fnc_handleKilled.sqf @@ -14,15 +14,9 @@ #include "script_component.hpp" -private ["_unit","_killer","_delay"]; +private ["_unit","_killer"]; _unit = _this select 0; _killer = _this select 1; -//Cache resettable info if player died while not already a spectator -if !(_unit getVariable [QGVAR(isSpectator),false]) then { - GVAR(cachedGroup) = group _unit; - GVAR(cachedSide) = side GVAR(cachedGroup); -}; - // Remove from group to prevent appearing on HUD upon respawn -[_unit] joinSilent grpNull; +[_unit, true, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide); diff --git a/addons/spectator/functions/fnc_setSpectator.sqf b/addons/spectator/functions/fnc_setSpectator.sqf index 0d373bd88d..6bf67c43ea 100644 --- a/addons/spectator/functions/fnc_setSpectator.sqf +++ b/addons/spectator/functions/fnc_setSpectator.sqf @@ -1,41 +1,49 @@ /* * Author: voiper, SilentSpike - * Sets local player to the given spectator state + * Sets target unit to the given spectator state * * Arguments: - * 0: Spectator camera target + * 0: Unit to put into spectator state * 1: New spectator state + * 2: Spectator camera target * * Return Value: * None * * Example: - * [_killer] call ace_spectator_fnc_setSpectator + * [player, true] call ace_spectator_fnc_setSpectator * * Public: Yes */ #include "script_component.hpp" -private ["_unit","_target","_set"]; -_unit = player; -_target = _this select 0; +private ["_unit","_set","_target"]; +_unit = _this select 0; _set = if (count _this > 1) then {_this select 1} else {true}; +_target = if (count _this > 2) then {_this select 2} else {objNull}; // No change, no service (but allow spectators who respawn to be reset) if !(_set || (_unit getVariable [QGVAR(isSpectator), false])) exitWith {}; +// Only run for player units +if !(isPlayer _unit) exitWith {}; + +if !(local _unit) exitwith { + [[_unit, _set, _target], QFUNC(setSpectator), _unit] call EFUNC(common,execRemoteFnc); +}; + // Prevent player falling into water _unit enableSimulation !_set; if (_set) then { // Move and hide the player ASAP to avoid being seen _unit setPosASL (getMarkerPos QGVAR(respawn)); - [_unit] joinSilent grpNull; + [_unit, true, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide); // Ghosts can't talk - [_unit, "isSpectator"] call EFUNC(common,hideUnit); - [_unit, "isSpectator"] call EFUNC(common,muteUnit); + [_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit); + [_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit); if !(GVAR(modulePos)) then { if !(isNull _target) then { @@ -48,15 +56,11 @@ if (_set) then { ["Exit"] call FUNC(camera); // Physical beings can talk - [_unit, "isSpectator"] call EFUNC(common,unhideUnit); - [_unit, "isSpectator"] call EFUNC(common,unmuteUnit); + [_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit); + [_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit); - // Don't create groups unless necessary (arma has a group limit) - if (isNull GVAR(cachedGroup)) then { - [_unit] joinSilent (createGroup GVAR(cachedSide)); - } else { - [_unit] joinSilent GVAR(cachedGroup); - }; + // Return to previous group + [_unit, false, QGVAR(isSpectator)] call EFUNC(common,switchToGroupSide); private ["_marker"]; _marker = ["respawn_west","respawn_east","respawn_guerrila","respawn_civilian"] select ([west,east,resistance,civilian] find GVAR(cachedSide));