28.08.2016, 09:43
Hey guys. I'm having an issue with a loop. I get no errors or anything however it's not doing what I want it to do.
What the situation is.
I want a timer to be able to detect weather a player has gone "afk". AFK meaning standing in the same position for 5 minutes. Once the player has been standing in the same position for 5 minutes SendClientMessageToAll stating that Name has gone AFK.
This is the code I have however the problem is. Whenever no one touches their keyboard and goes "AFK" how ever many people are connected go "AFK" for example if there are three people connected in the server; Named Bob, Test and John. If John(ID:3) goes AFK you get John has gone AFK, Bob has gone AFK, Test has gone AFK. If Bob and Test are active it immediately says Bob is back, Test is back. No matter how many people are in the server, it will always display all the names. So loop isn't working properly? Or am I just doing it wrong? Could it be the timer?
What the situation is.
I want a timer to be able to detect weather a player has gone "afk". AFK meaning standing in the same position for 5 minutes. Once the player has been standing in the same position for 5 minutes SendClientMessageToAll stating that Name has gone AFK.
PHP код:
public AFKCheck()
{
new Float:x, Float:y, Float:z, string[128];
for (new i, j = GetPlayerPoolSize(); i <= j; i++)
{
if(!IsPlayerConnected(i)) continue;
if(IsAFK[i] == 1) return 0;
GetPlayerPos(i,x,y,z);
if(IsPlayerInRangeOfPoint(i,2,x,y,z))
{
AFK[i]++;
}
if(AFK[i] == 300)
{
format(string,sizeof(string),"*%s has gone AFK",GetName(i));//Formats the /do cmd output
SendClientMessageToAll(COLOR_WHITE,string);
IsAFK[i] = 1;
}
}
return 1;
}
PHP код:
AFKTime[playerid] = SetTimer("AFKCheck",1000,1);