SA-MP Forums Archive
Textdraw ID Mess up - 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: Textdraw ID Mess up (/showthread.php?tid=331301)



Textdraw ID Mess up - Psycho77 - 04.04.2012

Hey Guys

first I have to say that my english is very bad.

I try to describe my problem:

My Textdraws which will be destroyed and created in between times mess up their IDs.

I search since a long time for a solution and i think i found the reason for it.

Let me try to explain:


I have 2 Textdraws for example:

Код:
new PlayerText:Txt1
new PlayerText:Txt2

Txt1 = CreatePlayerTextDraw(...);
Txt2 = CreatePlayerTextDraw(...);
now Txt1 and Txt2 have a specific value.
For example:

Txt1 = 1
Txt2 = 2

Because: Txt1 ist the first textdraw which was created and got the ID 1, Text2 the second and got the ID2.

Now i Destroy both Textdraws:
Код:
PlayerTextDrawDestroy(Txt1);
PlayerTextDrawDestroy(Txt2);
And now i think they have the follow values:

Txt1 = 1
Txt2 = 2

The Textdraws are destroyed but the variables habe stil the same values. I dont know whether its right that they have stil the same values, because i dont know how to reproduce the IDs in a print for example.

Now i create Txt2 again, you have to know that there arent any Textdraws, so Txt2 get the ID 1.

Now the values:

Txt1 = 1
Txt2 = 1

As you can see they have the same values and if i do anything with Txt1 it will have impacts on Txt2.

I hope you understand it.

Now i tried to set the value to -1 when the TextDraw was destroyed, but then i got an Error because it is the wrong type (float, integer, ...).


I hope you could unterstand me and anyone knows a solution.


Re: Textdraw ID Mess up - Unte99 - 04.04.2012

Show us how you use TextDrawSetString and the declarations of the variables (new ...).


Re: Textdraw ID Mess up - Psycho77 - 04.04.2012

Код:
enum pTDInfo
{
	PlayerText:InfoBoxHeader,
	PlayerText:InfoBoxInfo,
	PlayerText:TachoInfo1,
	PlayerText:TachoInfo2,
	PlayerText:TachoInfo3
}

