20.11.2016, 21:11
OnPlayerUpdate doesnt get called when they pause their game
This will work with ANY time of AFK
Problem with the system?
Dont use both OnPlayerUpdate & 1 second timer for this.
Basically what can happen is that you have that looping timer + OnPlayerUpdate with CallLocalFunction that call the same callback, its like an infinite loop when it detects that the player is AFK
pawn Код:
#define PAUSE_TIME 60 //we are setting pause time to 60 seconds. It means, if they are AFK for more than 60 seconds = kick. Change this to how many SECONDS you want. (5 minutes = 300 seconds)
new lastCheck[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
lastCheck[playerid] = gettime()+PAUSE_TIME; //We will just save their first check on connect
return 1;
}
public OnPlayerUpdate(playerid)
{
if(lastCheck[playerid] < gettime()) {
//Lets say they were afk for 5 seconds (PAUSE_TIME default)? This will not be called for 5 or more seconds (until they come back)
/* Shortly, how this works?
1. Player A is playing, we are saving last time he Updated (moves, wrote something etc...)
2. Player A is not doing anything for 5 seconds? (PAUSE_TIME) then OnPlayerUpdate will not be called.
3. They are back? OnPlayerUpdate gets called and checks if they were AFK for more than PAUSE_TIME seconds
*/
Kick(playerid); //we are kicking them or w/e you want to do here
}
lastCheck[playerid] = gettime()+PAUSE_TIME; //saving the time when he last responded
return 1;
}
This will work with ANY time of AFK
Problem with the system?
- Player is AFK but still in game (like not alttabbed or anything as such) he might get shot/hit by a car, receives SendClientMessage etc, the system will call OnPlayerUpdate
- Player closes the game while alt-tabbed. The OnPlayerUpdate wont be called since he wasnt in the game when he exited (for example if he kills the process thru Task Manager etc)
Dont use both OnPlayerUpdate & 1 second timer for this.
Basically what can happen is that you have that looping timer + OnPlayerUpdate with CallLocalFunction that call the same callback, its like an infinite loop when it detects that the player is AFK