SA-MP Forums Archive
Questions about AFK - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Questions about AFK (/showthread.php?tid=655955)



Questions about AFK - Ezzz - 03.07.2018

How do you determine if the player is in an AFK state and what I mean by AFK here is by pressing the ESC key or cutting out the game please call me back or the function
I am a Chinese. Maybe my English is not very good. Please understand that the samp in China is about to stop running
thanks!


Re: Questions about AFK - Ezzz - 03.07.2018

I mean is
How to check whether the player is in AFK state
There are no relative functions or callbacks


Re: Questions about AFK - Sew_Sumi - 03.07.2018

That's not AFK, that's Alt-Tabbed. OnPlayerUpdate doesn't get updated when the player is tabbed. But because of it's nature, bad internet can also cause packet-loss which will also not update OnPlayerUpdate.


This has been asked so many times before.


Re: Questions about AFK - Ezzz - 07.07.2018

So how do you detect a player in alt-tabbed?


Re: Questions about AFK - Sew_Sumi - 07.07.2018

https://sampforum.blast.hk/showthread.php?tid=281590

AFK is more sitting idle, in a car, or in a house not moving.

Alt-tabbed is in the menu/map, out in other apps.


packet loss, and a bad connection can cause the alt-tabbed scenario to trigger, as it's dropping packets and hence not having OnPlayerUpdate call as much as it should. This include likely copes with this.


Re: Questions about AFK - Kane - 07.07.2018

Checking if a player is alt tabbed is pretty simple.

Make two variables.
PHP код:
new 
    
gPauseUpdateMAX_PLAYERS ],
    
gIdleTimeMAX_PLAYERS ]

OnPlayerUpdate -
PHP код:
public OnPlayerUpdateplayerid )
{
    
gPauseUpdateplayerid ] = GetTickCount( );
    return 
1;

You'll need a one second timer.
PHP код:
public OnClientSecond()
{
    for( new 
playeridplayerid MAX_PLAYERSplayerid++ )
    {
        if( !
IsPlayerConnectedplayerid ) ) {
            continue;
        }
        if( 
GetTickCount( ) > ( gPauseUpdateplayerid ] + 3000 ) ) {
            
gIdleTimeplayerid ] ++;
        } else if( 
gIdleTimeplayerid ] ) gIdleTimeplayerid ] = 0;
    }
    return 
1;




Re: Questions about AFK - Sew_Sumi - 07.07.2018

^^ This is pretty good, for finding the tabbed players.

Just remember it will pick up people with bad connections, and people who are looking at the map.


Re: Questions about AFK - Ezzz - 07.07.2018

Thank you all