Textdraw dissapears after few seconds
#1

Hello. I am using textdraw and it works for about 20 seconds, but after that, it dissapears and never reapears again. Im using onplayerupdate. I know it can cause some lag but I need it since the information it gives is dynamic.

Code:
Код:
new Text:Textdraw0; // MDC
new Text:Textdraw1; // maverick seen
new Text:Textdraw2; // siren
Код:
public OnPlayerUpdate(playerid)
{
     TextDrawHideForPlayer(playerid,Textdraw1);
     TextDrawHideForPlayer(playerid,Textdraw2);
     ///////////////////////////////////////////////////////////////////////////
     if(team[playerid]==0)
     {
         new mavseenstring[25];
         if(newmavseen==0)
         {
		     format(mavseenstring,sizeof(mavseenstring),"Visual From Sky: ~r~No");
         }
         if(newmavseen==1)
         {
		     format(mavseenstring,sizeof(mavseenstring),"Visual From Sky: ~r~Yes");
         }
	     Textdraw1 = TextDrawCreate(388.000000, 310.000000, mavseenstring);
	     TextDrawBackgroundColor(Textdraw1, 255);
	     TextDrawFont(Textdraw1, 1);
	     TextDrawLetterSize(Textdraw1, 0.500000, 1.000000);    // "Visual From Sky: "
	     TextDrawColor(Textdraw1, -16776961);
	     TextDrawSetOutline(Textdraw1, 0);
	     TextDrawSetProportional(Textdraw1, 1);
	     TextDrawSetShadow(Textdraw1, 1);
	 
         TextDrawShowForPlayer(playerid,Textdraw1);
     }
	 ///////////////////////////////////////////////////////////////////////////
	 
	 ///////////////////////////////////////////////////////////////////////////
	 if(team[playerid]==0)
	 {
         new sirenstring[15];
         if(!IsPlayerInAnyVehicle(playerid))
         {
	    	 format(sirenstring,sizeof(sirenstring),"Siren: ~r~No");
         }
         else
         {
	    	 new vid=GetPlayerVehicleID(playerid);
             if(Siren[vid]==0)
             {
		         format(sirenstring,sizeof(sirenstring),"Siren: ~r~No");
             }
             if(Siren[vid]==1)
             {                                                    // siren info
	        	 format(sirenstring,sizeof(sirenstring),"Siren: ~r~Yes");
             }
         }
         Textdraw2 = TextDrawCreate(388.000000, 320.000000, sirenstring);
         TextDrawBackgroundColor(Textdraw2, 255);
         TextDrawFont(Textdraw2, 1);
         TextDrawLetterSize(Textdraw2, 0.500000, 1.000000);
         TextDrawColor(Textdraw2, -16776961);
         TextDrawSetOutline(Textdraw2, 0);
         TextDrawSetProportional(Textdraw2, 1);
         TextDrawSetShadow(Textdraw2, 1);

         TextDrawShowForPlayer(playerid,Textdraw2);
     }
	 ///////////////////////////////////////////////////////////////////////////
	 
     TextDrawHideForPlayer(playerid,Textdraw0);
	 if(team[playerid]==0)
	 {
         Textdraw0 = TextDrawCreate(560.000000, 312.000000, "Mobile Data Computer");
         TextDrawBackgroundColor(Textdraw0, 255);
         TextDrawFont(Textdraw0, 1);
         TextDrawLetterSize(Textdraw0, 0.500000, 1.000000);
         TextDrawColor(Textdraw0, -1);
         TextDrawSetOutline(Textdraw0, 1);                        // Blue police box
         TextDrawSetProportional(Textdraw0, 1);
         TextDrawUseBox(Textdraw0, 1);
         TextDrawBoxColor(Textdraw0, 65535);
         TextDrawTextSize(Textdraw0, 384.000000, 165.000000);
         TextDrawShowForPlayer(playerid,Textdraw0);
	 }
}
Any ideas?
Reply
#2

You're going over the textdraw limit because you're recreating the same textdraw over and over again without ever deleting old ones. Use TextDrawSetString instead. Much easier. Also you would probably want to have a per-player textdraw ([MAX_PLAYERS]).
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
You're going over the textdraw limit because you're recreating the same textdraw over and over again without ever deleting old ones. Use TextDrawSetString instead. Much easier. Also you would probably want to have a per-player textdraw ([MAX_PLAYERS]).
What's the point of making it a per-player text draw as it's very static and public text draw which will not change at any point for any player? You're wasting per-player text draw slots there, this kind of text draws should be global ones.

Just create the needed text draws under OnGameModeInit and show/hide them when you want.

pawn Код:
new Text:td_mavseen_no,
    Text:td_mavseen_yes,
    Text:td_siren_no,
    Text:td_siren_yes,
    Text:td_mobiledatacomputer;

