2019-12-11 21:29:01 +00:00
|
|
|
// AFK Timeout Script
|
|
|
|
|
// Script BY: DarkTiger
|
|
|
|
|
// Worked on: ChocoTaco
|
|
|
|
|
// If player is afk specific amount of time in minutes, force them into observer
|
2022-05-15 19:43:12 +00:00
|
|
|
deleteVariables("$dtVar::AFKList*");
|
|
|
|
|
$AFKCount = 0;
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
// Enable/Disable entire script
|
|
|
|
|
$dtVar::AFKTimeout = 1;
|
|
|
|
|
// 60000 * 2 is 2 minutes
|
|
|
|
|
// 0 minutes disables
|
2022-05-15 19:43:12 +00:00
|
|
|
$dtVar::AFKtime = 60000 * 1;
|
2019-12-11 21:29:01 +00:00
|
|
|
// Run from List Only instead of All clients on the server. 1 is yes, 0 is no
|
|
|
|
|
$dtVar::ListOnly = 1;
|
2020-11-03 21:48:44 +00:00
|
|
|
// Add clients who are normally AFK
|
2019-12-11 21:29:01 +00:00
|
|
|
$dtVar::AFKList[$AFKCount++] = "";
|
|
|
|
|
$dtVar::AFKList[$AFKCount++] = "";
|
2022-05-15 19:43:12 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
// Loop Check Timer
|
|
|
|
|
// How often do you want a AFKLoop. 1000 * 30 is 30 seconds
|
2022-05-15 19:43:12 +00:00
|
|
|
$dtVar::AFKloop = 1000 * 15;
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
// Set Status Var
|
2022-05-15 19:43:12 +00:00
|
|
|
if($dtVar::ListOnly || !$dtVar::AFKtime)
|
2019-12-11 21:29:01 +00:00
|
|
|
$DT_AFKStatus = "IDLE";
|
|
|
|
|
else
|
|
|
|
|
$DT_AFKStatus = "ACTIVE";
|
|
|
|
|
|
|
|
|
|
package DT_AFKPackage
|
2019-06-04 04:43:15 +00:00
|
|
|
{
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
function CreateServer( %mission, %missionType )
|
2019-06-04 04:43:15 +00:00
|
|
|
{
|
2019-12-11 21:29:01 +00:00
|
|
|
parent::CreateServer( %mission, %missionType );
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
//Call to start AFKTimeout update
|
|
|
|
|
DT_AFKtimeoutLoop();
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
// Prevent package from being activated if it is already
|
|
|
|
|
if(!isActivePackage(DT_AFKOverrides) && $dtVar::ListOnly)
|
|
|
|
|
activatePackage(DT_AFKOverrides);
|
2019-06-04 04:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Prevent package from being activated if it is already
|
2019-12-11 21:29:01 +00:00
|
|
|
if(!isActivePackage(DT_AFKPackage) && $dtVar::AFKTimeout)
|
|
|
|
|
activatePackage(DT_AFKPackage);
|
|
|
|
|
|
|
|
|
|
package DT_AFKOverrides
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function GameConnection::onConnect(%client, %name, %raceGender, %skin, %voice, %voicePitch)
|
|
|
|
|
{
|
|
|
|
|
Parent::onConnect(%client, %name, %raceGender, %skin, %voice, %voicePitch);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
DT_AFKStatusConnect(%client);
|
|
|
|
|
}
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
function GameConnection::onDrop(%client, %reason)
|
|
|
|
|
{
|
|
|
|
|
Parent::onDrop(%client, %reason);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
DT_AFKStatusDrop(%client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
function DT_AFKStatusConnect(%client)
|
|
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
if(!$dtVar::AFKtime || $Host::TournamentMode)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(%x = 1; %x <= $AFKCount; %x++)
|
2019-12-11 21:29:01 +00:00
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
%guid = $dtVar::AFKList[%x];
|
|
|
|
|
if(%client.guid $= %guid && %guid !$= "")
|
2019-12-11 21:29:01 +00:00
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
$DT_AFKStatus = "ACTIVE";
|
|
|
|
|
$DT_AFKListCount++;
|
|
|
|
|
%client.dtAFK = 1;
|
2019-12-11 21:29:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
function DT_AFKStatusDrop(%client)
|
2019-06-04 04:43:15 +00:00
|
|
|
{
|
2020-11-03 21:48:44 +00:00
|
|
|
if(%client.dtAFK)
|
2022-05-15 19:43:12 +00:00
|
|
|
$DT_AFKListCount--;
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2022-05-15 19:43:12 +00:00
|
|
|
//Reset
|
|
|
|
|
if($DT_AFKListCount $= 0)
|
2019-12-11 21:29:01 +00:00
|
|
|
$DT_AFKStatus = "IDLE";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function DT_AFKtimeoutLoop()
|
2020-11-03 21:48:44 +00:00
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
if(isEventPending($dtVar::AFKloopSchedule))
|
|
|
|
|
cancel($dtVar::AFKloopSchedule);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2022-05-15 19:43:12 +00:00
|
|
|
//echo($DT_AFKStatus);
|
|
|
|
|
if($DT_AFKStatus $= "ACTIVE" && !$Host::TournamentMode)
|
2019-12-11 21:29:01 +00:00
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
if($dtVar::ListOnly)
|
|
|
|
|
{
|
|
|
|
|
for(%i = 0; %i < ClientGroup.getCount(); %i ++)
|
|
|
|
|
{
|
|
|
|
|
%client = ClientGroup.getObject(%i);
|
|
|
|
|
if(%client.dtAFK)
|
|
|
|
|
{
|
|
|
|
|
if(!%client.isAIControlled() && isObject(%client.player) && %client.player.getState() !$= "Dead")
|
|
|
|
|
CheckAFK(%client);
|
|
|
|
|
}
|
2020-11-03 21:48:44 +00:00
|
|
|
}
|
2022-05-15 19:43:12 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(%i = 0; %i < ClientGroup.getCount(); %i ++)
|
|
|
|
|
{
|
|
|
|
|
%client = ClientGroup.getObject(%i);
|
|
|
|
|
if(!%client.isAIControlled() && isObject(%client.player) && %client.player.getState() !$= "Dead")
|
|
|
|
|
CheckAFK(%client);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-11 21:29:01 +00:00
|
|
|
}
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2022-05-15 19:43:12 +00:00
|
|
|
//Have another go?
|
2020-11-03 21:48:44 +00:00
|
|
|
$dtVar::AFKloopSchedule = schedule($dtVar::AFKloop, 0, "DT_AFKtimeoutLoop");
|
2019-06-04 04:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-15 19:43:12 +00:00
|
|
|
function CheckAFK(%client)
|
2019-06-04 04:43:15 +00:00
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
//checks to see if there position and rotation are the same.
|
|
|
|
|
if(%client.player.curTransform $= %client.player.getTransform())
|
|
|
|
|
{
|
|
|
|
|
%client.player.afkTimer += $dtVar::AFKloop;
|
|
|
|
|
if(%client.player.afkTimer >= $dtVar::AFKtime)
|
|
|
|
|
{
|
|
|
|
|
Game.AFKForceObserver(%client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
%client.player.afkTimer = 0; //reset if moving
|
2019-06-04 04:43:15 +00:00
|
|
|
|
2022-05-15 19:43:12 +00:00
|
|
|
//save current transform
|
|
|
|
|
%client.player.curTransform = %client.player.getTransform();
|
|
|
|
|
}
|
2019-12-11 21:29:01 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
function DefaultGame::AFKForceObserver(%game, %client)
|
|
|
|
|
{
|
2022-05-15 19:43:12 +00:00
|
|
|
if($Host::TournamentMode)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
//make sure we have a valid client...
|
|
|
|
|
if (%client <= 0)
|
|
|
|
|
return;
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// first kill this player
|
|
|
|
|
if(%client.player)
|
|
|
|
|
%client.player.scriptKill(0);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
if( %client.respawnTimer )
|
|
|
|
|
cancel(%client.respawnTimer);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
%client.respawnTimer = "";
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// remove them from the team rank array
|
|
|
|
|
%game.removeFromTeamRankArray(%client);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// place them in observer mode
|
|
|
|
|
%client.lastObserverSpawn = -1;
|
|
|
|
|
%client.observerStartTime = getSimTime();
|
|
|
|
|
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
%client.camera.getDataBlock().setMode( %client.camera, "observerFly" );
|
2019-12-11 21:29:01 +00:00
|
|
|
messageClient(%client, 'MsgClientJoinTeam', '\c2You have been placed into observer mode due to inactivity.', %client.name, game.getTeamName(0), %client, 0 );
|
2019-06-05 23:59:07 +00:00
|
|
|
logEcho(%client.nameBase@" (cl "@%client@") was forced into observer mode due to inactivity");
|
2019-06-04 04:43:15 +00:00
|
|
|
%client.lastTeam = %client.team;
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// switch client to team 0 (observer)
|
|
|
|
|
%client.team = 0;
|
|
|
|
|
%client.player.team = 0;
|
|
|
|
|
setTargetSensorGroup( %client.target, %client.team );
|
|
|
|
|
%client.setSensorGroup( %client.team );
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// set their control to the obs. cam
|
|
|
|
|
%client.setControlObject( %client.camera );
|
|
|
|
|
commandToClient(%client, 'setHudMode', 'Observer');
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// display the hud
|
|
|
|
|
//displayObserverHud(%client, 0);
|
|
|
|
|
updateObserverFlyHud(%client);
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-12-11 21:29:01 +00:00
|
|
|
messageAllExcept(%client, -1, 'MsgClientJoinTeam', '\c2%1 has been placed into observer mode due to inactivity.', %client.name, game.getTeamName(0), %client, 0 );
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
updateCanListenState( %client );
|
2020-11-03 21:48:44 +00:00
|
|
|
|
2019-06-04 04:43:15 +00:00
|
|
|
// call the onEvent for this game type
|
|
|
|
|
%game.onClientEnterObserverMode(%client); //Bounty uses this to remove this client from others' hit lists
|
2022-05-15 19:43:12 +00:00
|
|
|
}
|