#4

OnPlayerUpdate doesnt get called when they pause their game

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)
But besides that, should work with most of the AFK checks (alt tabbing, pressing escape to tab etc)

Quote:
Originally Posted by sampkinq
Посмотреть сообщение
Quote;
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
Reply


Messages In This Thread
Idea - by Shaheen - 20.11.2016, 19:14
Re: Idea - by sampkinq - 20.11.2016, 19:27
Re: Idea - by Kaliber - 20.11.2016, 19:34
Re: Idea - by TwinkiDaBoss - 20.11.2016, 21:11
Re: Idea - by iamjems - 21.11.2016, 09:06
Re: Idea - by IceBilizard - 21.11.2016, 09:17
Re: Idea - by Shaheen - 26.11.2016, 19:05

Forum Jump:


Users browsing this thread: 1 Guest(s)