new pTextDraw[MAX_PLAYERS][pTDInfo];
Код:
public CreateSpeedo(playerid)
{
	/*new str[1000];
	format(str,sizeof(str),"{008400}%s\n",cInfo[GetVehicleModel(GetPlayerVehicleID(playerid))-400][cName]);
	format(str,sizeof(str),"%s\n{0000B2}Geschwindigkeit:      {FFFFFF}000 Km/h",str);
	format(str,sizeof(str),"%s\n{0000B2}Tempomat:               {FFFFFF}000 Km/h",str);
	format(str,sizeof(str),"%s\n{0000B2}Status:                    {FFFFFF}1000 / 1000",str);
	format(str,sizeof(str),"%s\n{0000B2}Tank:                        {FFFFFF}000 / 000L",str);
	Tachotext[playerid] = CreateDynamic3DTextLabel(str,0xFFFFFFFF,0.0,0.0,0.0,10.0,INVALID_PLAYER_ID,GetPlayerVehicleID(playerid),0,0,0,playerid,15.0);*/

	//Tacho:
	pTextDraw[playerid][TachoInfo1] = CreatePlayerTextDraw(playerid, 320.000000, 391.000000, "_");
	PlayerTextDrawAlignment(playerid, pTextDraw[playerid][TachoInfo1], 2);
	PlayerTextDrawBackgroundColor(playerid, pTextDraw[playerid][TachoInfo1], 255);
	PlayerTextDrawFont(playerid, pTextDraw[playerid][TachoInfo1], 2);
	PlayerTextDrawLetterSize(playerid, pTextDraw[playerid][TachoInfo1], 0.180000, 0.800000);
	PlayerTextDrawColor(playerid, pTextDraw[playerid][TachoInfo1], -1);
	PlayerTextDrawSetOutline(playerid, pTextDraw[playerid][TachoInfo1], 0);
	PlayerTextDrawSetProportional(playerid, pTextDraw[playerid][TachoInfo1], 1);
	PlayerTextDrawSetShadow(playerid, pTextDraw[playerid][TachoInfo1], 1);

	pTextDraw[playerid][TachoInfo2] = CreatePlayerTextDraw(playerid, 223.0, 403.0, "Geschwindigkeit: 000 Km/h~n~~n~Tank: 000/000L");
	PlayerTextDrawBackgroundColor(playerid, pTextDraw[playerid][TachoInfo2], 255);
	PlayerTextDrawFont(playerid, pTextDraw[playerid][TachoInfo2], 2);
	PlayerTextDrawLetterSize(playerid, pTextDraw[playerid][TachoInfo2], 0.155000, 0.760000);
	PlayerTextDrawColor(playerid, pTextDraw[playerid][TachoInfo2], -1);
	PlayerTextDrawSetOutline(playerid, pTextDraw[playerid][TachoInfo2], 0);
	PlayerTextDrawSetProportional(playerid, pTextDraw[playerid][TachoInfo2], 1);
	PlayerTextDrawSetShadow(playerid, pTextDraw[playerid][TachoInfo2], 1);

	pTextDraw[playerid][TachoInfo3] = CreatePlayerTextDraw(playerid, 357.000000, 403.000000, "Tempomat: 000~n~~n~Status: 1000/1000");
	PlayerTextDrawBackgroundColor(playerid, pTextDraw[playerid][TachoInfo3], 255);
	PlayerTextDrawFont(playerid, pTextDraw[playerid][TachoInfo3], 2);
	PlayerTextDrawLetterSize(playerid, pTextDraw[playerid][TachoInfo3], 0.155000, 0.760000);
	PlayerTextDrawColor(playerid, pTextDraw[playerid][TachoInfo3], -1);
	PlayerTextDrawSetOutline(playerid, pTextDraw[playerid][TachoInfo3], 0);
	PlayerTextDrawSetProportional(playerid, pTextDraw[playerid][TachoInfo3], 1);
	PlayerTextDrawSetShadow(playerid, pTextDraw[playerid][TachoInfo3], 1);
	
	TextDrawShowForPlayer(playerid,gTextDraw[TachoMain1]);
	TextDrawShowForPlayer(playerid,gTextDraw[TachoMain2]);
	TextDrawShowForPlayer(playerid,gTextDraw[TachoMain3]);
	TextDrawShowForPlayer(playerid,gTextDraw[TachoMain4]);
	PlayerTextDrawShow(playerid,pTextDraw[playerid][TachoInfo1]);
	PlayerTextDrawShow(playerid,pTextDraw[playerid][TachoInfo2]);
	PlayerTextDrawShow(playerid,pTextDraw[playerid][TachoInfo3]);
	return 1;
}

public DestroySpeedo(playerid)
{
    //DestroyDynamic3DTextLabel(Tachotext[playerid]);
    
    //Tacho:
	TextDrawHideForPlayer(playerid,gTextDraw[TachoMain1]);
	TextDrawHideForPlayer(playerid,gTextDraw[TachoMain2]);
	TextDrawHideForPlayer(playerid,gTextDraw[TachoMain3]);
	TextDrawHideForPlayer(playerid,gTextDraw[TachoMain4]);
	p_PlayerTextDrawDestroy(playerid, pTextDraw[playerid][TachoInfo1]);
	p_PlayerTextDrawDestroy(playerid, pTextDraw[playerid][TachoInfo2]);
	p_PlayerTextDrawDestroy(playerid, pTextDraw[playerid][TachoInfo3]);
    return 1;
}

