how to make auto afk system - 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 make auto afk system (
/showthread.php?tid=330055)
how to make auto afk system -
Xtreme Brotherz - 31.03.2012
i want to make an auto afk system so tht if a player press esc he will be auto afk.. i want just the code in knowing whether a player is in esc or not
Re: how to make auto afk system -
Xtreme Brotherz - 31.03.2012
nobody?
Re: how to make auto afk system -
AndreT - 31.03.2012
I will not give you an exact full working code since you should do some searching on your own, however I can tell you that OnPlayerUpdate is not called when the player is not in-game (paused or alt-tabbed).
Sometimes I see people doing this with GetTickCount() and then comparing times, but this isn't actually necessary. All you need is a variable that is getting reset in the OnPlayerUpdate callback and incremented in an one-second timer.
pawn Код:
new AFK[MAX_PLAYERS];
// ...
public OnGameModeInit()
{
// Run a timer here
SetTimer("CheckAFK", 1000, true);
}
// ...
public OnPlayerUpdate(playerid)
{
// If the player just came back from being afk, the AFK variable is most likely more than 3/5 (vary this based on your gamemode and experience)
if(AFK[playerid] > 3)
{
// This player just came back from being AFK
}
AFK[playerid] = 0;
}
// ...
forward CheckAFK();
public CheckAFK()
{
// Suggestions for loop: either use foreach or at least define MAX_PLAYERS to your server's server.cfg amount!
for(new i = 0; i != MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
AFK[i] ++;
if(AFK[i] == 3)
{
// The player most likely just went AFK!
}
}
}
Starting from around 5 seconds, you can also probably effectively tell for how long the player has been away from the game.
pawn Код:
format(string, sizeof(string), "%s(%i) has been away from keyboard for %d seconds.", PlayerName, playerid, AFK[playerid]);
SendClientMessageToAll(-1, string);
Perhaps I should make some sort of a library for AFK detection this way. Unsure at this point, but keep in mind the code probably does not work, but it should give you a good idea how it is supposed to work.
Re: how to make auto afk system -
lordturhan - 31.03.2012
Maybe you can check if player pressed esc key?
Re: how to make auto afk system -
Randyy - 31.03.2012
Yeah pressing the key ESC, or ALT, TAB because most of the guys using that.
Good luck.