Offline player help
#1

Hello all
I have this system to check if player is AFK(that clock symbol above his head)
If he is AFK(...) PlayerInfo[i][AFK] = 0;
When he is back PlayerInfo[i][AFK] = 1;
Why it doesn't work ?

Problem is that it doesn't shift from 0 to 1 or from 1 to 0
My timer for " UpdatePlayerStatus " is 1 second
PHP код:

new PlayerTick[MAX_PLAYERS];
function 
UpdatePlayerStatus(playerid)
{
CheckAFK();
//MY OTHER STUFF
//MY OTHER STUFF
//MY OTHER STUFF
//MY OTHER STUFF....
return 1;
}
function 
CheckAFK()
{
foreach(new 
Player)
{
new 
Tick;
Tick GetTickCount();
if((
Tick PlayerTick[i]) > 750)
{
if(
PlayerInfo[i][AFK] == 0)
{
PlayerInfo[i][AFK] = 1;
}
}
else
{
if(
PlayerInfo[i][AFK] == 1)
{
PlayerInfo[i][AFK] = 0;
}
}
}
return 
1;

Reply
#2

I would do something like this

Код:
forward AFKToggle(playerid);
public AFKToggle(playerid)
{
      PlayerInfo[playerid][AFK] = 1;
}

public OnPlayerUpdate(playerid)
{
         PlayerInfo[playerid][AFK] = 0;

         //// YOUR CODE HERE

         SetTimerEx("AFKToggle", 2000, false, "i", playerid);
}
OnPlayerUpdate is called very often and the timer at the end will set your player back to AFK 2 seconds after it is last called. I haven't tested this myself but hopefully when the player tabs out, the timer will still get called and they will still be set to AFK because OnPlayerUpdate is not called to set them back to not AFK as they are tabbed out.
Reply
#3

Nope
I use timer for other stuff too.....
Whats wrong with my code!?
Reply
#4

The problem is your code logic, nothing else. You didn't show us where you set the per-player variable "PlayerTick", so I assume it's 0.
Since the "Tick" or tick count will always be bigger than 0 it only executes that statement and "PlayerInfo[i][AFK]" is always set to a 1.

Listen to what HarrisonC said - that is the only right way to do this. You need one timer(looping through all players) and one per player variable. Then under OnPlayerUpdate you constantly reset the AFK counter to 0. In the timer you increase that counter and if the value is not 0 then the player has most likely pressed ESCAPE or ALT-tabbed and gone AFK for a while. Note this doesn't detect AFK if the player didn't press the ESC button.
Reply
#5

Yea playertick is 0...
How can I make MY code to work ?
I triend but nothing!
Reply
#6

Don't try to make your (wrong) code work, instead embrace the suggestions we gave you to make a fully working code which is correct and which is what you want.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)