forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
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);
}
}
}
}
Don't increase the variable if they're AFK.
You can check if they're paused by setting a variable to 5 under OnPlayerUpdate and have the value decrease every 1 second. If the variable is ever three or below, they're AFK. That way you can stop increasing the time online variable. |
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);
}
}
}
}
public OnPlayerUpdate(playerid)
{
AFKCheck[playerid] = 5;
SetTimerEx("AfkTimer", 1000, 1, "i", playerid);
return 1;
}
forward AfkTimer(playerid);
public AfkTimer(playerid)
{
AFKCheck[playerid]--;
if (AFKCheck[playerid] < 3)
{
AFK[playerid] = 1;
SendClientMessage(playerid, COLOR_ORANGE, "Debug - Now afk");
}
else
{
AFK[playerid] = 0;
}
}