public OnGameModeInit()
{
    td_mavseen_no = TextDrawCreate(388.000000, 310.000000, "Visual From Sky: ~r~No");
    TextDrawBackgroundColor(td_mavseen_no, 255);
    TextDrawFont(td_mavseen_no, 1);
    TextDrawLetterSize(td_mavseen_no, 0.500000, 1.000000);
    TextDrawColor(td_mavseen_no, -16776961);
    TextDrawSetOutline(td_mavseen_no, 0);
    TextDrawSetProportional(td_mavseen_no, 1);
    TextDrawSetShadow(td_mavseen_no, 1);

    td_mavseen_yes = TextDrawCreate(388.000000, 310.000000, "Visual From Sky: ~r~Yes");
    TextDrawBackgroundColor(td_mavseen_yes, 255);
    TextDrawFont(td_mavseen_yes, 1);
    TextDrawLetterSize(td_mavseen_yes, 0.500000, 1.000000);
    TextDrawColor(td_mavseen_yes, -16776961);
    TextDrawSetOutline(td_mavseen_yes, 0);
    TextDrawSetProportional(td_mavseen_yes, 1);
    TextDrawSetShadow(td_mavseen_yes, 1);

    td_siren_no = TextDrawCreate(388.000000, 320.000000, "Siren: ~r~No");
    TextDrawBackgroundColor(td_siren_no, 255);
    TextDrawFont(td_siren_no, 1);
    TextDrawLetterSize(td_siren_no, 0.500000, 1.000000);
    TextDrawColor(td_siren_no, -16776961);
    TextDrawSetOutline(td_siren_no, 0);
    TextDrawSetProportional(td_siren_no, 1);
    TextDrawSetShadow(td_siren_no, 1);

    td_siren_yes = TextDrawCreate(388.000000, 320.000000, "Siren: ~r~Yes");
    TextDrawBackgroundColor(td_siren_yes, 255);
    TextDrawFont(td_siren_yes, 1);
    TextDrawLetterSize(td_siren_yes, 0.500000, 1.000000);
    TextDrawColor(td_siren_yes, -16776961);
    TextDrawSetOutline(td_siren_yes, 0);
    TextDrawSetProportional(td_siren_yes, 1);
    TextDrawSetShadow(td_siren_yes, 1);

    td_mobiledatacomputer = TextDrawCreate(560.000000, 312.000000, "Mobile Data Computer");
    TextDrawBackgroundColor(td_mobiledatacomputer, 255);
    TextDrawFont(td_mobiledatacomputer, 1);
    TextDrawLetterSize(td_mobiledatacomputer, 0.500000, 1.000000);
    TextDrawColor(td_mobiledatacomputer, -1);
    TextDrawSetOutline(td_mobiledatacomputer, 1);
    TextDrawSetProportional(td_mobiledatacomputer, 1);
    TextDrawUseBox(td_mobiledatacomputer, 1);
    TextDrawBoxColor(td_mobiledatacomputer, 65535);
    TextDrawTextSize(td_mobiledatacomputer, 384.000000, 165.000000);
    return 1;
}
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(team[playerid] == 0)
    {
        TextDrawShowForPlayer(playerid, td_mobiledatacomputer);

        if(newmavseen == 0)
        {
            TextDrawShowForPlayer(playerid, td_mavseen_no);
        }
        else
        {
            TextDrawShowForPlayer(playerid, td_mavseen_yes);
        }

        new vid = GetPlayerVehicleID(playerid);
        if(vid && Siren[vid] == 1)
        {
            TextDrawShowForPlayer(playerid, td_siren_yes);
        }
        else
        {
            TextDrawShowForPlayer(playerid, td_siren_no);
        }
    }
    else
    {
        TextDrawHideForPlayer(playerid, td_mobiledatacomputer);
        TextDrawHideForPlayer(playerid, td_mavseen_yes);
        TextDrawHideForPlayer(playerid, td_mavseen_no);
        TextDrawHideForPlayer(playerid, td_siren_yes);
        TextDrawHideForPlayer(playerid, td_siren_no);
    }

    return 1;
}
Reply
#4

Thanks to both of you. Gave me an idea on how it should be. Right now it was also giving me massive lags
thanks again. Ill try it out. +rep for you
Reply
#5

By the way Finn,

I realized that your script is creating new and new textdraws on player update. wont this cause huge overwriting on screen and big lags too?
Reply
#6

Quote:
Originally Posted by Sam5513
Посмотреть сообщение
By the way Finn,

I realized that your script is creating new and new textdraws on player update. wont this cause huge overwriting on screen and big lags too?
No it doesn't, it's only showing and hiding the text draws.

Also I would recommend putting that in a timer instead of OnPlayerUpdate because showing some text draw doesn't have to be too accurate.
Reply
#7

Thank you for your quick response. I quite dont understand that it doesnt have to be too accurate. I mean, onplayerupdate happens like 20 times a second, no? So it really should be accurate.
Reply
#8

Quote:
Originally Posted by Sam5513
Посмотреть сообщение
Thank you for your quick response. I quite dont understand that it doesnt have to be too accurate. I mean, onplayerupdate happens like 20 times a second, no? So it really should be accurate.
Do you need to make sure the text draw will appear on the players' screens 20 times a second or would it be just fine if you checked it every second, or every 2 seconds? IMO a timer would be better choice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)