Timer help
#1

Hi, I using this code and AFK time in label adding too fast. I know, that timer must add 1 sec, but when i test it system adding not 1, but 2 seconds in label afk time. Why?

Code:
new AFKTime[MAX_PLAYERS];
new AFKTimer[MAX_PLAYERS];
new Text3D:label[MAX_PLAYERS];

forward AFKCheck();

public OnPlayerConnect(playerid)
{
	AFKTimer[playerid] = SetTimer("AFKCheck",1000,1);
	label[playerid] = Create3DTextLabel(" ", 0xFFFFFFFF, 30.0, 40.0, 50.0, 40.0, 0);
	Attach3DTextLabelToPlayer(label[playerid], playerid, 0.0, 0.0, 0.7);
	return 1;
}

public OnPlayerUpdate(playerid)
{
	AFKTime[playerid] = 0;
	Update3DTextLabelText(label[playerid], 0xFFFFFFFF, " ");
	return 1;
}

public AFKCheck()
{
	new Float:Pos[3];
	for(new i = 0; i < MAX_PLAYERS; i++)
  	{
		GetPlayerPos(i,Pos[0],Pos[1],Pos[2]);
     	if(IsPlayerInRangeOfPoint(i,2,Pos[0],Pos[1],Pos[2]))
     	{
			AFKTime[i]++;
     	}
		if(AFKTime[i] > 20)
     	{
     	    new string[100];
			format(string, sizeof string, "This player is AFK {00FF00}(%d Seconds)", AFKTime[i]);
    		Update3DTextLabelText(label[i], 0xFFFFFFFF, string);
      	}
  	}
	return 1;
}
Reply
#2

This timer should go under OnGameModeInit, since it's calling global function for all players, your functions is not designed for per player call.
pawn Code:
SetTimer("AFKCheck", 1000, true);
Reply
#3

Thanks! How to do, that in label will show how much (hours, minuts and seconds) player is AFK, not only seconds?
Reply
#4

Edit:
My bad, thank you Threshold for correcting me, i was definitely sleepy.
pawn Code:
format(string, sizeof(string), "This player is AFK {00FF00}(%d hours %d minutes %d Seconds)", AFKTime[i] / 3600, (AFKTime[i] % 3600) / 60, AFKTime[i] % 60);
Reply
#5

Quote:
Originally Posted by Dragony92
View Post
pawn Code:
format(string, sizeof(string), "This player is AFK {00FF00}(%d hours %d minutes %d Seconds)", AFKTime[i]%3600, AFKTime[i]%60, AFKTime[i]);
pawn Code:
format(string, sizeof(string), "This player is AFK {00FF00}(%d hours %d minutes %d Seconds)", AFKTime[i] / 3600, (AFKTime[i] % 3600) / 60, AFKTime[i] % 60);
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)