11.06.2014, 23:00
This needs to be a global variable:
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 Text3D:PlayerID[MAX_PLAYERS];
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..
}