ACE3/addons/spectator/functions/fnc_setSpectator.sqf

78 lines
2.5 KiB
Plaintext
Raw Normal View History

/*
* Author: SilentSpike
* Sets target unit to the given spectator state
*
* Arguments:
* 0: Unit to put into spectator state <OBJECT>
2015-07-04 23:49:47 +00:00
* 1: New spectator state <BOOL> <OPTIONAL>
*
* Return Value:
2015-07-04 23:49:47 +00:00
* None <NIL>
*
* Example:
* [player, true] call ace_spectator_fnc_setSpectator
*
* Public: Yes
*/
#include "script_component.hpp"
2015-07-17 01:05:24 +00:00
params ["_unit",["_set",true,[true]],["_target",objNull,[objNull]]];
2015-07-05 20:30:19 +00:00
// 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;
// Move to/from group as appropriate
[_unit, _set, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide);
if (_set) then {
// Move and hide the player ASAP to avoid being seen
2015-07-18 12:04:23 +00:00
_unit setPos (getMarkerPos QGVAR(respawn));
// Ghosts can't talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit);
2015-07-15 11:03:54 +00:00
["open"] call FUNC(handleInterface);
} else {
2015-07-15 11:03:54 +00:00
["close"] call FUNC(handleInterface);
// Physical beings can talk
[_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit);
[_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit);
2015-07-18 17:46:46 +00:00
private "_marker";
_marker = ["respawn_west","respawn_east","respawn_guerrila","respawn_civilian"] select ([west,east,resistance,civilian] find (side group _unit));
2015-07-05 20:53:09 +00:00
_unit setPos (getMarkerPos _marker);
};
// Enable/disable input as appropriate
2015-07-15 11:03:54 +00:00
//[QGVAR(isSpectator), _set] call EFUNC(common,setDisableUserInputStatus);
// Handle common addon audio
if (["ace_hearing"] call EFUNC(common,isModLoaded)) then {EGVAR(hearing,disableVolumeUpdate) = _set};
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};
// Spectators ignore damage (vanilla and ace_medical)
_unit allowDamage !_set;
2015-07-05 00:01:27 +00:00
_unit setVariable [QEGVAR(medical,allowDamage), !_set];
2015-07-05 20:30:19 +00:00
// No theoretical change if an existing spectator was reset
if !(_set && (_unit getVariable [QGVAR(isSpectator), false])) then {
// Mark spectator state for reference
_unit setVariable [QGVAR(isSpectator), _set, true];
2015-07-05 20:30:19 +00:00
["spectatorChanged",[_set]] call EFUNC(common,localEvent);
};