17.02.2014, 09:12
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:
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)
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);
}
}
}
}
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)