Health float comparing for AFK system
#5

Quote:
Originally Posted by ZeeX
When they minimize the game, it doesn't send the data to the server, i.e. OnPlayerUpdate won't be called for them (I've tested it recently). So if you check the time between two packets are sent (use timer to do this) and it is over than some value, e.g. one second, then you know that the player paused his game.

Edit:
Here is implementation of my idea:
pawn Code:
#include <a_samp>

#define abs(%1) \
            ((%1 < 0) ? (-(%1)) : (%1))

new
    gPlayerTicks[MAX_PLAYERS],
    gPlayerIsAFK[MAX_PLAYERS];

#define UPDATE_TIMEOUT  10000

public OnPlayerUpdate(playerid)
{
    new
        ticks = GetTickCount();
    if (playerid < MAX_PLAYERS)
    {  
        if (gPlayerIsAFK[playerid])
        {
            gPlayerIsAFK[playerid] = false;
            printf("player #%d is back", playerid);
        }  
        else
        {
            SetTimerEx("OnPlayerUpdate", UPDATE_TIMEOUT + 1000, false, "i", playerid + MAX_PLAYERS);
        }
        gPlayerTicks[playerid] = ticks;
    }  
    else
    {
        playerid -= MAX_PLAYERS;
        if (!gPlayerIsAFK[playerid])
        {
            if (abs(gPlayerTicks[playerid] - ticks) > UPDATE_TIMEOUT)
            {
                gPlayerIsAFK[playerid] = true;
                printf("player #%d is AFK now", playerid);
            }
        }
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    gPlayerIsAFK[playerid] = false;
    return 1;
}
Code doesn't work, you never see the print.
Reply


Messages In This Thread
Health float comparing for AFK system - by Outbreak - 10.11.2009, 11:25
Re: Health float comparing - by Outbreak - 10.11.2009, 22:16
Re: Health float comparing - by Zeex - 10.11.2009, 22:30
Re: Health float comparing for AFK system - by Daren_Jacobson - 11.11.2009, 00:58
Re: Health float comparing - by cyber_punk - 11.11.2009, 10:59
Re: Health float comparing - by Outbreak - 11.11.2009, 12:45

Forum Jump:


Users browsing this thread: 1 Guest(s)