public UpdateSpeedo()
{
	for(new v = 0; v < MAX_VEHICLES; v++)
	{
		if(!vInfo[v][vCreatet] || !IstFahrzeugMotorisiert(v)) continue;
	    new playerid, engine, light, alarm, door, bonnet, boot, objective;
	    GetVehicleDriver(v,playerid);
	    p_GetVehicleParamsEx(v, engine, light, alarm, door, bonnet, boot, objective);
		if(!engine)
        {
            p_SetVehicleParamsEx(v, engine, 0, alarm, door, bonnet, boot, objective);
			if(playerid != INVALID_PLAYER_ID) DestroySpeedo(playerid);
			continue;
        }
        if(vInfo[v][vTank] <= 0)
		{
			p_SetVehicleParamsEx(v,0,0,alarm,door,bonnet,boot,objective);
			if(playerid != INVALID_PLAYER_ID)
			{
				DestroySpeedo(playerid);
				SendClientMessage(playerid,rot,"Ihr Tank ist leer! Benutzen Sie einen Kanister oder rufen Sie den ADAC!");
			}
			continue;
		}
		if(sirenean[v])
		{
			if(light == 0) p_SetVehicleParamsEx(v, engine, 1, alarm, door, bonnet, boot, objective);
			else p_SetVehicleParamsEx(v, engine, 0, alarm, door, bonnet, boot, objective);
		}
		vInfo[v][vTankVerbrauch] ++;
		if(vInfo[v][vTankVerbrauch] >= cInfo[GetVehicleModel(v)-400][cVerbrauchSekunden] * 5)
		{
			vInfo[v][vTankVerbrauch] = 0;
		    vInfo[v][vTank]--;
		    if(vInfo[v][vTank] < cInfo[GetVehicleModel(v)-400][cMaxTank] / 12 && playerid != INVALID_PLAYER_ID) PlayerPlaySound(playerid, 1084, 0.0, 0.0, 4.0);
		}
		if(playerid == INVALID_PLAYER_ID) continue;
		new Float:Health, Float:Speed, DisplayedSpeed;
		GetVehicleHealth(v, Health);
	    GetVehicleSpeed(v, Speed);
		new Float:x, Float:y, Float:z, Float:angle, Float:heading;
		GetVehicleVelocity(v, x, y, z);
		GetVehicleZAngle(v, angle);
		GetVehicleHeadingAngle(v, heading);
		DisplayedSpeed = floatround(Speed);
		if(floatround(Speed) < vInfo[v][vTempo] || vInfo[v][vTempo] < 10 || z > 0.5 || (floatabs(angle - heading) > 50 && floatabs(angle - heading) < 310)) {}
		else
		{
			SetVehicleSpeed(v,vInfo[v][vTempo]);
			DisplayedSpeed = vInfo[v][vTempo];
		}
		UpdateTacho(playerid, cInfo[GetVehicleModel(v)-400][cName], DisplayedSpeed, vInfo[v][vTempo], vInfo[v][vTank], cInfo[GetVehicleModel(v)-400][cMaxTank], floatround(Health, floatround_ceil));
		//UpdateDynamic3DTextLabelText(Tachotext[playerid],0xFFFFFFFF,GetSpeedoString(vInfo[v][vTempo],DisplayedSpeed,floatround(Health,floatround_round),vInfo[v][vTank],cInfo[GetVehicleModel(v)-400][cMaxTank],cInfo[GetVehicleModel(v)-400][cName]));
	}
	return 1;
}

