SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/12/2018, 05:25 PM   #1
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Issue with 3DTextLabel that's ment to vanish with a timer.

So, I want to have a 3DTextLabel that triggers OnPlayerSpawn and says "I recently spawned." for 20 seconds. However, it only seems to delete the label after 20 seconds for the first player that has it, and for the rest, it remains permanently.

See the code below:

Code:
new Text3D:PlayerLoginLabel[MAX_PLAYERS]; // //So each player has it's own 3DTextLabel.
new ExistentPlayerLoginLabels; // In order to know which label is which. 
new LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn

public OnPlayerSpawn(playerid)
{
        new LoginLabelid; // A variable to define label ID's (used for the timers)
    	ExistentLoginLabels++;
    	LoginLabelid = ExistentPlayerLoginLabels;
    	LoginLabelDespawnTimer[LoginLabelid] = SetTimerEx("LabelTimer", 20000, false, "i", LoginLabelid);
        return 1;
}

forward LabelTimer(LoginLabelid);
public LabelTimer(LoginLabelid)
{
    Delete3DTextLabel(PlayerLoginLabel[LoginLabelid]);
}
Stefhan is offline   Reply With Quote
Old 28/12/2018, 06:02 PM   #2
CantBeJohn
Big Clucker
 
CantBeJohn's Avatar
 
Join Date: Oct 2016
Posts: 112
Reputation: 15
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

I feel like you're over complicating things for no reason. It looks like you're manually trying to keep track of 3D Text IDS when Create3DText already returns it's corresponding ID.

Something like this should work:
PHP Code:
new
    
Text3D:PlayerLoginLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel.
    
LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.)

public OnPlayerSpawn(playerid)
{
    if(!
IsValid3DTextLabel(PlayerLoginLabel[playerid])) // In case someone spawns multiple times while the 3D Text is valid/created.
    
{
        
PlayerLoginLabel[playerid] = Create3DTextLabel(. . . ); // Put your Create3DTextLabel here.
        
LoginLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer"20000false"i"playerid);
    }
    return 
1;
}

forward SpawnLabelTimer(playerid);
public 
SpawnLabelTimer(playerid)
{
    if(
IsValid3DTextLabel(PlayerLoginLabel[playerid]))
    {
        
Delete3DTextLabel(PlayerLoginLabel[playerid]);
        
PlayerLoginLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
    }

CantBeJohn is offline   Reply With Quote
Old 28/12/2018, 06:29 PM   #3
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,209
Reputation: 144
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by CantBeJohn View Post
I feel like you're over complicating things for no reason. It looks like you're manually trying to keep track of 3D Text IDS when Create3DText already returns it's corresponding ID.

Something like this should work:
PHP Code:
new
    
Text3D:PlayerLoginLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel.
    
LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.)

public OnPlayerSpawn(playerid)
{
    if(!
IsValid3DTextLabel(PlayerLoginLabel[playerid])) // In case someone spawns multiple times while the 3D Text is valid/created.
    
{
        
PlayerLoginLabel[playerid] = Create3DTextLabel(. . . ); // Put your Create3DTextLabel here.
        
LoginLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer"20000false"i"playerid);
    }
    return 
1;
}

forward SpawnLabelTimer(playerid);
public 
SpawnLabelTimer(playerid)
{
    if(
IsValid3DTextLabel(PlayerLoginLabel[playerid]))
    {
        
Delete3DTextLabel(PlayerLoginLabel[playerid]);
        
PlayerLoginLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
    }

Even though the timer isn't set to repeat, you should still kill it
__________________
beckzy is offline   Reply With Quote
Old 28/12/2018, 06:42 PM   #4
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by CantBeJohn View Post
I feel like you're over complicating things for no reason. It looks like you're manually trying to keep track of 3D Text IDS when Create3DText already returns it's corresponding ID.

Something like this should work:
PHP Code:
new
    
Text3D:PlayerLoginLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel.
    
LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.)

public OnPlayerSpawn(playerid)
{
    if(!
IsValid3DTextLabel(PlayerLoginLabel[playerid])) // In case someone spawns multiple times while the 3D Text is valid/created.
    
{
        
PlayerLoginLabel[playerid] = Create3DTextLabel(. . . ); // Put your Create3DTextLabel here.
        
LoginLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer"20000false"i"playerid);
    }
    return 
1;
}

