2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-07-02 23:53:26 +00:00
|
|
|
/*
|
2015-07-15 10:48:49 +00:00
|
|
|
* Author: SilentSpike
|
2017-08-12 13:25:48 +00:00
|
|
|
* Enter/exit spectator mode for the local player
|
2015-08-01 17:10:11 +00:00
|
|
|
*
|
2015-08-08 11:24:49 +00:00
|
|
|
* Client will be able to communicate in ACRE/TFAR as appropriate
|
2017-08-12 13:25:48 +00:00
|
|
|
* If "hide player" is true player will be hidden from group, invisible and invulnerable, but unmoved
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-10-04 12:52:54 +00:00
|
|
|
* 0: Spectator state of local client <BOOL> (default: true)
|
|
|
|
* 1: Force interface <BOOL> (default: true)
|
2017-08-12 13:25:48 +00:00
|
|
|
* 2: Hide player (if alive) <BOOL> (default: true)
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-08-12 13:25:48 +00:00
|
|
|
* None
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2015-08-08 11:24:49 +00:00
|
|
|
* [true] call ace_spectator_fnc_setSpectator
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
params [["_set",true,[true]], ["_force",true,[true]], ["_hide",true,[true]]];
|
2017-08-30 15:36:53 +00:00
|
|
|
TRACE_3("Params",_set,_force,_hide);
|
2015-07-02 23:53:26 +00:00
|
|
|
|
2015-08-08 11:24:49 +00:00
|
|
|
// Only clients can be spectators
|
2016-01-13 18:28:36 +00:00
|
|
|
if !(hasInterface) exitWith {};
|
2015-07-09 20:20:09 +00:00
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
// Let the display know if it is or isn't forced
|
|
|
|
// Could be switched after spectator has already started
|
|
|
|
GVAR(uiForced) = _force;
|
|
|
|
|
|
|
|
// Exit if no change (everything above this may need to be ran again)
|
2015-11-30 16:14:05 +00:00
|
|
|
if (_set isEqualTo GVAR(isSet)) exitWith {};
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2017-08-30 15:36:53 +00:00
|
|
|
// Delay if local player (must not be ACE_Player) does not exist
|
|
|
|
if (isNull player) exitWith {
|
2017-08-12 13:25:48 +00:00
|
|
|
[
|
2017-08-30 15:36:53 +00:00
|
|
|
{ !isNull player },
|
2017-08-12 13:25:48 +00:00
|
|
|
FUNC(setSpectator),
|
|
|
|
_this
|
|
|
|
] call CBA_fnc_waitUntilAndExecute;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Remove any current deafness and disable volume updates while spectating
|
2015-11-13 12:59:46 +00:00
|
|
|
if (["ace_hearing"] call EFUNC(common,isModLoaded)) then {
|
|
|
|
EGVAR(hearing,disableVolumeUpdate) = _set;
|
|
|
|
EGVAR(hearing,deafnessDV) = 0;
|
|
|
|
};
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// Toggle spectator mode in 3rd party radio addons
|
2015-08-03 20:38:44 +00:00
|
|
|
if (["acre_sys_radio"] call EFUNC(common,isModLoaded)) then {[_set] call acre_api_fnc_setSpectator};
|
2015-08-08 11:24:49 +00:00
|
|
|
if (["task_force_radio"] call EFUNC(common,isModLoaded)) then {[player, _set] call TFAR_fnc_forceSpectator};
|
2015-08-03 20:38:44 +00:00
|
|
|
|
2015-07-02 23:53:26 +00:00
|
|
|
if (_set) then {
|
2017-08-12 13:25:48 +00:00
|
|
|
// Initalize the camera
|
|
|
|
[true] call FUNC(cam);
|
|
|
|
|
|
|
|
// Create the display when main display is ready
|
|
|
|
[{ !isNull MAIN_DISPLAY },{ [true] call FUNC(ui) }] call CBA_fnc_waitUntilAndExecute;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2015-11-22 20:03:10 +00:00
|
|
|
// Cache current channel to switch back to on exit
|
|
|
|
GVAR(channelCache) = currentChannel;
|
|
|
|
|
|
|
|
// Channel index starts count after the 5 default channels
|
|
|
|
GVAR(channel) radioChannelAdd [player];
|
|
|
|
setCurrentChannel (5 + GVAR(channel));
|
|
|
|
|
2015-08-23 16:50:11 +00:00
|
|
|
// Cache and disable nametag settings
|
|
|
|
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
|
|
|
|
GVAR(nametagSettingCache) = [EGVAR(nametags,showPlayerNames), EGVAR(nametags,showNamesForAI)];
|
|
|
|
EGVAR(nametags,showPlayerNames) = 0;
|
|
|
|
EGVAR(nametags,showNamesForAI) = false;
|
|
|
|
};
|
2015-07-02 23:53:26 +00:00
|
|
|
} else {
|
2017-08-30 15:36:53 +00:00
|
|
|
// Kill the display (ensure main display exists, handles edge case where spectator turned off beforehand)
|
2017-08-12 13:25:48 +00:00
|
|
|
[{ !isNull MAIN_DISPLAY },{ [false] call FUNC(ui) }] call CBA_fnc_waitUntilAndExecute;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
// This variable doesn't matter anymore
|
|
|
|
GVAR(uiForced) = nil;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
|
|
|
// Terminate camera
|
2017-08-12 13:25:48 +00:00
|
|
|
[false] call FUNC(cam);
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2015-11-22 20:03:10 +00:00
|
|
|
// Remove from spectator chat
|
|
|
|
GVAR(channel) radioChannelRemove [player];
|
|
|
|
|
|
|
|
// Restore cached channel and delete cache
|
|
|
|
setCurrentChannel GVAR(channelCache);
|
|
|
|
GVAR(channelCache) = nil;
|
|
|
|
|
2015-08-23 16:50:11 +00:00
|
|
|
// Reset nametag settings
|
|
|
|
if (["ace_nametags"] call EFUNC(common,isModLoaded)) then {
|
|
|
|
EGVAR(nametags,showPlayerNames) = GVAR(nametagSettingCache) select 0;
|
|
|
|
EGVAR(nametags,showNamesForAI) = GVAR(nametagSettingCache) select 1;
|
|
|
|
GVAR(nametagSettingCache) = nil;
|
|
|
|
};
|
2015-07-02 23:53:26 +00:00
|
|
|
};
|
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
// Hide/Unhide the player if enabled and alive
|
|
|
|
if (alive player) then {
|
|
|
|
private _hidden = (_hide && _set);
|
2017-11-04 16:03:51 +00:00
|
|
|
TRACE_1("",_hidden);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// Ignore damage (vanilla and ace_medical)
|
|
|
|
player allowDamage !_hidden;
|
|
|
|
player setVariable [QEGVAR(medical,allowDamage), !_hidden];
|
|
|
|
|
|
|
|
// Move to/from group as appropriate
|
|
|
|
[player, _hidden, QGVAR(isSet), side group player] call EFUNC(common,switchToGroupSide);
|
|
|
|
|
|
|
|
// Ghosts can't talk
|
2017-10-28 16:23:18 +00:00
|
|
|
if (_hidden) then {
|
|
|
|
[player, QGVAR(isSet)] call EFUNC(common,hideUnit);
|
|
|
|
[player, QGVAR(isSet)] call EFUNC(common,muteUnit);
|
|
|
|
} else {
|
|
|
|
[player, QGVAR(isSet)] call EFUNC(common,unhideUnit);
|
|
|
|
[player, QGVAR(isSet)] call EFUNC(common,unmuteUnit);
|
|
|
|
};
|
2017-08-12 13:25:48 +00:00
|
|
|
};
|
|
|
|
|
2015-08-23 16:50:11 +00:00
|
|
|
// Reset interruptions
|
|
|
|
GVAR(interrupts) = [];
|
|
|
|
|
2015-08-03 20:38:44 +00:00
|
|
|
// Mark spectator state for reference
|
|
|
|
GVAR(isSet) = _set;
|
2017-10-26 22:40:06 +00:00
|
|
|
player setVariable [QGVAR(isSet), _set, true];
|
2015-08-02 11:47:26 +00:00
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
["ace_spectatorSet", [_set, player]] call CBA_fnc_globalEvent;
|