SA-MP Forums Archive
3D Text Label - removing when disconnects. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: 3D Text Label - removing when disconnects. (/showthread.php?tid=461419)



3D Text Label - removing when disconnects. - Dynamic - 01.09.2013

Basically I have got a script which shows up the player name in my server which automatically filters out the underscore, although I got an issue because the 3Dtextlabel gets attached to the playerid of the person and when I log out for example it removes, but when someone else logs in and have got the ID I had before his OWN name and MY name will appear and it will be one messy thing.

I have tried using but it does not work properly and still not works.
Код:
#include <a_samp>
public OnPlayerConnect(playerid)
{
	new Text3D:label = Create3DTextLabel(GetPlayersName(playerid), 0xFFFFFFAA, 30.0, 40.0, 50.0, 20.0, 0);
    Attach3DTextLabelToPlayer(label, playerid, 0.0, 0.0, 0.2);
    return 1;
}
public OnPlayerDisconnect(playerid)
{
	new Text3D:label = Create3DTextLabel(GetPlayersName(playerid), 0xFFFFFFAA, 30.0, 40.0, 50.0, 20.0, 0);
	 DeletePlayer3DTextLabel(playerid, Text3D:label);

}
Please help me out!

Thanks in advance.


AW: 3D Text Label - removing when disconnects. - NaS - 01.09.2013

Okay, you save the Label ID into your variable "label", which is, in your case, a LOCAL variable.
A local variable does only exist in the function you created it, so it gets deleted after executing OnPlayerConnect/Disconnect. This means the Label ID gets lost.

To fix this, you have to make your variable global - which is pretty simple.

Add

Код:
new Text3D:PlayerLabel[MAX_PLAYERS];
under your #include line. This will create an Array called PlayerLabel with the size of 500 (MAX_PLAYERS) - ****** "array" if you don't know what it is.

Now, in OnPlayerConnect you change the code to:

Код:
PlayerLabel[playerid] = Create3DTextLabel(GetPlayersName(playerid), 0xFFFFFFAA, 30.0, 40.0, 50.0, 20.0, 0);
Attach3DTextLabelToPlayer(PlayerLabel[playerid], playerid, 0.0, 0.0, 0.2);
The [playerid] tells pawn to put the Label ID into the array slot of that player's ID to access it later.

Now, to delete the label again, put this into OnPlayerDisconnect:

Код:
Delete3DTextLabel(PlayerLabel[playerid]);
And you're done!