new lastupdate[MAX_PLAYERS]; public OnPlayerUpdate(playerid) { lastupdate[playerid] = gettime(); return 1; } isPlayerAFK(playerid) { return gettime() - lastupdate[playerid] > 3; // afk if player hasn't sent any updates for 3 seconds }
If a player is paused, he won't send updates anymore, so you can for example keep a variable for every player that tracks the last update, and if the current time subtracted by that last update is some amount of seconds, the player is afk.
Code:
new lastupdate[MAX_PLAYERS]; public OnPlayerUpdate(playerid) { lastupdate[playerid] = gettime(); return 1; } isPlayerAFK(playerid) { return gettime() - lastupdate[playerid] > 3; // afk if player hasn't sent any updates for 3 seconds } |
if(isPlayerAFK(playerid)){SendClientMessageToAll(-1,"A");}
// hook_secloop is a function that gets called every second public hook_secloop() { for( new i = 0; i < MAX_PLAYERS; i++ ) { if( isPlayerAFK( i ) ) SendClientMessageToAll( -1, "A" ); } }
If a player is paused, he won't send updates anymore, so you can for example keep a variable for every player that tracks the last update, and if the current time subtracted by that last update is some amount of seconds, the player is afk.
Code:
new lastupdate[MAX_PLAYERS]; public OnPlayerUpdate(playerid) { lastupdate[playerid] = gettime(); return 1; } isPlayerAFK(playerid) { return gettime() - lastupdate[playerid] > 3; // afk if player hasn't sent any updates for 3 seconds } |
It does work for me
Code:
// hook_secloop is a function that gets called every second public hook_secloop() { for( new i = 0; i < MAX_PLAYERS; i++ ) { if( isPlayerAFK( i ) ) SendClientMessageToAll( -1, "A" ); } } |