This commit is contained in:
ChocoTaco1 2022-05-15 15:43:12 -04:00
parent 5f2444fdc2
commit cf74f47e1a

View file

@ -2,31 +2,30 @@
// Script BY: DarkTiger // Script BY: DarkTiger
// Worked on: ChocoTaco // Worked on: ChocoTaco
// If player is afk specific amount of time in minutes, force them into observer // If player is afk specific amount of time in minutes, force them into observer
deleteVariables("$dtVar::AFKList*");
$AFKCount = 0;
// Enable/Disable entire script // Enable/Disable entire script
$dtVar::AFKTimeout = 1; $dtVar::AFKTimeout = 1;
// 60000 * 2 is 2 minutes // 60000 * 2 is 2 minutes
// 0 minutes disables // 0 minutes disables
$dtVar::AFKtime = 60000 * 2; $dtVar::AFKtime = 60000 * 1;
// Run from List Only instead of All clients on the server. 1 is yes, 0 is no // Run from List Only instead of All clients on the server. 1 is yes, 0 is no
$dtVar::ListOnly = 1; $dtVar::ListOnly = 1;
// Add clients who are normally AFK // Add clients who are normally AFK
$dtVar::AFKList[$AFKCount++] = ""; $dtVar::AFKList[$AFKCount++] = "";
$dtVar::AFKList[$AFKCount++] = ""; $dtVar::AFKList[$AFKCount++] = "";
// Loop Check Timer // Loop Check Timer
// How often do you want a AFKLoop. 1000 * 30 is 30 seconds // How often do you want a AFKLoop. 1000 * 30 is 30 seconds
$dtVar::AFKloop = 1000 * 30; $dtVar::AFKloop = 1000 * 15;
////////////////////////////////////////////////////////////////////////////////
// Set Status Var // Set Status Var
if($dtVar::ListOnly) if($dtVar::ListOnly || !$dtVar::AFKtime)
$DT_AFKStatus = "IDLE"; $DT_AFKStatus = "IDLE";
else else
$DT_AFKStatus = "ACTIVE"; $DT_AFKStatus = "ACTIVE";
////////////////////////////////////////////////////////////////////////////////
package DT_AFKPackage package DT_AFKPackage
{ {
@ -67,21 +66,19 @@ function GameConnection::onDrop(%client, %reason)
}; };
////////////////////////////////////////////////////////////////////////////////
function DT_AFKStatusConnect(%client) function DT_AFKStatusConnect(%client)
{ {
if($dtVar::AFKtime != 0 && !$Host::TournamentMode) //0 minutes disables if(!$dtVar::AFKtime || $Host::TournamentMode)
return;
for(%x = 1; %x <= $AFKCount; %x++)
{ {
for(%x = 1; %x <= $AFKCount; %x++) %guid = $dtVar::AFKList[%x];
if(%client.guid $= %guid && %guid !$= "")
{ {
%guid = $dtVar::AFKList[%x]; $DT_AFKStatus = "ACTIVE";
if(%client.guid $= %guid && %guid !$= "") $DT_AFKListCount++;
{ %client.dtAFK = 1;
$DT_AFKStatus = "ACTIVE";
$DT_AFKListCount++;
%client.dtAFK = 1;
}
} }
} }
} }
@ -89,87 +86,72 @@ function DT_AFKStatusConnect(%client)
function DT_AFKStatusDrop(%client) function DT_AFKStatusDrop(%client)
{ {
if(%client.dtAFK) if(%client.dtAFK)
$DT_AFKListCount = $DT_AFKListCount - 1; $DT_AFKListCount--;
// for(%x = 1; %x <= $AFKCount; %x++) //Reset
// { if($DT_AFKListCount $= 0)
// %guid = $dtVar::AFKList[%x];
// if(%client.guid $= %guid && %guid !$= "")
// $DT_AFKListCount = $DT_AFKListCount - 1;
// }
if($DT_AFKListCount $= 0) //Wont set IDLE until all List Clients are off the server
$DT_AFKStatus = "IDLE"; $DT_AFKStatus = "IDLE";
} }
////////////////////////////////////////////////////////////////////////////////
function DT_AFKtimeoutLoop() function DT_AFKtimeoutLoop()
{ {
//echo($DT_AFKStatus);
switch$($DT_AFKStatus)
{
case ACTIVE:
if($dtVar::AFKtime != 0 && !$Host::TournamentMode) //0 minutes disables
{
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")
AFKChk(%client);
}
}
}
else
{
for(%i = 0; %i < ClientGroup.getCount(); %i ++)
{
%client = ClientGroup.getObject(%i);
if(!%client.isAIControlled() && isObject(%client.player) && %client.player.getState() !$= "Dead")
AFKChk(%client);
}
}
}
case IDLE:
//Do Nothing
}
if(isEventPending($dtVar::AFKloopSchedule)) if(isEventPending($dtVar::AFKloopSchedule))
cancel($dtVar::AFKloopSchedule); cancel($dtVar::AFKloopSchedule);
//echo($DT_AFKStatus);
if($DT_AFKStatus $= "ACTIVE" && !$Host::TournamentMode)
{
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);
}
}
}
else
{
for(%i = 0; %i < ClientGroup.getCount(); %i ++)
{
%client = ClientGroup.getObject(%i);
if(!%client.isAIControlled() && isObject(%client.player) && %client.player.getState() !$= "Dead")
CheckAFK(%client);
}
}
}
//Have another go?
$dtVar::AFKloopSchedule = schedule($dtVar::AFKloop, 0, "DT_AFKtimeoutLoop"); $dtVar::AFKloopSchedule = schedule($dtVar::AFKloop, 0, "DT_AFKtimeoutLoop");
} }
//////////////////////////////////////////////////////////////////////////////// function CheckAFK(%client)
function AFKChk(%client)
{ {
if(%client.player.curTransform $= %client.player.getTransform()) //checks to see if there position and rotation are the same.
{//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) %client.player.afkTimer += $dtVar::AFKloop;
{ if(%client.player.afkTimer >= $dtVar::AFKtime)
Game.AFKForceObserver(%client); {
return; Game.AFKForceObserver(%client);
} return;
} }
else }
{ else
%client.player.afkTimer = 0;//reset if moving %client.player.afkTimer = 0; //reset if moving
}
%client.player.curTransform = %client.player.getTransform();//save current transform //save current transform
%client.player.curTransform = %client.player.getTransform();
} }
////////////////////////////////////////////////////////////////////////////////
function DefaultGame::AFKForceObserver(%game, %client) function DefaultGame::AFKForceObserver(%game, %client)
{ {
if($Host::TournamentMode)
return;
//make sure we have a valid client... //make sure we have a valid client...
if (%client <= 0) if (%client <= 0)
return; return;
@ -196,23 +178,6 @@ function DefaultGame::AFKForceObserver(%game, %client)
logEcho(%client.nameBase@" (cl "@%client@") was forced into observer mode due to inactivity"); logEcho(%client.nameBase@" (cl "@%client@") was forced into observer mode due to inactivity");
%client.lastTeam = %client.team; %client.lastTeam = %client.team;
if($Host::TournamentMode)
{
if(!$matchStarted)
{
if(%client.camera.Mode $= "pickingTeam")
{
commandToClient( %client, 'processPickTeam');
clearBottomPrint( %client );
}
else
{
clearCenterPrint(%client);
%client.notReady = true;
}
}
}
// switch client to team 0 (observer) // switch client to team 0 (observer)
%client.team = 0; %client.team = 0;
%client.player.team = 0; %client.player.team = 0;
@ -233,4 +198,4 @@ function DefaultGame::AFKForceObserver(%game, %client)
// call the onEvent for this game type // call the onEvent for this game type
%game.onClientEnterObserverMode(%client); //Bounty uses this to remove this client from others' hit lists %game.onClientEnterObserverMode(%client); //Bounty uses this to remove this client from others' hit lists
} }