Here's another way:
Note: The timer can be replaced with a different method if needed, like the "onTimeChange" event or something.
function AFKCheck()
{
foreach( ii , iv in Players )
{
if( iv.Spawned )
{
if( !IsTabbed[ iv.ID ] )
{
if( ( time( ) - LastTick[ iv.ID ] ) >= MAX_PAUSE_TIME )
{
IsTabbed[ iv.ID ] = true;
}
}
}
}
}
function onPlayerUpdate( player )
{
if( IsTabbed[ player.ID ] )
{
local amount = time( ) - LastTick[ player.ID ];
IsTabbed[ player.ID ] = false;
}
LastTick[ player.ID ] = time( );
}
function onScriptLoad( )
{
Players <- { };
LastTick <- array( 128 , 0 );
IsTabbed <- array( 128 , 0 );
// Time before each player is considered "paused" in seconds
// NOT in milliseconds
MAX_PAUSE_TIME <- 2;
AFKTimer <- NewTimer( "AFKCheck" , 500 , 0 );
}
function onPlayerConnect( player )
{
Players[ player.ID ] <- player;
}
function onPlayerPart( player , reason )
{
Players[ player.ID ] <- null;
}
EDIT: Some details I forgot to mention ...
The MAX_PAUSE_TIME can be any number, but 2 seems decent enough, so I chose it. It is used for how much time needs to pass before a player is considered "paused" and NOT how often the check happens.
Also, you can add other things to happen when a player pauses or unpauses. Turn the player into a ghost or something cool if you want.