stock UpdateTacho(playerid, Auto[], Geschw, Tempo, Tank, MaxTank, Status)
{
    new TankStr[50], StatsStr[50], GeschStr[50], TempoStr[30], str1[100], str2[100];

    format(TankStr, 50, "Tank: %d/%dL", Tank, MaxTank);
    format(StatsStr, 50, "Status: %d/1000", Status);
    format(GeschStr, 50, "%03d Km/h", Geschw);
    format(TempoStr, 30, "%03d", Tempo);

    format(str1,sizeof(str1),"%s~n~~n~%s",GeschStr,TankStr);
    format(str2,sizeof(str2),"     Tempomat: %s~n~~n~%s",TempoStr,StatsStr);

    PlayerTextDrawSetString(playerid, pTextDraw[playerid][TachoInfo1], Auto);
    PlayerTextDrawSetString(playerid, pTextDraw[playerid][TachoInfo2], str1);
    PlayerTextDrawSetString(playerid, pTextDraw[playerid][TachoInfo3], str2);
    return 1;
}
Код:
stock CreatePetrolInfo(playerid)
{
    DestroyBincoInfo(playerid);
    DestroyRepairInfo(playerid);

	pTextDraw[playerid][InfoBoxHeader] = CreatePlayerTextDraw(playerid,555.000000, 361.000000, "Unbekannt");
	PlayerTextDrawAlignment(playerid,pTextDraw[playerid][InfoBoxHeader], 2);
	PlayerTextDrawBackgroundColor(playerid,pTextDraw[playerid][InfoBoxHeader], 255);
	PlayerTextDrawFont(playerid,pTextDraw[playerid][InfoBoxHeader], 2);
	PlayerTextDrawLetterSize(playerid,pTextDraw[playerid][InfoBoxHeader], 0.140000, 0.899999);
	PlayerTextDrawColor(playerid,pTextDraw[playerid][InfoBoxHeader], -1);
	PlayerTextDrawSetOutline(playerid,pTextDraw[playerid][InfoBoxHeader], 0);
	PlayerTextDrawSetProportional(playerid,pTextDraw[playerid][InfoBoxHeader], 1);
	PlayerTextDrawSetShadow(playerid,pTextDraw[playerid][InfoBoxHeader], 1);

	pTextDraw[playerid][InfoBoxInfo] = CreatePlayerTextDraw(playerid,600.000000, 376.000000, "_");
	PlayerTextDrawAlignment(playerid,pTextDraw[playerid][InfoBoxInfo], 3);
	PlayerTextDrawBackgroundColor(playerid,pTextDraw[playerid][InfoBoxInfo], 255);
	PlayerTextDrawFont(playerid,pTextDraw[playerid][InfoBoxInfo], 2);
	PlayerTextDrawLetterSize(playerid,pTextDraw[playerid][InfoBoxInfo], 0.129999, 0.899999);
	PlayerTextDrawColor(playerid,pTextDraw[playerid][InfoBoxInfo], -1);
	PlayerTextDrawSetOutline(playerid,pTextDraw[playerid][InfoBoxInfo], 0);
	PlayerTextDrawSetProportional(playerid,pTextDraw[playerid][InfoBoxInfo], 1);
	PlayerTextDrawSetShadow(playerid,pTextDraw[playerid][InfoBoxInfo], 1);
	
	TextDrawShowForPlayer(playerid,gTextDraw[InfoBox1]);
	TextDrawShowForPlayer(playerid,gTextDraw[InfoBox2]);
	TextDrawShowForPlayer(playerid,gTextDraw[InfoBox3]);
	TextDrawShowForPlayer(playerid,gTextDraw[PetrolInfo]);
	PlayerTextDrawShow(playerid,pTextDraw[playerid][InfoBoxHeader]);
	PlayerTextDrawShow(playerid,pTextDraw[playerid][InfoBoxInfo]);
	
	UpdatePetrolInfo(playerid,GetPetrolInfoString(playerid),true);
	return 1;
}

stock UpdatePetrolInfo(playerid, tdstr[], bool:tankanzeige)
{
	new hstr[50];
	format(hstr,sizeof(hstr),"Unbekannt");
	for(new t = 0; t < sizeof Tanken; t++)
	{
        if(!IsPlayerInRangeOfPoint(playerid,15.0,Tanken[t][psx],Tanken[t][psy],Tanken[t][psz])) continue;
        format(hstr,sizeof(hstr),"~g~%s",Tanken[t][PSName]);
        break;
	}
	for(new t = 0; t < sizeof Flugzeugtanken; t++)
	{
        if(!IsAHelicopter(GetPlayerVehicleID(playerid)))
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,15.0,Flugzeugtanken[t][psx1],Flugzeugtanken[t][psy1],Flugzeugtanken[t][psz1])) continue;
	    }
	    else
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,15.0,Flugzeugtanken[t][psx2],Flugzeugtanken[t][psy2],Flugzeugtanken[t][psz2])) continue;
	    }
        format(hstr,sizeof(hstr),"~g~%s",Flugzeugtanken[t][PSName]);
        break;
	}
	PlayerTextDrawSetString(playerid,pTextDraw[playerid][InfoBoxHeader],hstr);
	PlayerTextDrawSetString(playerid,pTextDraw[playerid][InfoBoxInfo],tdstr);
	if(!tankanzeige) TextDrawHideForPlayer(playerid,gTextDraw[PetrolInfo]);
	return 1;
}