forward SpawnLabelTimer(playerid);
public 
SpawnLabelTimer(playerid)
{
    if(
IsValid3DTextLabel(PlayerLoginLabel[playerid]))
    {
        
Delete3DTextLabel(PlayerLoginLabel[playerid]);
        
PlayerLoginLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
    }

This code looks great, thank you so much for your assistance. But I can't compile the code.

Code:
error 017: undefined symbol "IsValid3DTextLabel"
Also, I've found that chat bubbles can overlap the label at OnPlayerText, any way to kill it at OnPlayerText if it's still enabled?
Stefhan is offline   Reply With Quote
Old 28/12/2018, 08:05 PM   #5
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

So I installed YSF and compiled the code, but now the labels won't appear at all.

My current code:

Code:
new 
    Text3D:PlayerLoginLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel. 
    LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.) 

public OnPlayerSpawn(playerid)
{
    	if(!IsValid3DTextLabel(PlayerLoginLabel[playerid]))
    	{ 
        	PlayerLoginLabel[playerid] = Create3DTextLabel("I just spawned.", COLOR_YELLOW, 0, 0, 0, 20, 0);
        	LoginLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer", 20000, false, "i", playerid); 
    	}
	return 1;
}

forward SpawnLabelTimer(playerid); 
public SpawnLabelTimer(playerid) 
{ 
    if(IsValid3DTextLabel(PlayerLoginLabel[playerid])) 
    { 
        Delete3DTextLabel(PlayerLoginLabel[playerid]); 
        PlayerLoginLabel[playerid] = Text3D:INVALID_3DTEXT_ID; 
    } 
}
Anyone, please help me out.
Stefhan is offline   Reply With Quote
Old 29/12/2018, 04:51 AM   #6
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,209
Reputation: 144
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by Stefhan View Post
So I installed YSF and compiled the code, but now the labels won't appear at all.

My current code:

Code:
new 
    Text3D:PlayerLoginLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel. 
    LoginLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.) 

public OnPlayerSpawn(playerid)
{
    	if(!IsValid3DTextLabel(PlayerLoginLabel[playerid]))
    	{ 
        	PlayerLoginLabel[playerid] = Create3DTextLabel("I just spawned.", COLOR_YELLOW, 0, 0, 0, 20, 0);
        	LoginLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer", 20000, false, "i", playerid); 
    	}
	return 1;
}

forward SpawnLabelTimer(playerid); 
public SpawnLabelTimer(playerid) 
{ 
    if(IsValid3DTextLabel(PlayerLoginLabel[playerid])) 
    { 
        Delete3DTextLabel(PlayerLoginLabel[playerid]); 
        PlayerLoginLabel[playerid] = Text3D:INVALID_3DTEXT_ID; 
    } 
}
Anyone, please help me out.
What's your define of COLOR_YELLOW? What alpha are you using? E.G. 0xFFFF00FF . Also add KillTimer(LoginLabelDespawnTimer[playerid]); at the end of the timer.
__________________
beckzy is offline   Reply With Quote
Old 29/12/2018, 06:38 AM   #7
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by BeckzyBoi View Post
What's your define of COLOR_YELLOW? What alpha are you using? E.G. 0xFFFF00FF . Also add KillTimer(LoginLabelDespawnTimer[playerid]); at the end of the timer.
I added it, but I want to know why it's important. Isn't the fact that the timer is on "false" enough to kill it?

Anyways, my current issue is that it only works for the first player that gets the label. The other players, all have the label above their head until they logout instead of after 20 seconds.

The code right now:

Code:
new 
    Text3D:PlayerSpawnLabel[MAX_PLAYERS] = { Text3D:INVALID_3DTEXT_ID, ... }, // So each player has it's own 3DTextLabel. 
    SpawnLabelDespawnTimer[MAX_PLAYERS]; // A timer for each label to despawn. (Although technically, unless you specifically need to use the timer ids somewhere else in your code; you don't even need a variable to store all the timer ids.)

