How to identify AFK people
#1

hello there, i was wondering if there is a way to identify afk people

I was thinking, maybe saving their coordinates and when a payday comes, if they are the same then they dont get paid but that doesnt make much sense if they are just chatting :P or they could just take a bus bot to avoid the system

so i figured, if player hasnt pressed any keys for the last 20 minutes, then he is AFK

Can u give me a hint about how to identify if there has been any key pressing in the last 20, if player moves i guess I would use a tickcount
Reply
#2

I'm not sure if this is what you request:
http://forum.sa-mp.com/index.php?topic=130673.0
Reply
#3

I would use tickcounts too.
Always get the current tickcount unter OnPlayerKeyStateChange.
If its over 20 minutes, then .. kick him. I don't know, just try it out. OnPlayerKeyStateChange doesn't support all keys, but the most important ones which should be regularly pressed ..
Reply
#4

is there a list of keys supported?
I think I will use that system :P
I hope it supports chat keys too? abcdefg..

thanks


------

knool, that one identifies position, can be avoided by taking a bus bot and ride it for hours :P
Reply
#5

https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

Key list:
https://sampwiki.blast.hk/wiki/GetPlayerKeys
Reply
#6

Well you'd have to use GetTickCount() on a player variable and update it only when the player speaks, presses a button, or has moved.

pawn Код:
#define AFKTIME 900000 //15 minutes in milliseconds
//#define USEPOSITION //decomment this if you want to check for position change
forward AFKCheck();
new pLastMoment[MAX_PLAYERS];
#if defined USEPOSITION
new Float:pOldPos[MAX_PLAYERS][3];
#endif
new pIsAFK[MAX_PLAYERS];
new pKeys;
public OnGameModeInit()
{
  SetTimer("AFKCheck",1000,1);
  return 1;
}
public OnPlayerConnect(playerid)
{
  pLastMoment[playerid]=GetTickCount();
  return 1;
}
public OnKeyStateChange(playerid,newkeys,oldkeys)
{
  pLastMoment[playerid]=GetTickCount();
  return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
  pLastMoment[playerid]=GetTickCount();
  return 1;
}
public OnPlayerUpdate(playerid)
{
  #if defined USEPOSITION
  if(!IsPlayerInRangeOfPoint(playerid,0.0,pOldPos[playerid][0],pOldPos[playerid][1],pOldPos[playerid][2]))pLastMoment[playerid]=GetTickCount();
  GetPlayerPos(playerid,pOldPos[playerid][0],pOldPos[playerid][1],pOldPos[playerid][2]);
  #endif
  GetPlayerKeys(playerid,pKeys,pKeys);
  if(pKeys)pLastMoment[playerid]=GetTickCount();
  return 1'
}
public AFKCheck()
{
  if(GetTickCount()-pLastMoment[playerid]>AFKTIME)
  {
    pIsAFK[playerid]=1;
    //function here (kick(playerid)?)
  }
}
Reply
#7

Thanks!
Reply
#8

There is a much simpler way of detecting if someone is paused/alt-tabbed. Since OnPlayerUpdate doesn't get called when you aren't in the actual game, create a variable and set it to 0 constantly under OnPlayerUpdate. Then set a (1 second) timer which check if the variable is 1 (if yes, then he's afk) and after the check set it to 1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)