05.09.2012, 10:05
Hello there, I need a system which will kick player who stayed 5min without moving. Basically it'll kick AFK people. If you don't move in 5 min, you'll get auto-kicked. Thanks from now.
new AfkCount[MAX_PLAYERS]; //<-- this will be our player variable for checking any AFK'ers.
stock IsPlayerAfk(playerid) return (AfkCount[playerid] > 1); //<-- usefull to check if the player is afk/desynced or not
public OnGameModeInit()
//..or
public OnFilterScriptInit()
{
SetTimer("SlowTick", 500, true); //<- our timer to increase the amount of our player variables.
return 1;
}
forward SlowTick();
public SlowTick()
{
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++) //<-- our player loop
{
if(!IsPlayerConnected(playerid)) continue; //<-- if not connected.. just check the next ID
AfkCount[playerid]++; //<-- adds always +1;
}
}
public OnPlayerConnect(playerid)
{
AfkCount[playerid] = 0; //resets after player login
return 1;
}
public OnPlayerUpdate(playerid)
{
AfkCount[playerid] = 0; //Resets after every player update (happens only if the player is not afk)
return 1;
}