Play time randomly goes up when player goes afk
#6

You can detect it using OnPlayerUpdate because it don't get called when player goes paused. Here's a small include which I've wrote before, using it, the code would be:
pawn Код:
forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
    if(IsPlayerPaused(playerid)) return 0; //Callback doesn't continue if player is paused.
    PlayerInfo[playerid][MinutesPlayed]++;
    if(PlayerInfo[playerid][MinutesPlayed] >= 60)
    {
        PlayerInfo[playerid][MinutesPlayed] = 0;
        PlayerInfo[playerid][HoursPlayed]++;
        if (PlayerInfo[playerid][pTeamKills] > 0)
        {
            PlayerInfo[playerid][pTeamKills]--;
            new Level;
            new Kills = PlayerInfo[playerid][pKills];
            new Deaths = PlayerInfo[playerid][pDeaths];
            new Penalty = 2 * PlayerInfo[playerid][pTeamKills];
            Level = (Kills - Deaths) - Penalty;
            if (Level < 0)
            {
                SetPlayerScore(playerid, 0);
            }
            else
            {
                SetPlayerScore(playerid, Level);
            }
        }
    }
    else if(PlayerInfo[playerid][MinutesPlayed] == 30 )
    {
        if (PlayerInfo[playerid][pTeamKills] > 0)
        {
            PlayerInfo[playerid][pTeamKills]--;
            new Level;
            new Kills = PlayerInfo[playerid][pKills];
            new Deaths = PlayerInfo[playerid][pDeaths];
            new Penalty = 2 * PlayerInfo[playerid][pTeamKills];
            Level = (Kills - Deaths) - Penalty;
            if (Level < 0)
            {
                SetPlayerScore(playerid, 0);
            }
            else
            {
                SetPlayerScore(playerid, Level);
            }
        }
    }
}
Include : https://github.com/Lordzy/AutoAFK

And if you're using a server sided AFK system, make sure that you determine the variable under "TimeOnServer" and return 0 in case if player is AFK (server sided)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)