Add spectator text chat

Turns out custom radio channels are kind of a pain to work with. However this should work fine assuming the radioChannelAdd commands will work on client machines.
This commit is contained in:
SilentSpike 2015-11-22 20:03:10 +00:00
parent f07f06c843
commit d2538c6ff2
4 changed files with 28 additions and 8 deletions

View File

@ -9,5 +9,11 @@
GVAR(availableVisions) = [[-2,-1,0,1], [-2,-1], [-2,0,1], [-2]] select GVAR(restrictVisions);
}] call EFUNC(common,addEventHandler);
// Create a radio channel for any spectators to text chat in
if (isServer) then {
GVAR(channel) = radioChannelCreate [[0.729,0.149,0.098,1],"Spectator","Spectator (%UNIT_NAME)",[]];
publicVariable QGVAR(channel);
};
// Should prevent unending spectator on mission end
addMissionEventHandler ["Ended",{ [false] call FUNC(setSpectator) }];

View File

@ -172,9 +172,12 @@ switch (toLower _mode) do {
[QGVAR(zeus)] call FUNC(interrupt);
["zeus"] call FUNC(handleInterface);
};
if ((isServer || {serverCommandAvailable "#kick"}) && {_dik in (actionKeys "Chat" + actionKeys "PrevChannel" + actionKeys "NextChannel")}) exitWith {
if (_dik in (actionKeys "Chat")) exitWith {
false
};
if (_dik in (actionKeys "PrevChannel" + actionKeys "NextChannel")) exitWith {
!(isServer || serverCommandAvailable "#kick")
};
// Handle held keys (prevent repeat calling)
if (GVAR(heldKeys) param [_dik,false]) exitwith {};

View File

@ -63,9 +63,17 @@ if (_set) then {
GVAR(unitCamera) camCommit 0;
[] call FUNC(transitionCamera);
// Close map and clear radio
// 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
openMap [false,false];
clearRadio;
enableRadio false;
// Disable BI damage effects
BIS_fnc_feedback_allowPP = false;
@ -111,7 +119,16 @@ if (_set) then {
camDestroy GVAR(unitCamera);
camDestroy GVAR(targetCamera);
// 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
clearRadio;
enableRadio true;
// Return to player view
player switchCamera "internal";

View File

@ -61,7 +61,6 @@ if (_newMode == 0) then { // Free
};
GVAR(camAgent) switchCamera "internal";
clearRadio;
} else {
_camera = GVAR(unitCamera);
@ -87,11 +86,6 @@ if (_newMode == 0) then { // Free
_camera cameraEffect ["internal", "back"];
};
// Clear radio if group changed
if (group _newUnit != group GVAR(camUnit)) then {
clearRadio;
};
GVAR(camUnit) = _newUnit;
};