18.08.2011, 22:38
Okay that is just PLAIN HORRIBLE.
You should definitely not use PVars in OnPlayerUpdate. And actually you don't even need GetTickCount().
What you should do to detect AFKing is:
1. in OnPlayerUpdate, keep setting a variable to 0
2. in your 1-second timer, keep incrementing the variable until it reaches 2. If it reaches 2, the player is not sending updates anymore (is paused, about to time out, whatever)
Basic but you get the idea.
You should definitely not use PVars in OnPlayerUpdate. And actually you don't even need GetTickCount().
What you should do to detect AFKing is:
1. in OnPlayerUpdate, keep setting a variable to 0
2. in your 1-second timer, keep incrementing the variable until it reaches 2. If it reaches 2, the player is not sending updates anymore (is paused, about to time out, whatever)
pawn Код:
new updating[MAX_PLAYERS char];
public OnGameModeInit()
{
SetTimer("checkAFK", 1000, true);
}
public OnPlayerUpdate(playerid)
{
updating{playerid} = 0;
}
forward checkAFK();
public checkAFK()
{
foreach(Player, i)
{
if(updating{i} < 2)
updating{i} ++;
else
{
// Player went AFK!
}
}
}