2015-07-02 23:53:26 +00:00
|
|
|
/*
|
2015-07-15 10:48:49 +00:00
|
|
|
* Author: SilentSpike
|
2015-08-08 11:24:49 +00:00
|
|
|
* Sets local client to the given spectator state (virtually)
|
2015-08-01 17:10:11 +00:00
|
|
|
* To physically handle a spectator see ace_spectator_fnc_stageSpectator
|
|
|
|
*
|
2015-08-08 11:24:49 +00:00
|
|
|
* Client will be able to communicate in ACRE/TFAR as appropriate
|
2015-08-01 17:10:11 +00:00
|
|
|
* The spectator interface will be opened/closed
|
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)
|
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-08-08 11:24:49 +00:00
|
|
|
* [true] call ace_spectator_fnc_setSpectator
|
2015-07-02 23:53:26 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-10-04 12:52:54 +00:00
|
|
|
params [["_set",true,[true]], ["_force",true,[true]]];
|
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
|
|
|
|
2015-08-23 16:50:11 +00:00
|
|
|
// Exit if no change
|
2015-11-30 16:14:05 +00:00
|
|
|
if (_set isEqualTo GVAR(isSet)) exitWith {};
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2015-08-03 20:38:44 +00:00
|
|
|
// Handle common addon audio
|
2015-11-13 12:59:46 +00:00
|
|
|
if (["ace_hearing"] call EFUNC(common,isModLoaded)) then {
|
|
|
|
EGVAR(hearing,disableVolumeUpdate) = _set;
|
|
|
|
EGVAR(hearing,deafnessDV) = 0;
|
|
|
|
};
|
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 {
|
2015-08-23 16:50:11 +00:00
|
|
|
// Initalize camera variables
|
|
|
|
GVAR(camBoom) = 0;
|
|
|
|
GVAR(camDolly) = [0,0];
|
|
|
|
GVAR(camGun) = false;
|
|
|
|
|
|
|
|
// Initalize display variables
|
|
|
|
GVAR(ctrlKey) = false;
|
|
|
|
GVAR(heldKeys) = [];
|
|
|
|
GVAR(heldKeys) resize 255;
|
|
|
|
GVAR(mouse) = [false,false];
|
|
|
|
GVAR(mousePos) = [0.5,0.5];
|
|
|
|
|
|
|
|
// Update units before opening to support pre-set camera unit
|
|
|
|
[] call FUNC(updateUnits);
|
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
// Initalize the camera objects
|
|
|
|
GVAR(freeCamera) = "Camera" camCreate (ASLtoATL GVAR(camPos));
|
|
|
|
GVAR(unitCamera) = "Camera" camCreate [0,0,0];
|
|
|
|
GVAR(targetCamera) = "Camera" camCreate [0,0,0];
|
|
|
|
|
|
|
|
// Initalize view
|
|
|
|
GVAR(unitCamera) camSetTarget GVAR(targetCamera);
|
|
|
|
GVAR(unitCamera) camCommit 0;
|
2015-08-23 16:50:11 +00:00
|
|
|
[] call FUNC(transitionCamera);
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
// Close map and clear the chat
|
2015-08-23 16:50:11 +00:00
|
|
|
openMap [false,false];
|
|
|
|
clearRadio;
|
2015-11-22 20:03:10 +00:00
|
|
|
enableRadio false;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
|
|
|
// Disable BI damage effects
|
|
|
|
BIS_fnc_feedback_allowPP = false;
|
|
|
|
|
|
|
|
// Close any open dialogs
|
|
|
|
while {dialog} do {
|
|
|
|
closeDialog 0;
|
|
|
|
};
|
|
|
|
|
2015-09-25 10:51:13 +00:00
|
|
|
[{
|
2016-01-13 18:28:36 +00:00
|
|
|
disableSerialization;
|
2015-09-25 10:51:13 +00:00
|
|
|
// Create the display
|
2016-01-13 18:28:36 +00:00
|
|
|
_display = (findDisplay 46) createDisplay QGVAR(interface);
|
2015-10-04 12:52:54 +00:00
|
|
|
|
|
|
|
// If not forced, make esc end spectator
|
|
|
|
if (_this) then {
|
2016-01-13 18:28:36 +00:00
|
|
|
_display displayAddEventHandler ["KeyDown", {
|
2015-10-04 12:52:54 +00:00
|
|
|
if (_this select 1 == 1) then {
|
2016-05-07 20:17:21 +00:00
|
|
|
[false] call FUNC(setSpectator);
|
2015-10-04 12:52:54 +00:00
|
|
|
true
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
};
|
2016-05-22 13:27:24 +00:00
|
|
|
}, !_force] call CBA_fnc_execNextFrame;
|
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 {
|
2015-08-23 16:50:11 +00:00
|
|
|
// Close any open dialogs (could be interrupts)
|
|
|
|
while {dialog} do {
|
|
|
|
closeDialog 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Kill the display
|
2016-01-13 18:28:36 +00:00
|
|
|
(GETUVAR(GVAR(interface),displayNull)) closeDisplay 0;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
|
|
|
// Terminate camera
|
2015-09-09 22:21:49 +00:00
|
|
|
GVAR(freeCamera) cameraEffect ["terminate", "back"];
|
|
|
|
camDestroy GVAR(freeCamera);
|
|
|
|
camDestroy GVAR(unitCamera);
|
|
|
|
camDestroy GVAR(targetCamera);
|
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;
|
|
|
|
|
|
|
|
// Clear any residual spectator chat
|
2015-08-23 16:50:11 +00:00
|
|
|
clearRadio;
|
2015-11-22 20:03:10 +00:00
|
|
|
enableRadio true;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
|
|
|
// Return to player view
|
|
|
|
player switchCamera "internal";
|
|
|
|
|
|
|
|
// Enable BI damage effects
|
|
|
|
BIS_fnc_feedback_allowPP = true;
|
|
|
|
|
|
|
|
// Cleanup camera variables
|
|
|
|
GVAR(camBoom) = nil;
|
|
|
|
GVAR(camDolly) = nil;
|
|
|
|
GVAR(camGun) = nil;
|
2015-09-09 22:21:49 +00:00
|
|
|
GVAR(freeCamera) = nil;
|
|
|
|
GVAR(unitCamera) = nil;
|
|
|
|
GVAR(targetCamera) = nil;
|
2015-08-23 16:50:11 +00:00
|
|
|
|
2016-01-01 06:14:48 +00:00
|
|
|
//Kill these PFEH handlers now because the PFEH can run before the `onunload` event is handled
|
|
|
|
GVAR(camHandler) = nil;
|
|
|
|
GVAR(compHandler) = nil;
|
|
|
|
GVAR(toolHandler) = nil;
|
|
|
|
|
2015-08-23 16:50:11 +00:00
|
|
|
// Cleanup display variables
|
|
|
|
GVAR(ctrlKey) = nil;
|
|
|
|
GVAR(heldKeys) = nil;
|
|
|
|
GVAR(mouse) = nil;
|
|
|
|
GVAR(mousePos) = nil;
|
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
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;
|
2015-08-02 11:47:26 +00:00
|
|
|
|
2015-08-08 11:24:49 +00:00
|
|
|
["spectatorSet",[_set]] call EFUNC(common,localEvent);
|