stock GetPetrolInfoString(playerid)
{
	new str[150], Float:lpreis, vehicleid = GetPlayerVehicleID(playerid);
	new model = GetVehicleModel(vehicleid)-400;
	for(new t = 0; t < sizeof Tanken; t++)
	{
        if(!IsPlayerInRangeOfPoint(playerid,15.0,Tanken[t][psx],Tanken[t][psy],Tanken[t][psz])) continue;
        lpreis = Tanken[t][Literpreis];
        break;
	}
	for(new t = 0; t < sizeof Flugzeugtanken; t++)
	{
        if(!IsAHelicopter(vehicleid))
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,15.0,Flugzeugtanken[t][psx1],Flugzeugtanken[t][psy1],Flugzeugtanken[t][psz1])) continue;
	    }
	    else
	    {
	        if(!IsPlayerInRangeOfPoint(playerid,15.0,Flugzeugtanken[t][psx2],Flugzeugtanken[t][psy2],Flugzeugtanken[t][psz2])) continue;
	    }
        lpreis = Tanken[t][Literpreis];
        break;
	}
	format(str,sizeof(str),"%d / %dL~n~$%0.2f~n~~n~$%0.2f",vInfo[vehicleid][vTank],cInfo[model][cMaxTank],lpreis,GetPVarFloat(playerid,"tanksumme"));
	return str;
}

stock DestroyPetrolInfo(playerid)
{
    TextDrawHideForPlayer(playerid,gTextDraw[InfoBox1]);
	TextDrawHideForPlayer(playerid,gTextDraw[InfoBox2]);
	TextDrawHideForPlayer(playerid,gTextDraw[InfoBox3]);
	TextDrawHideForPlayer(playerid,gTextDraw[PetrolInfo]);
	p_PlayerTextDrawDestroy(playerid,pTextDraw[playerid][InfoBoxHeader]);
	p_PlayerTextDrawDestroy(playerid,pTextDraw[playerid][InfoBoxInfo]);
	return 1;
}
//edit:

p_PlayerTextDrawDestroy = PlayerTextDrawDestroy.

I try to reset the ID so i write a own function:

Код:
stock p_PlayerTextDrawDestroy(playerid, PlayerText:text)
{
	PlayerTextDrawDestroy(playerid, text);
        //reset id;
	return 1;
}



Re: Textdraw ID Mess up - SpiritEvil - 04.04.2012

Try resetting the values of Txt1 and Txt2 manually after the Textdraw is destroyed.


Re: Textdraw ID Mess up - Psycho77 - 04.04.2012

yes, this is what i try but you cant give a variable like Text:lala or PlayerText:lala a value like '-1'

its like you give an integer a value like 200.000.


Re: Textdraw ID Mess up - SpiritEvil - 04.04.2012

Of course you can. When a textdraw is created they just hold an integer value which is returned after the textdraw is created. If you want to test this try the following code:

pawn Код:
new PlayerText:TD0;
new PlayerText:TD1;

public OnGameModeInit()
{
    TD0 = CreatePlayerTextDraw(playerid, 0.0, 0.0, "Textdraw0");
    TD1 = CreatePlayerTextDraw(playerid, 1.0, 1.0, "Textdraw1");
    printf("Textdraw0's ID: %i\nTextdraw1's ID: %i", _:TD0, _:TD1); //Should print 0 for TD0 and 1 for TD1
    return 1;
}



Re: Textdraw ID Mess up - Psycho77 - 04.04.2012

ah okay and how can i set the value.
if i do it so:

TD0 = 0;

I got an error because its the wrong type like i give an Integer a Value like 200.00


