TextDraw Help
#1

Hi. I have a textdraw that displays zones. But I want to hide the textdraw whilst in requestclass and whilst dead.

I've tried creating the textdraw under OnPlayerSpawn, however whenever I do that. Once I die, it creates a new one over the top and then bugs the textdraw. I've tried adding TextDrawHideForPlayer under the callback OnPlayerDeath, but it doesn't hide... I've tried TextDrawDestroy, under the callback OnPlayerDeath, it did end up destroying.

However it would only fix it for one player. Then I decided that I'd try change the textdraw to a PlayerText and I managed to get it to work perfectly, but it only works perfectly for one person. If another person joins the server the whole textdraw won't appear.

This is my text draw.
PHP код:
    SetTimer("Zones_Update"5001);
    for(new 
i=0i<MAX_PLAYERSi++)
    {
           
Zones[i] = CreatePlayerTextDraw(playerid,6.5425.4"_");
           
PlayerTextDrawLetterSize(playeridZones[i], 0.652.1);
           
PlayerTextDrawSetOutline(playeridZones[i], 1);
     } 
I have it being destroyed under OnPlayerDeath
PHP код:
PlayerTextDrawDestroy(playerid,Zones[playerid]); 
Does anyone have any ideas?
Reply
#2

first OnPlayerSpawn is not the correct place for creating a player textdraw...
So put it under OnPlayerConnect
PHP код:
public OnPlayerConnect(playerid)
{
           
Zones[playerid] = CreatePlayerTextDraw(playerid,6.5425.4"_"); 
           
PlayerTextDrawLetterSize(playeridZones[playerid], 0.652.1); 
           
PlayerTextDrawSetOutline(playeridZones[playerid], 1); 

When player spawn u have to show up the textdraw..
PHP код:
public OnPlayerSpawn(playerid)
{
           
PlayerTextDrawShow(playerid,Zones[playerid]); 

Now you have to hide it on OnPlayerDeath..
PHP код:
public OnPlayerDeath(playerid)
{
      
PlayerTextDrawHide(playerid,Zones[playerid]); 

If Zone_update is Global then put it under OnGamemodeInit and if not then put it under OnPlayerConnect
PHP код:
public OnplayerConnect(playerid)
{
       
SetTimerEx("Zone_Update"5001"i"playerid);

It would be better if u repeat it after every 1 sec not not in every 1/2 sec.
Reply
#3

I wonder how people still use global textdraws with global variables for players when you need to use player text draws that does the job and are made for it.

Player textdraw code (taken from my gamemode):
How i create textdraws, using player textdraws
PHP код:
// top of the script
new PlayerText:PlayerTD;
// creating it on OPConnect
PlayerTD CreatePlayerTextDraw(playeridXXX.000000XXX.000000" ");
PlayerTextDrawBackgroundColor(playeridPlayerTDXXX);
PlayerTextDrawFont(playeridPlayerTDX);
PlayerTextDrawColor(playeridPlayerTDXX);
PlayerTextDrawSetOutline(playeridPlayerTDXX);
PlayerTextDrawSetShadow(playeridPlayerTDX);
PlayerTextDrawLetterSize(playeridPlayerTDXXXXXX);
PlayerTextDrawSetSelectable(playeridPlayerTDXX);
// destroying it on OPDisconnect
PlayerTextDrawDestroy(playeridPlayerTD);
// how to display it
PlayerTextDrawSetString(playeridPlayerTD"~r~ XXXXX");
PlayerTextDrawShow(playeridPlayerTD); 
This is wrong... Player who use global textdraws for players, use this method which causes bugs and isn't recommended.
PHP код:
new PlayerText:Zones[MAX_PLAYERS]; /* or */ new Text:Zones[MAX_PLAYERS]; // wrong method
Zones[playerid] = CreatePlayerTextDraw(playerid,6.5425.4"_"); 
it should be like
PHP код:
new PlayerText:Zones//right method
Zones CreatePlayerTextDraw(playerid,6.5425.4"_"); 
Reply
#4

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
I wonder how people still use global textdraws with global variables for players when you need to use player text draws that does the job and are made for it.

Player textdraw code (taken from my gamemode):
How i create textdraws, using player textdraws
PHP код:
// top of the script
new PlayerText:PlayerTD;
// creating it on OPConnect
PlayerTD CreatePlayerTextDraw(playeridXXX.000000XXX.000000" ");
PlayerTextDrawBackgroundColor(playeridPlayerTDXXX);
PlayerTextDrawFont(playeridPlayerTDX);
PlayerTextDrawColor(playeridPlayerTDXX);
PlayerTextDrawSetOutline(playeridPlayerTDXX);
PlayerTextDrawSetShadow(playeridPlayerTDX);
PlayerTextDrawLetterSize(playeridPlayerTDXXXXXX);
PlayerTextDrawSetSelectable(playeridPlayerTDXX);
// destroying it on OPDisconnect
PlayerTextDrawDestroy(playeridPlayerTD);
// how to display it
PlayerTextDrawSetString(playeridPlayerTD"~r~ XXXXX");
PlayerTextDrawShow(playeridPlayerTD); 
This is wrong... Player who use global textdraws for players, use this method which causes bugs and isn't recommended.
PHP код:
new PlayerText:Zones[MAX_PLAYERS]; /* or */ new Text:Zones[MAX_PLAYERS]; // wrong method
Zones[playerid] = CreatePlayerTextDraw(playerid,6.5425.4"_"); 
it should be like
PHP код:
new PlayerText:Zones//right method
Zones CreatePlayerTextDraw(playerid,6.5425.4"_"); 
Your code is wrong... if you want to edit your player textdraws when there are more than 1 player online, how do you expect to do that if the textdraw ID gets overwritten every time a new player connects?

Correction:
pawn Код:
// top of the script
new PlayerText:PlayerTD[MAX_PLAYERS];

// creating it on OPConnect
PlayerTD[playerid] = CreatePlayerTextDraw(playerid, XXX.000000, XXX.000000, " ");
PlayerTextDrawBackgroundColor(playerid, PlayerTD[playerid], XXX);
PlayerTextDrawFont(playerid, PlayerTD[playerid], X);
PlayerTextDrawColor(playerid, PlayerTD[playerid], XX);
PlayerTextDrawSetOutline(playerid, PlayerTD[playerid], XX);
PlayerTextDrawSetShadow(playerid, PlayerTD[playerid], X);
PlayerTextDrawLetterSize(playerid, PlayerTD[playerid], XXX, XXX);
PlayerTextDrawSetSelectable(playerid, PlayerTD[playerid], XX);

// destroying it on OPDisconnect
PlayerTextDrawDestroy(playerid, PlayerTD[playerid]);

// how to display it
PlayerTextDrawSetString(playerid, PlayerTD[playerid], "~r~ XXXXX");
PlayerTextDrawShow(playerid, PlayerTD[playerid]);
Reply
#5

Thanks guys for your input. I did what you both said. However I got this warning. Warning: client exceeded 'ackslimit' I went through my code and it was to to with my Zone_Update. Fixed it but now my server is very laggy. Also the Textdraw doesn't show for some people. I logged into the server first, I could see if. After my friend logged in they couldn't see the textdraw. Any ideas?
Reply
#6

Wait, when exactly are you trying to create the textdraw, and what exactly does Zone_Update do?

Here's what I suggest you do.
pawn Код:
// Global variable
new PlayerText:Zones[MAX_PLAYERS];

// OnPlayerConnect
Zones[playerid] = CreatePlayerTextDraw(playerid, 6.5, 425.4, "_");
PlayerTextDrawLetterSize(playerid, Zones[playerid], 0.65, 2.1);
PlayerTextDrawSetOutline(playerid, Zones[playerid]);

// OnPlayerDeath
PlayerTextDrawDestroy(playerid, Zones[playerid]);
If you have it being destroyed under OnPlayerDeath, is it not meant to show again? If the player is meant to see it again, then you should either re-create it under OnPlayerSpawn or not destroy it all and only destroy it on disconnect.
Reply
#7

Quote:
Originally Posted by ALiScripter
Посмотреть сообщение
I wonder how people still use global textdraws with global variables for players when you need to use player text draws that does the job and are made for it.

Player textdraw code (taken from my gamemode):
How i create textdraws, using player textdraws
PHP код:
// top of the script
new PlayerText:PlayerTD;
// creating it on OPConnect
PlayerTD CreatePlayerTextDraw(playeridXXX.000000XXX.000000" ");
PlayerTextDrawBackgroundColor(playeridPlayerTDXXX);
PlayerTextDrawFont(playeridPlayerTDX);
PlayerTextDrawColor(playeridPlayerTDXX);
PlayerTextDrawSetOutline(playeridPlayerTDXX);
PlayerTextDrawSetShadow(playeridPlayerTDX);
PlayerTextDrawLetterSize(playeridPlayerTDXXXXXX);
PlayerTextDrawSetSelectable(playeridPlayerTDXX);
// destroying it on OPDisconnect
PlayerTextDrawDestroy(playeridPlayerTD);
// how to display it
PlayerTextDrawSetString(playeridPlayerTD"~r~ XXXXX");
PlayerTextDrawShow(playeridPlayerTD); 
This is wrong... Player who use global textdraws for players, use this method which causes bugs and isn't recommended.
PHP код:
new PlayerText:Zones[MAX_PLAYERS]; /* or */ new Text:Zones[MAX_PLAYERS]; // wrong method
Zones[playerid] = CreatePlayerTextDraw(playerid,6.5425.4"_"); 
it should be like
PHP код:
new PlayerText:Zones//right method
Zones CreatePlayerTextDraw(playerid,6.5425.4"_"); 
but the [PHP] is not in File server in SAMP php is server internet explorer only!
Reply
#8

This is what my Zones_Update does.

PHP код:
public Zones_Update(playerid)
{
    new 
zone[MAX_ZONE_NAME], string[30];
    for(new 
i=0i<MAX_PLAYERSi++){
    
GetPlayer2DZone(izoneMAX_ZONE_NAME);
    
format(string,sizeof(string),"%s"zone);
    
PlayerTextDrawSetString(playeridZones[i], string);}
    return 
1;
}

stock GetPlayer2DZone(playeridzone[], len)
{
    new 
Float:xFloat:yFloat:z;
    
GetPlayerPos(playeridxyz);
     for(new 
0!= sizeof(gSAZones); i++ )
     {
        if(
>= gSAZones[i][SAZONE_AREA][0] && <= gSAZones[i][SAZONE_AREA][3] && >= gSAZones[i][SAZONE_AREA][1] && <= gSAZones[i][SAZONE_AREA][4])
        {
            return 
format(zonelengSAZones[i][SAZONE_NAME], 0);
        }
    }
    return 
0;

Reply
#9

Try that what i have said..

And destroy Playertextdraw OnPLayerDissconnect
PHP код:
public OnPlayerDissconnect(playerid)
{
      
PlayerTextDrawDestroy(playeridZone[playerid]);

Reply
#10

Oh, well that's relatively easy then.

pawn Код:
// Global variables
new PlayerText:Zones[MAX_PLAYERS];
new ZoneUpdateTimer[MAX_PLAYERS];

// OnPlayerConnect
Zones[playerid] = CreatePlayerTextDraw(playerid, 6.5, 425.4, "_");
PlayerTextDrawLetterSize(playerid, Zones[playerid], 0.65, 2.1);
PlayerTextDrawSetOutline(playerid, Zones[playerid], 1);

// OnPlayerSpawn
Zones_Update(playerid);
ZoneUpdateTimer[playerid] = SetTimerEx("Zones_Update", 2000, true, "i", playerid);

// OnPlayerDeath
PlayerTextDrawHide(playerid, Zones[playerid]);
KillTimer(ZoneUpdateTimer[playerid]);

// OnPlayerDisconnect
KillTimer(ZoneUpdateTimer[playerid]);
PlayerTextDrawDestroy(playerid, Zones[playerid]);

forward Zones_Update(playerid);
public Zones_Update(playerid)
{
    new zone[MAX_ZONE_NAME];
    GetPlayer2DZone(playerid, zone, MAX_ZONE_NAME);
    PlayerTextDrawSetString(playerid, Zones[playerid], zone);
    return 1;
}
I think 500ms is far too fast to be updating any sort of textdraw unless it's something like vehicle speed. For locations I wouldn't look for anything under a second. You weren't assigning a player ID to the 'Zones_Update' function, so it was always using '0' as the player ID, but you were still using a loop even though the player ID was being passed. So every time a new player connected your timer would be called again and you'd have multiple instances.

Use SetTimerEx for passing parameters to a timer function. (https://sampwiki.blast.hk/wiki/SetTimerEx)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)