player afk 3dtextlable problem
#1

hi guys so i create this system for showing other players how many time a paused player has been away from the keyboard [on his head]:

Code:
// ======= AFK LABLE ====== //
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
          if(IsPlayerPaused(i) == true)
          {
                 afktimer[i]++;
                   if(afktimer[i] > 0)
                   {
                            new stra[200];
	 		    format(stra,sizeof(stra),"AFK : %d Sec",afktimer[i]);
		 	    afklable[i] = Create3DTextLabel(str, COLOR_CYAN, 30.0, 40.0, 50.0, 40.0, 0);
			    Attach3DTextLabelToPlayer(afklable[i], i, 0.0, 0.0, 0.5);
     		   }
           }
    }
// ======= AFK LABLE ====== //

// ======= AFK LABLE - REMOVE ====== //
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
			 if(IsPlayerPaused(i) != true && afktimer[i] > 0)
			 {
    		         afktimer[i] = 0;
			 Delete3DTextLabel(afklable[i]);
			 }
	}
// ======= AFK LABLE - REMOVE ====== //
but i have a problem 3dtext will not update the attached text , its looks like a spam , AFK : time on another AFK time i mean the older will not disappear and new timer with new seconds will be on older one!!
hope you got what im saying , sorry for my bad english please help me with this <3
Reply
#2

Add
Code:
Delete3DTextLabel(afklable[i]);
Just before
Code:
afklable[i] = Create3DTextLabel(str, COLOR_CYAN, 30.0, 40.0, 50.0, 40.0, 0);
Reply
#3

thnx but it will disapeare for a sec i see some serveres this 3dtext will not disapear and shows like textdraw is there any better soloution??
Reply
#4

alright now i have another problem , its just show for 1 person , if another player afk at the same time other guy who was esc will lose his 3dtext
Reply
#5

Quote:
Originally Posted by Joe Staff
View Post
Add
Code:
Delete3DTextLabel(afklable[i]);
Just before
Code:
afklable[i] = Create3DTextLabel(str, COLOR_CYAN, 30.0, 40.0, 50.0, 40.0, 0);
Why destroy and recreate constantly if you can also just update the text?

Quote:
Originally Posted by PoniStar
View Post
alright now i have another problem , its just show for 1 person , if another player afk at the same time other guy who was esc will lose his 3dtext
Might be because of the Delete code you added. If the variable wasn't used before it will be ID 0 that gets deleted, which at that point might be a valid label for another player.

Initialize the array for each player with an invalid ID in OnPlayerConnect, eg. INVALID_3DTEXT_ID. Then in the timer, check if the ID you want to delete is valid before deleting.
When you finally delete the label when the player returns, set player's array slot to INVALID_3DTEXT_ID again.

That way you ensure no unrelated Labels get deleted.

You can also switch to Update3DTextLabelText instead of recreating so this wouldn't be a problem.
Reply
#6

Agreed with NaS. Create the 3D text only once, update the text accordingly, delete and set the variable to INVALID when player returns, delete and set the variable as INVALID when a player disconnects.
Reply
#7

well im a little confiused can you edit it for me
Reply
#8

can you guys just edit this for me? im really confiused 😭
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)