public OnPlayerSpawn(playerid)
{
         if(!IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
	    	{ 
	        PlayerSpawnLabel[playerid] = Create3DTextLabel("I just spawned.", COLOR_YELLOW, 0, 0, 0, 20, 0);
	        Attach3DTextLabelToPlayer(PlayerSpawnLabel[playerid], playerid, 0.0, 0.0, 0.27);
	        SpawnLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer", 20000, false, "i", playerid); 
	        }
	return 1;
}

forward SpawnLabelTimer(playerid); 
public SpawnLabelTimer(playerid) 
{ 
    if(IsValid3DTextLabel(PlayerSpawnLabel[playerid])) 
    { 
        Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
        PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID; 
        KillTimer(SpawnLabelDespawnTimer[playerid]);
    } 
}
Thanks a lot for your help so far.
Stefhan is offline   Reply With Quote
Old 29/12/2018, 07:13 AM   #8
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,209
Reputation: 144
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by Stefhan View Post
I added it, but I want to know why it's important. Isn't the fact that the timer is on "false" enough to kill it?
No it doesn't kill it, it just stops it from repeating.

Quote:
Originally Posted by Stefhan View Post
Anyways, my current issue is that it only works for the first player that gets the label. The other players, all have the label above their head until they logout instead of after 20 seconds.
Code:
new Text3D:PlayerSpawnLabel[MAX_PLAYERS] = {Text3D:INVALID_3DTEXT_ID, ...};
new SpawnLabelDespawnTimer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    if (!IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    { 
        PlayerSpawnLabel[playerid] = Create3DTextLabel("I just spawned.", COLOR_YELLOW, 0, 0, 0, 20, 0);
        SpawnLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer", 20000, false, "i", playerid);
    }
    // attach it regardless of whether it already existed
    Attach3DTextLabelToPlayer(PlayerSpawnLabel[playerid], playerid, 0.0, 0.0, 0.27);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if (IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    {
        Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
        PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
        KillTimer(SpawnLabelDespawnTimer[playerid]);
    }
    return 1;
}

public OnPlayerDeath(playerid)
{
    if (IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    {
        Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
        PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
        KillTimer(SpawnLabelDespawnTimer[playerid]);
    }
    return 1;
}

forward SpawnLabelTimer(playerid);

public SpawnLabelTimer(playerid) 
{ 
    Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
    PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID; 
    KillTimer(SpawnLabelDespawnTimer[playerid]);
}
__________________
beckzy is offline   Reply With Quote
Old 29/12/2018, 03:42 PM   #9
Stefhan
Big Clucker
 
Stefhan's Avatar
 
Join Date: Nov 2014
Posts: 139
Reputation: 0
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by BeckzyBoi View Post
No it doesn't kill it, it just stops it from repeating.



Code:
new Text3D:PlayerSpawnLabel[MAX_PLAYERS] = {Text3D:INVALID_3DTEXT_ID, ...};
new SpawnLabelDespawnTimer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    if (!IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    { 
        PlayerSpawnLabel[playerid] = Create3DTextLabel("I just spawned.", COLOR_YELLOW, 0, 0, 0, 20, 0);
        SpawnLabelDespawnTimer[playerid] = SetTimerEx("SpawnLabelTimer", 20000, false, "i", playerid);
    }
    // attach it regardless of whether it already existed
    Attach3DTextLabelToPlayer(PlayerSpawnLabel[playerid], playerid, 0.0, 0.0, 0.27);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if (IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    {
        Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
        PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
        KillTimer(SpawnLabelDespawnTimer[playerid]);
    }
    return 1;
}

public OnPlayerDeath(playerid)
{
    if (IsValid3DTextLabel(PlayerSpawnLabel[playerid]))
    {
        Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
        PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID;
        KillTimer(SpawnLabelDespawnTimer[playerid]);
    }
    return 1;
}

forward SpawnLabelTimer(playerid);

public SpawnLabelTimer(playerid) 
{ 
    Delete3DTextLabel(PlayerSpawnLabel[playerid]); 
    PlayerSpawnLabel[playerid] = Text3D:INVALID_3DTEXT_ID; 
    KillTimer(SpawnLabelDespawnTimer[playerid]);
}
Thank you so much, it finally works like a charm!

One last question, should I always killtimers? Even those that are ment to loop?
Stefhan is offline   Reply With Quote
Old 29/12/2018, 04:07 PM   #10
jop9888
Big Clucker
 
Join Date: Mar 2009
Posts: 116
Reputation: 6
Default Re: Issue with 3DTextLabel that's ment to vanish with a timer.

Quote:
Originally Posted by BeckzyBoi View Post
Even though the timer isn't set to repeat, you should still kill it
Why would you have to kill a timer that is not repeating when its function gets called. That is already handled by the timer itself after completing the function right.
jop9888 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is better Per Player Timer or Global timer? (issue with timer) Dokins Scripting Help 4 07/06/2016 10:50 AM
/vanish help jamjamnewbie Scripting Help 3 02/11/2014 01:19 AM
3DTextLabel Issue CrystalMethod Scripting Help 7 05/05/2013 05:38 AM
What are switches ment for? (Dialogs). rangerxxll Scripting Help 6 17/03/2013 07:22 PM
3DTextLabel Issue!! BlackWolf120 Help Archive 6 16/02/2011 08:10 PM


All times are GMT. The time now is 06:48 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.