2022-02-08 13:03:55 -05:00
|
|
|
#include common_scripts\utility;
|
|
|
|
#include maps\mp\_utility;
|
|
|
|
#include maps\mp\gametypes\_hud_util;
|
|
|
|
#include maps\mp\gametypes\_playerlogic;
|
|
|
|
|
|
|
|
init()
|
|
|
|
{
|
|
|
|
// setup default vars
|
2022-02-09 15:45:28 -05:00
|
|
|
level.eventBus = spawnstruct();
|
|
|
|
level.eventBus.inVar = "sv_iw4madmin_in";
|
|
|
|
level.eventBus.outVar = "sv_iw4madmin_out";
|
|
|
|
level.eventBus.failKey = "fail";
|
|
|
|
level.eventBus.timeoutKey = "timeout";
|
2022-02-10 17:50:45 -05:00
|
|
|
level.eventBus.timeout = 30;
|
2022-02-08 13:03:55 -05:00
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
level.clientDataKey = "clientData";
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
level.eventTypes = spawnstruct();
|
2022-02-10 17:50:45 -05:00
|
|
|
level.eventTypes.localClientEvent = "client_event";
|
2022-02-08 13:03:55 -05:00
|
|
|
level.eventTypes.clientDataReceived = "ClientDataReceived";
|
|
|
|
level.eventTypes.clientDataRequested = "ClientDataRequested";
|
2022-02-10 17:50:45 -05:00
|
|
|
level.eventTypes.setClientDataRequested = "SetClientDataRequested";
|
|
|
|
level.eventTypes.setClientDataCompleted = "SetClientDataCompleted";
|
2022-02-08 13:03:55 -05:00
|
|
|
level.eventTypes.executeCommandRequested = "ExecuteCommandRequested";
|
|
|
|
|
|
|
|
SetDvarIfUninitialized( level.eventBus.inVar, "" );
|
|
|
|
SetDvarIfUninitialized( level.eventBus.outVar, "" );
|
|
|
|
SetDvarIfUninitialized( "sv_iw4madmin_integration_enabled", 1 );
|
2022-02-09 15:45:28 -05:00
|
|
|
SetDvarIfUninitialized( "sv_iw4madmin_integration_debug", 0 );
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
// map the event type to the handler
|
|
|
|
level.eventCallbacks = [];
|
2022-02-10 17:50:45 -05:00
|
|
|
level.eventCallbacks[level.eventTypes.clientDataReceived] = ::OnClientDataReceived;
|
|
|
|
level.eventCallbacks[level.eventTypes.executeCommandRequested] = ::OnExecuteCommand;
|
|
|
|
level.eventCallbacks[level.eventTypes.setClientDataCompleted] = ::OnSetClientDataCompleted;
|
2022-02-12 22:54:21 -05:00
|
|
|
|
|
|
|
if ( GetDvarInt( "sv_iw4madmin_integration_enabled" ) != 1 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
// start long running tasks
|
2022-02-10 17:50:45 -05:00
|
|
|
level thread MonitorClientEvents();
|
2022-02-08 13:03:55 -05:00
|
|
|
level thread MonitorBus();
|
|
|
|
level thread OnPlayerConnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Client Methods
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
OnPlayerConnect()
|
|
|
|
{
|
|
|
|
level endon ( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
level waittill( "connected", player );
|
2022-02-09 15:45:28 -05:00
|
|
|
|
|
|
|
level.iw4adminIntegrationDebug = GetDvarInt( "sv_iw4madmin_integration_debug" );
|
|
|
|
|
|
|
|
if ( !isDefined( player.pers[level.clientDataKey] ) )
|
|
|
|
{
|
|
|
|
player.pers[level.clientDataKey] = spawnstruct();
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
player thread OnPlayerSpawned();
|
2022-02-10 17:50:45 -05:00
|
|
|
player thread PlayerTrackingOnInterval();
|
2022-02-25 09:22:40 -05:00
|
|
|
|
|
|
|
// only toggle if it's enabled
|
|
|
|
if ( IsDefined( level.nightModeEnabled ) && level.nightModeEnabled )
|
|
|
|
{
|
|
|
|
player ToggleNightMode();
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPlayerSpawned()
|
|
|
|
{
|
|
|
|
self endon( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
self waittill( "spawned_player" );
|
|
|
|
self PlayerConnectEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
OnPlayerDisconnect()
|
|
|
|
{
|
|
|
|
level endon ( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
self waittill( "disconnect" );
|
|
|
|
self SaveTrackingMetrics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OnGameEnded()
|
|
|
|
{
|
|
|
|
level endon ( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
level waittill( "game_ended" );
|
|
|
|
// note: you can run data code here but it's possible for
|
2022-02-15 21:05:50 -05:00
|
|
|
// data to get truncated, so we will try a timer based approach for now
|
2022-02-10 17:50:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
DisplayWelcomeData()
|
|
|
|
{
|
|
|
|
self endon( "disconnect" );
|
|
|
|
|
|
|
|
clientData = self.pers[level.clientDataKey];
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
if ( clientData.permissionLevel == "User" || clientData.permissionLevel == "Flagged" )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self IPrintLnBold( "Welcome, your level is ^5" + clientData.permissionLevel );
|
|
|
|
wait( 2.0 );
|
2022-02-08 13:03:55 -05:00
|
|
|
self IPrintLnBold( "You were last seen ^5" + clientData.lastConnection );
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerConnectEvents()
|
|
|
|
{
|
|
|
|
self endon( "disconnect" );
|
2022-03-05 14:13:00 -05:00
|
|
|
|
|
|
|
if ( IsDefined( self.isHidden ) && self.isHidden )
|
|
|
|
{
|
|
|
|
self HideImpl();
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
clientData = self.pers[level.clientDataKey];
|
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
// this gives IW4MAdmin some time to register the player before making the request;
|
2022-02-10 17:50:45 -05:00
|
|
|
// although probably not necessary some users might have a slow database or poll rate
|
2022-02-09 15:45:28 -05:00
|
|
|
wait ( 2 );
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
if ( isDefined( clientData.state ) && clientData.state == "complete" )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-02-09 15:45:28 -05:00
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
self RequestClientBasicData();
|
|
|
|
// example of requesting meta from IW4MAdmin
|
|
|
|
// self RequestClientMeta( "LastServerPlayed" );
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
PlayerTrackingOnInterval()
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
self endon( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
wait ( 120 );
|
|
|
|
if ( IsAlive( self ) )
|
|
|
|
{
|
|
|
|
self SaveTrackingMetrics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorClientEvents()
|
|
|
|
{
|
|
|
|
level endon( "disconnect" );
|
2022-02-08 13:03:55 -05:00
|
|
|
self endon( "disconnect" );
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
level waittill( level.eventTypes.localClientEvent, client );
|
2022-02-08 13:03:55 -05:00
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
|
|
|
self IPrintLn( "Processing Event " + client.event.type + "-" + client.event.subtype );
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
eventHandler = level.eventCallbacks[client.event.type];
|
|
|
|
|
|
|
|
if ( isDefined( eventHandler ) )
|
|
|
|
{
|
|
|
|
client [[eventHandler]]( client.event );
|
|
|
|
}
|
|
|
|
|
|
|
|
client.eventData = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Helper Methods
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
RequestClientMeta( metaKey )
|
|
|
|
{
|
|
|
|
getClientMetaEvent = BuildEventRequest( true, level.eventTypes.clientDataRequested, "Meta", self, metaKey );
|
2022-02-10 17:50:45 -05:00
|
|
|
level thread QueueEvent( getClientMetaEvent, level.eventTypes.clientDataRequested, self );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RequestClientBasicData()
|
|
|
|
{
|
|
|
|
getClientDataEvent = BuildEventRequest( true, level.eventTypes.clientDataRequested, "None", self, "" );
|
2022-02-10 17:50:45 -05:00
|
|
|
level thread QueueEvent( getClientDataEvent, level.eventTypes.clientDataRequested, self );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
IncrementClientMeta( metaKey, incrementValue, clientId )
|
|
|
|
{
|
|
|
|
SetClientMeta( metaKey, incrementValue, clientId, "increment" );
|
|
|
|
}
|
|
|
|
|
|
|
|
DecrementClientMeta( metaKey, decrementValue, clientId )
|
|
|
|
{
|
|
|
|
SetClientMeta( metaKey, decrementValue, clientId, "decrement" );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetClientMeta( metaKey, metaValue, clientId, direction )
|
|
|
|
{
|
|
|
|
data = "key=" + metaKey + "|value=" + metaValue;
|
|
|
|
clientNumber = -1;
|
|
|
|
|
|
|
|
if ( IsDefined ( clientId ) )
|
|
|
|
{
|
|
|
|
data = data + "|clientId=" + clientId;
|
|
|
|
clientNumber = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsDefined( direction ) )
|
|
|
|
{
|
|
|
|
data = data + "|direction=" + direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsPlayer( self ) )
|
|
|
|
{
|
|
|
|
clientNumber = self getEntityNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
setClientMetaEvent = BuildEventRequest( true, level.eventTypes.setClientDataRequested, "Meta", clientNumber, data );
|
|
|
|
level thread QueueEvent( setClientMetaEvent, level.eventTypes.setClientDataRequested, self );
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveTrackingMetrics()
|
|
|
|
{
|
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
IPrintLn( "Saving tracking metrics for " + self.persistentClientId );
|
2022-02-10 17:50:45 -05:00
|
|
|
}
|
2022-02-22 18:10:33 -05:00
|
|
|
|
|
|
|
if ( !IsDefined( self.lastShotCount ) )
|
|
|
|
{
|
|
|
|
self.lastShotCount = 0;
|
|
|
|
}
|
2022-02-10 17:50:45 -05:00
|
|
|
|
|
|
|
currentShotCount = self getPlayerStat( "mostshotsfired" );
|
|
|
|
change = currentShotCount - self.lastShotCount;
|
2022-02-12 22:54:21 -05:00
|
|
|
self.lastShotCount = currentShotCount;
|
2022-02-10 17:50:45 -05:00
|
|
|
|
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
IPrintLn( "Total Shots Fired increased by " + change );
|
2022-02-10 17:50:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !IsDefined( change ) )
|
|
|
|
{
|
|
|
|
change = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( change == 0 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IncrementClientMeta( "TotalShotsFired", change, self.persistentClientId );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildEventRequest( responseExpected, eventType, eventSubtype, entOrId, data )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
|
|
|
if ( !isDefined( data ) )
|
|
|
|
{
|
|
|
|
data = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !isDefined( eventSubtype ) )
|
|
|
|
{
|
|
|
|
eventSubtype = "None";
|
|
|
|
}
|
2022-02-10 17:50:45 -05:00
|
|
|
|
|
|
|
if ( IsPlayer( entOrId ) )
|
|
|
|
{
|
|
|
|
entOrId = entOrId getEntityNumber();
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
request = "0";
|
|
|
|
|
|
|
|
if ( responseExpected )
|
|
|
|
{
|
|
|
|
request = "1";
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
request = request + ";" + eventType + ";" + eventSubtype + ";" + entOrId + ";" + data;
|
2022-02-08 13:03:55 -05:00
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorBus()
|
|
|
|
{
|
|
|
|
level endon( "game_ended" );
|
|
|
|
|
|
|
|
for( ;; )
|
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
wait ( 0.1 );
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
// check to see if IW4MAdmin is ready to receive more data
|
|
|
|
if ( getDvar( level.eventBus.inVar ) == "" )
|
|
|
|
{
|
|
|
|
level notify( "bus_ready" );
|
|
|
|
}
|
|
|
|
|
|
|
|
eventString = getDvar( level.eventBus.outVar );
|
|
|
|
|
|
|
|
if ( eventString == "" )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
|
|
|
IPrintLn( "-> " + eventString );
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
NotifyClientEvent( strtok( eventString, ";" ) );
|
|
|
|
|
|
|
|
SetDvar( level.eventBus.outVar, "" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
QueueEvent( request, eventType, notifyEntity )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
level endon( "disconnect" );
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
start = GetTime();
|
2022-02-10 17:50:45 -05:00
|
|
|
maxWait = level.eventBus.timeout * 1000; // 30 seconds
|
2022-02-08 13:03:55 -05:00
|
|
|
timedOut = "";
|
|
|
|
|
|
|
|
while ( GetDvar( level.eventBus.inVar ) != "" && ( GetTime() - start ) < maxWait )
|
|
|
|
{
|
2022-02-09 15:45:28 -05:00
|
|
|
level waittill_notify_or_timeout( "bus_ready", 1 );
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
if ( GetDvar( level.eventBus.inVar ) != "" )
|
|
|
|
{
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
IPrintLn( "A request is already in progress..." );
|
2022-02-09 15:45:28 -05:00
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
timedOut = "set";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
timedOut = "unset";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( timedOut == "set")
|
|
|
|
{
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
IPrintLn( "Timed out waiting for response..." );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-09 15:45:28 -05:00
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
if ( IsDefined( notifyEntity) )
|
|
|
|
{
|
|
|
|
notifyEntity NotifyClientEventTimeout( eventType );
|
|
|
|
}
|
2022-02-09 15:45:28 -05:00
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
return;
|
|
|
|
}
|
2022-02-09 15:45:28 -05:00
|
|
|
|
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
|
|
|
IPrintLn("<- " + request);
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
SetDvar( level.eventBus.inVar, request );
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseDataString( data )
|
|
|
|
{
|
|
|
|
dataParts = strtok( data, "|" );
|
|
|
|
dict = [];
|
|
|
|
|
|
|
|
counter = 0;
|
|
|
|
foreach ( part in dataParts )
|
|
|
|
{
|
|
|
|
splitPart = strtok( part, "=" );
|
|
|
|
key = splitPart[0];
|
|
|
|
value = splitPart[1];
|
|
|
|
dict[key] = value;
|
|
|
|
dict[counter] = key;
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
NotifyClientEventTimeout( eventType )
|
|
|
|
{
|
|
|
|
// todo: make this actual eventing
|
|
|
|
if ( eventType == level.eventTypes.clientDataRequested )
|
|
|
|
{
|
|
|
|
self.pers["clientData"].state = level.eventBus.timeoutKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
NotifyClientEvent( eventInfo )
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
origin = getPlayerFromClientNum( int( eventInfo[3] ) );
|
|
|
|
target = getPlayerFromClientNum( int( eventInfo[4] ) );
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
event = spawnstruct();
|
|
|
|
event.type = eventInfo[1];
|
|
|
|
event.subtype = eventInfo[2];
|
2022-02-15 21:05:50 -05:00
|
|
|
event.data = eventInfo[5];
|
|
|
|
event.origin = origin;
|
|
|
|
event.target = target;
|
2022-02-08 13:03:55 -05:00
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
IPrintLn( "NotifyClientEvent->" + event.data );
|
2022-02-09 15:45:28 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
client = event.origin;
|
2022-02-08 13:03:55 -05:00
|
|
|
client.event = event;
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
level notify( level.eventTypes.localClientEvent, client );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Event Handlers
|
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
OnClientDataReceived( event )
|
|
|
|
{
|
|
|
|
event.data = ParseDataString( event.data );
|
|
|
|
clientData = self.pers[level.clientDataKey];
|
|
|
|
|
2022-02-09 15:45:28 -05:00
|
|
|
if ( event.subtype == "Fail" )
|
|
|
|
{
|
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
|
|
|
IPrintLn( "Received fail response" );
|
|
|
|
}
|
|
|
|
clientData.state = level.eventBus.failKey;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
if ( event.subtype == "Meta" )
|
|
|
|
{
|
2022-02-10 17:50:45 -05:00
|
|
|
if ( !isDefined( clientData.meta ) )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
|
|
|
clientData.meta = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
metaKey = event.data[0];
|
2022-02-10 17:50:45 -05:00
|
|
|
clientData.meta[metaKey] = event.data[metaKey];
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clientData.permissionLevel = event.data["level"];
|
2022-02-10 17:50:45 -05:00
|
|
|
clientData.clientId = event.data["clientId"];
|
2022-02-08 13:03:55 -05:00
|
|
|
clientData.lastConnection = event.data["lastConnection"];
|
|
|
|
clientData.state = "complete";
|
2022-02-10 17:50:45 -05:00
|
|
|
self.persistentClientId = event.data["clientId"];
|
2022-02-08 13:03:55 -05:00
|
|
|
|
|
|
|
self thread DisplayWelcomeData();
|
|
|
|
}
|
|
|
|
|
|
|
|
OnExecuteCommand( event )
|
|
|
|
{
|
|
|
|
data = ParseDataString( event.data );
|
2022-02-15 21:05:50 -05:00
|
|
|
response = "";
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
switch ( event.subtype )
|
|
|
|
{
|
|
|
|
case "GiveWeapon":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = event.target GiveWeaponImpl( data );
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
|
|
|
case "TakeWeapons":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = event.target TakeWeaponsImpl();
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
|
|
|
case "SwitchTeams":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = event.target TeamSwitchImpl();
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
|
|
|
case "Hide":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = self HideImpl();
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
|
|
|
case "Unhide":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = self UnhideImpl();
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
|
|
|
case "Alert":
|
2022-02-15 21:05:50 -05:00
|
|
|
response = event.target AlertImpl( data );
|
|
|
|
break;
|
|
|
|
case "Goto":
|
|
|
|
if ( IsDefined( event.target ) )
|
|
|
|
{
|
|
|
|
response = self GotoPlayerImpl( event.target );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-01 13:45:39 -05:00
|
|
|
response = self GotoImpl( data );
|
2022-02-15 21:05:50 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Kill":
|
|
|
|
response = event.target KillImpl();
|
|
|
|
break;
|
|
|
|
case "NightMode":
|
|
|
|
NightModeImpl();
|
2022-02-08 13:03:55 -05:00
|
|
|
break;
|
2022-03-01 13:45:39 -05:00
|
|
|
case "SetSpectator":
|
|
|
|
response = event.target SetSpectatorImpl();
|
|
|
|
break;
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
// send back the response to the origin, but only if they're not the target
|
|
|
|
if ( response != "" && IsPlayer( event.origin ) && event.origin != event.target )
|
|
|
|
{
|
|
|
|
event.origin IPrintLnBold( response );
|
|
|
|
}
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
2022-02-10 17:50:45 -05:00
|
|
|
OnSetClientDataCompleted( event )
|
|
|
|
{
|
|
|
|
// IW4MAdmin let us know it persisted (success or fail)
|
|
|
|
if ( level.iw4adminIntegrationDebug == 1 )
|
|
|
|
{
|
|
|
|
IPrintLn( "Set Client Data -> subtype = " + event.subType + " status = " + event.data["status"] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 13:03:55 -05:00
|
|
|
//////////////////////////////////
|
|
|
|
// Command Implementations
|
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
GiveWeaponImpl( data )
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
if ( !IsAlive( self ) )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
return self.name + "^7 is not alive";
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
self IPrintLnBold( "You have been given a new weapon" );
|
|
|
|
self GiveWeapon( data["weaponName"] );
|
|
|
|
self SwitchToWeapon( data["weaponName"] );
|
|
|
|
|
|
|
|
return self.name + "^7 has been given ^5" + data["weaponName"];
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TakeWeaponsImpl()
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
if ( !IsAlive( self ) )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
return self.name + "^7 is not alive";
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
self TakeAllWeapons();
|
|
|
|
self IPrintLnBold( "All your weapons have been taken" );
|
|
|
|
|
|
|
|
return "Took weapons from " + self.name;
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TeamSwitchImpl()
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
if ( !IsAlive( self ) )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
return self.name + "^7 is not alive";
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
team = level.allies;
|
|
|
|
|
|
|
|
if ( self.team == "allies" )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
team = level.axis;
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
self IPrintLnBold( "You are being team switched" );
|
|
|
|
wait( 2 );
|
|
|
|
self [[team]]();
|
|
|
|
|
|
|
|
return self.name + "^7 switched to " + self.team;
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
HideImpl()
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
if ( !IsAlive( self ) )
|
|
|
|
{
|
|
|
|
self IPrintLnBold( "You are not alive" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self SetClientDvar( "sv_cheats", 1 );
|
2022-02-25 09:22:40 -05:00
|
|
|
self SetClientDvar( "cg_thirdperson", 1 );
|
|
|
|
self SetClientDvar( "sv_cheats", 0 );
|
2022-02-15 21:05:50 -05:00
|
|
|
|
2022-03-05 14:13:00 -05:00
|
|
|
if ( !IsDefined( self.savedHealth ) || self.health < 1000 )
|
|
|
|
{
|
|
|
|
self.savedHealth = self.health;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.maxhealth = 99999;
|
|
|
|
self.health = 99999;
|
2022-02-15 21:05:50 -05:00
|
|
|
self.isHidden = true;
|
|
|
|
|
|
|
|
self Hide();
|
|
|
|
|
|
|
|
self IPrintLnBold( "You are now ^5hidden ^7from other players" );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
UnhideImpl()
|
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
if ( !IsAlive( self ) )
|
2022-02-08 13:03:55 -05:00
|
|
|
{
|
2022-02-15 21:05:50 -05:00
|
|
|
self IPrintLnBold( "You are not alive" );
|
|
|
|
return;
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-02-15 21:05:50 -05:00
|
|
|
|
2022-02-25 09:22:40 -05:00
|
|
|
self SetClientDvar( "sv_cheats", 1 );
|
|
|
|
self SetClientDvar( "cg_thirdperson", 0 );
|
|
|
|
self SetClientDvar( "sv_cheats", 0 );
|
2022-02-15 21:05:50 -05:00
|
|
|
|
|
|
|
self.health = self.savedHealth;
|
|
|
|
self.isHidden = false;
|
|
|
|
|
|
|
|
self Show();
|
|
|
|
self IPrintLnBold( "You are now ^5visible ^7to other players" );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AlertImpl( data )
|
|
|
|
{
|
|
|
|
self thread maps\mp\gametypes\_hud_message::oldNotifyMessage( data["alertType"], data["message"], "compass_waypoint_target", ( 1, 0, 0 ), "ui_mp_nukebomb_timer", 7.5 );
|
2022-02-15 21:05:50 -05:00
|
|
|
return "Sent alert to " + self.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
GotoImpl( data )
|
|
|
|
{
|
|
|
|
if ( !IsAlive( self ) )
|
|
|
|
{
|
|
|
|
self IPrintLnBold( "You are not alive" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = ( int(data["x"]), int(data["y"]), int(data["z"]) );
|
|
|
|
self SetOrigin( position );
|
|
|
|
self IPrintLnBold( "Moved to " + "("+ position[0] + "," + position[1] + "," + position[2] + ")" );
|
|
|
|
}
|
|
|
|
|
|
|
|
GotoPlayerImpl( target )
|
|
|
|
{
|
|
|
|
if ( !IsAlive( target ) )
|
|
|
|
{
|
|
|
|
self IPrintLnBold( target.name + " is not alive" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self SetOrigin( target GetOrigin() );
|
|
|
|
self IPrintLnBold( "Moved to " + target.name );
|
|
|
|
}
|
|
|
|
|
|
|
|
KillImpl()
|
|
|
|
{
|
|
|
|
if ( !IsAlive( self ) )
|
|
|
|
{
|
|
|
|
return self.name + " is not alive";
|
|
|
|
}
|
|
|
|
|
|
|
|
self Suicide();
|
|
|
|
self IPrintLnBold( "You were killed by " + self.name );
|
|
|
|
|
|
|
|
return "You killed " + self.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
NightModeImpl()
|
|
|
|
{
|
|
|
|
if ( !IsDefined ( level.nightModeEnabled ) )
|
|
|
|
{
|
|
|
|
level.nightModeEnabled = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.nightModeEnabled = !level.nightModeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = "^5NightMode ^7is disabled";
|
|
|
|
|
|
|
|
if ( level.nightModeEnabled )
|
|
|
|
{
|
|
|
|
message = "^5NightMode ^7is enabled";
|
|
|
|
}
|
|
|
|
|
|
|
|
IPrintLnBold( message );
|
|
|
|
|
|
|
|
foreach( player in level.players )
|
|
|
|
{
|
2022-02-18 11:15:11 -05:00
|
|
|
player ToggleNightMode();
|
2022-02-15 21:05:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ToggleNightMode()
|
|
|
|
{
|
|
|
|
colorMap = 1;
|
|
|
|
fxDraw = 1;
|
|
|
|
|
|
|
|
if ( IsDefined( level.nightModeEnabled ) && level.nightModeEnabled )
|
|
|
|
{
|
|
|
|
colorMap = 0;
|
|
|
|
fxDraw = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
self SetClientDvar( "sv_cheats", 1 );
|
|
|
|
self SetClientDvar( "r_colorMap", colorMap );
|
|
|
|
self SetClientDvar( "fx_draw", fxDraw );
|
|
|
|
self SetClientDvar( "sv_cheats", 0 );
|
2022-02-08 13:03:55 -05:00
|
|
|
}
|
2022-03-01 13:45:39 -05:00
|
|
|
|
|
|
|
SetSpectatorImpl()
|
|
|
|
{
|
|
|
|
if ( self.pers["team"] == "spectator" )
|
|
|
|
{
|
|
|
|
return self.name + " is already spectating";
|
|
|
|
}
|
|
|
|
|
|
|
|
self [[level.spectator]]();
|
|
|
|
self IPrintLnBold( "You have been moved to spectator" );
|
|
|
|
|
|
|
|
return self.name + " has been moved to spectator";
|
|
|
|
}
|