Re: Textdraw ID Mess up - Unte99 - 04.04.2012

Don't create textdraws in functions. It is best to create them in OnGameModeInit. You should read the wiki more: https://sampwiki.blast.hk/wiki/TextDrawCreate

pawn Код:
new Text:pTextDraw1[MAX_PLAYERS],Text:pTextDraw2[MAX_PLAYERS],Text:pTextDraw3[MAX_PLAYERS],Text:pTextDraw4[MAX_PLAYERS],Text:pTextDraw5[MAX_PLAYERS];

OnGameModeInit()
{
for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
{
pTextDraw1[playerid] = TextDrawCreate(playerid, 320.000000, 391.000000, "_");
TextDrawAlignment(playerid, pTextDraw1[playerid], 2);

pTextDraw2[playerid] = TextDrawCreate(playerid, 223.0, 403.0, "Geschwindigkeit: 000 Km/h~n~~n~Tank: 000/000L");
TextDrawBackgroundColor(playerid, pTextDraw2[playerid], 255);
}
}
Now when you set the string:

pawn Код:
TextDrawSetString(playerid,pTextDraw1[playerid],hstr);
TextDrawSetString(playerid,pTextDraw2[playerid],tdstr);
To show the textdraw:

pawn Код:
TextDrawShowForPlayer(playerid,gTextDraw1[playerid]);
To hide the textdraw:

pawn Код:
TextDrawHideForPlayer(playerid,gTextDraw1[playerid]);



Re: Textdraw ID Mess up - SpiritEvil - 04.04.2012

Try this to reset the values:

pawn Код:
PlayerTextDrawDestroy(Txt1);
PlayerTextDrawDestroy(Txt2);
_:Txt1 = 0;
_:Txt2 = 0;



Re: Textdraw ID Mess up - Psycho77 - 04.04.2012

Quote:
Originally Posted by Unte99
Посмотреть сообщение
Don't create textdraws in functions. It is best to create them in OnGameModeInit. You should read the wiki more: https://sampwiki.blast.hk/wiki/TextDrawCreate

pawn Код:
new Text:pTextDraw1[MAX_PLAYERS],Text:pTextDraw2[MAX_PLAYERS],Text:pTextDraw3[MAX_PLAYERS],Text:pTextDraw4[MAX_PLAYERS],Text:pTextDraw5[MAX_PLAYERS];

OnGameModeInit()
{
for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
{
pTextDraw1[playerid] = TextDrawCreate(playerid, 320.000000, 391.000000, "_");
TextDrawAlignment(playerid, pTextDraw1[playerid], 2);

pTextDraw2[playerid] = TextDrawCreate(playerid, 223.0, 403.0, "Geschwindigkeit: 000 Km/h~n~~n~Tank: 000/000L");
TextDrawBackgroundColor(playerid, pTextDraw2[playerid], 255);
}
}
Now when you set the string:

pawn Код:
TextDrawSetString(playerid,pTextDraw1[playerid],hstr);
TextDrawSetString(playerid,pTextDraw2[playerid],tdstr);
To show the textdraw:

pawn Код:
TextDrawShowForPlayer(playerid,gTextDraw1[playerid]);
To hide the textdraw:

pawn Код:
TextDrawHideForPlayer(playerid,gTextDraw1[playerid]);
I know how to make Textdraws.

And why should i create player Textdraws in OnGameModeInit.
My global textdraws are created in OnGameModeInit and destroyed in OngameModeExit.

When a player need the Textdraw it will be shown for the player and hide if not.

But my Player textdraws will create when it it is needed. And when it isnt needed anymore it will destroy.

I could create all playertextdraws when they connect and destroy when they leave, but why should i have unnecessary Textdraw created? Why u use an Object Streamer? because you dont need Object in LV while you are in LS or SF its the same

______

I tried it, but there are stil errors:

Код:
stock p_PlayerTextDrawDestroy(playerid, &PlayerText:text)
{
	PlayerTextDrawDestroy(playerid, text);
	_:text = -1;
}