2015-07-02 23:53:26 +00:00
|
|
|
/*
|
2015-07-15 10:48:49 +00:00
|
|
|
* Author: SilentSpike
|
2015-07-09 20:20:09 +00:00
|
|
|
* Sets target unit to the given spectator state
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-07-09 20:20:09 +00:00
|
|
|
* 0: Unit to put into spectator state <OBJECT>
|
2015-07-04 23:49:47 +00:00
|
|
|
* 1: New spectator state <BOOL> <OPTIONAL>
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-07-04 23:49:47 +00:00
|
|
|
* None <NIL>
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-07-09 20:20:09 +00:00
|
|
|
* [player, true] call ace_spectator_fnc_setSpectator
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-07-17 01:05:24 +00:00
|
|
|
params ["_unit",["_set",true,[true]],["_target",objNull,[objNull]]];
|
2015-07-02 23:53:26 +00:00
|
|
|
|
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 {};
|
2015-07-02 23:53:26 +00:00
|
|
|
|
2015-07-09 20:20:09 +00:00
|
|
|
// Only run for player units
|
|
|
|
if !(isPlayer _unit) exitWith {};
|
|
|
|
|
|
|
|
if !(local _unit) exitwith {
|
|
|
|
[[_unit, _set, _target], QFUNC(setSpectator), _unit] call EFUNC(common,execRemoteFnc);
|
|
|
|
};
|
|
|
|
|
2015-07-03 12:13:02 +00:00
|
|
|
// Prevent player falling into water
|
|
|
|
_unit enableSimulation !_set;
|
2015-07-02 23:53:26 +00:00
|
|
|
|
2015-07-15 10:48:49 +00:00
|
|
|
// Move to/from group as appropriate
|
|
|
|
[_unit, _set, QGVAR(isSpectator), side group _unit] call EFUNC(common,switchToGroupSide);
|
|
|
|
|
2015-07-02 23:53:26 +00:00
|
|
|
if (_set) then {
|
2015-07-04 18:41:18 +00:00
|
|
|
// Move and hide the player ASAP to avoid being seen
|
2015-07-18 12:04:23 +00:00
|
|
|
_unit setPos (getMarkerPos QGVAR(respawn));
|
2015-07-03 12:13:02 +00:00
|
|
|
|
2015-07-04 18:41:18 +00:00
|
|
|
// Ghosts can't talk
|
2015-07-09 20:20:09 +00:00
|
|
|
[_unit, QGVAR(isSpectator)] call EFUNC(common,hideUnit);
|
|
|
|
[_unit, QGVAR(isSpectator)] call EFUNC(common,muteUnit);
|
2015-07-02 23:53:26 +00:00
|
|
|
|
2015-07-15 11:03:54 +00:00
|
|
|
["open"] call FUNC(handleInterface);
|
2015-07-02 23:53:26 +00:00
|
|
|
} else {
|
2015-07-15 11:03:54 +00:00
|
|
|
["close"] call FUNC(handleInterface);
|
2015-07-03 12:13:02 +00:00
|
|
|
|
2015-07-04 18:41:18 +00:00
|
|
|
// Physical beings can talk
|
2015-07-09 20:20:09 +00:00
|
|
|
[_unit, QGVAR(isSpectator)] call EFUNC(common,unhideUnit);
|
|
|
|
[_unit, QGVAR(isSpectator)] call EFUNC(common,unmuteUnit);
|
|
|
|
|
2015-07-18 17:46:46 +00:00
|
|
|
private "_marker";
|
2015-07-15 10:48:49 +00:00
|
|
|
_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);
|
2015-07-02 23:53:26 +00:00
|
|
|
};
|
|
|
|
|
2015-07-15 10:48:49 +00:00
|
|
|
// Enable/disable input as appropriate
|
2015-07-15 11:03:54 +00:00
|
|
|
//[QGVAR(isSpectator), _set] call EFUNC(common,setDisableUserInputStatus);
|
2015-07-15 10:48:49 +00:00
|
|
|
|
2015-07-03 12:13:02 +00:00
|
|
|
// Handle common addon audio
|
2015-07-04 18:41:18 +00:00
|
|
|
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};
|
2015-07-03 12:13:02 +00:00
|
|
|
|
2015-07-02 23:53:26 +00:00
|
|
|
// 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-02 23:53:26 +00:00
|
|
|
|
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
|
2015-07-15 10:48:49 +00:00
|
|
|
_unit setVariable [QGVAR(isSpectator), _set, true];
|
2015-07-02 23:53:26 +00:00
|
|
|
|
2015-07-05 20:30:19 +00:00
|
|
|
["spectatorChanged",[_set]] call EFUNC(common,localEvent);
|
|
|
|
};
|