enum afkInfo {
Float:aX,
Float:aY,
Float:aZ,
aCounter
};
new AFKPlayer[MAX_PLAYERS][afkInfo];
// Inside the timer:
for (new i = 0; i < MAX_PLAYERS; i++)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(i, x, y, z);
if (x == AFKPlayer[i][aX] && y == AFKPlayer[i][aY] && z == AFKPlayer[i][aZ])
{
AFKPlayer[i][aCounter]++;
if (AFKPlayer[i][aCounter] >= 15) // player has been AFk for 15 seconds or more
{
// Do things you want to do if player is AFK
}
}
else
{
AFKPlayer[i][aX] = x;
AFKPlayer[i][aY] = y;
AFKPlayer[i][aZ] = z;
AFKPlayer[i][aCounter] = 0;
}
}
|
Originally Posted by https://sampwiki.blast.hk/wiki/OnPlayerUpdate
This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for).
The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling. |
|
Depends on how many people are on the server.
OnPlayerUpdate gets called 30 times a second, so you do the math. I would recommend a timer though. |
OnGamemodeInit()...
SetTimer("CheckAFK", 800, true);
PUBLIC:CheckAFK()
{
foreach(new i : Player)
{
if(gettime() - AFKDetect[i] > 5 && !IsPlayerAFK[i])
{
IsPlayerAFK[i] = true;
TogglePlayerControllable(i, false);
SCMTAE(RED, "%s is now AFK.", GetName(i));
}
else if(gettime() - AFKDetect[i] < 5 && IsPlayerAFK[i])
{
IsPlayerAFK[i] = false;
TogglePlayerControllable(i, true);
SCMTAE(RED, "%s is not anymore AFK.", GetName(i));
}
}
return 1;
}
OnPlayerUpdate()..
AFKDetect[playerid] = gettime();