Question about 3DTextLabel's. [UNSOLVED] -
$Marco$ - 11.06.2014
Hello there,
I was making a custom "name" for people to take off the health bar if they want it, but for some reason I couldn't "
delete" it.
Here is what I've done:
pawn Код:
new HealthBars[MAX_PLAYERS];
CMD:healthbars(playerid)
{
new Text3D:PlayerID[MAX_PLAYERS];
if(HealthBars[playerid] == 1)
{
new string[25], Float:Xpos, Float:Ypos, Float:Zpos;
GetPlayerPos(playerid, Xpos, Ypos, Zpos);
PlayerID[playerid] = Create3DTextLabel(string, 0xFFFFFFFF, Xpos, Ypos, Zpos + 1.34, 20.0, 0);
Attach3DTextLabelToPlayer(PlayerID[playerid], playerid, 0.0, 0.0, 0.14);
HealthBars[playerid] = 1;
}
else
{
Delete3DTextLabel(PlayerID[playerid]); // THIS IS WHATS NOT DELETING
HealthBars[playerid] = 0;
return 1;
}
return 1;
}
I will be really happy if anyone will tell my why the TextLabel is not deleting itself when i type /healthbars for the second time.
FURTHER EXPLANATION: [INCASE YOU DIDN'T UNDERSTAND]
When a player types in
/healthbars it will remove his
OWN healthbar (by hiding his nametag and placing a 3DTextLabel attached above his head) so when he want's to show his healthbar again he types
/healthbars and his nametag shows itself again while the 3DTextLabel gets
erased.
The problem I'm having:
When player with the ID 0 types
/healthbars, it hides its health everything is good.
ID 1 now types
/healthbars, it hides its health everything is good.
ID 0 now decides to show his health again so he re-types
/healthbars and it shows his healthbar but
ALSO the 3DTextLabel with his name which doesn't need to be there (It doesn't delete it for some reason).
TL
R:
It needs to create your own PERSONAL 3DTextLabel above your head and delete this own personal 3DTextLabel when you retype the CMD.
Re: Question about 3DTextLabel's. -
Rittik - 11.06.2014
Example :-
Код:
new Text3D:MyLabel;
MyLabel = Create3DTextLabel(...);
Delete3DTextLabel(MyLabel);
Re: Question about 3DTextLabel's. -
$Marco$ - 11.06.2014
This is not working, it will always delete the first created textlabel (I think)
Re: Question about 3DTextLabel's. -
Rittik - 11.06.2014
Can you explain about your problem a little bit more ?
Re: Question about 3DTextLabel's. -
$Marco$ - 11.06.2014
When a player types in
/healthbars it will remove his
OWN healthbar (by hiding his nametag and placing a 3DTextLabel attached above his head) so when he want's to show his healthbar again he types
/healthbars and his nametag shows itself again while the 3DTextLabel gets
erased.
The problem I'm having:
When player with the ID 0 types
/healthbars, it hides its health everything is good.
ID 1 now types
/healthbars, it hides its health everything is good.
ID 0 now decides to show his health again so he re-types
/healthbars and it shows his healthbar but
ALSO the 3DTextLabel with his name which doesn't need to be there (It doesn't delete it for some reason).
TL ; DR:
It needs to create your own PERSONAL 3DTextLabel above your head and delete this own personal 3DTextLabel when you retype the CMD.
Re: Question about 3DTextLabel's. -
$Marco$ - 11.06.2014
Anyone?
Re: Question about 3DTextLabel's. -
$Marco$ - 11.06.2014
Bump.
Re: Question about 3DTextLabel's. -
Richie© - 11.06.2014
Try making PlayerID to global var.
Re: Question about 3DTextLabel's. -
Threshold - 11.06.2014
This needs to be a global variable:
pawn Код:
new Text3D:PlayerID[MAX_PLAYERS];
Currently every time you use '/healthbars' it gives PlayerID[playerid] a new value (which is 0 by default). So when you use /healthbars to delete the text, it will always delete Label ID 0. What you need to do is this:
pawn Код:
new HealthBars[MAX_PLAYERS]; //At the top of your script.
new Text3D:PlayerID[MAX_PLAYERS]; //At the top of your script.
CMD:healthbars(playerid)
{
if(!HealthBars[playerid])
{
//new string[25]. Why? You're not formatting the string at all, so it will just be empty...
new string[25], Float:Xpos, Float:Ypos, Float:Zpos; //X, Y and Z isn't necessary.
GetPlayerPos(playerid, Xpos, Ypos, Zpos); //This isn't necessary.
PlayerID[playerid] = Create3DTextLabel(string, 0xFFFFFFFF, Xpos, Ypos, (Zpos + 1.34), 20.0, 0);
//Because you are attaching the label to a player, you can create the label anywhere like 0.0, 0.0, 0.0. It won't matter.
Attach3DTextLabelToPlayer(PlayerID[playerid], playerid, 0.0, 0.0, 0.14);
}
else Delete3DTextLabel(PlayerID[playerid]);
HealthBars[playerid] = (HealthBars[playerid]) ? (0) : (1);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(HealthBars[playerid]) Delete3DTextLabel(PlayerID[playerid]);
//Rest of code...
}
public OnPlayerConnect(playerid)
{
HealthBars[playerid] = 0;
//Rest of code..
}