SA-MP Forums Archive
How to detect a tabbing player? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to detect a tabbing player? (/showthread.php?tid=605150)



How to detect a tabbing player? - Lirbo - 15.04.2016

Hi, how can I detect a tabbing player? not talking about a player that's not moving for a while, i'm talking about the ones who're tabbing. my friend told me to check if they return values or something like that, i'm not sure what he meant, could anyone explain me how to do it?


Re: How to detect a tabbing player? - yugecin - 15.04.2016

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
}



Re: How to detect a tabbing player? - Lirbo - 15.04.2016

Quote:
Originally Posted by yugecin
View Post
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
}
ergh it doesnt work to me, I tried to insert this into a loop:
PHP Code:
if(isPlayerAFK(playerid)){SendClientMessageToAll(-1,"A");} 
but it didn't send me anything.


Re: How to detect a tabbing player? - yugecin - 15.04.2016

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" );
	}
}



Re: How to detect a tabbing player? - Lirbo - 15.04.2016

Quote:
Originally Posted by yugecin
View Post
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
}
Quote:
Originally Posted by yugecin
View Post
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" );
	}
}
Well doesnt work for me, i placed the function you made at OnPlayerUpdate at the same loop cuz whenever i'm putting it OnPlayerUpdate it's crashing my pc when i login