SA-MP Forums Archive
TextDraw is duplicated unnecessarily - 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 is duplicated unnecessarily (/showthread.php?tid=615149)



TextDraw is duplicated unnecessarily - mikianto - 18.08.2016

Help! I have this problem:



This is code:

Quote:

if(GPLon[vehid]==1)
{
if(Gas[vehid]<=100 || Gas[vehid]>=70)
{
format(string, sizeof(string), "~g~......");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
PlayerTextDrawFont(playerid, SpeedometerText[playerid][3], 1);
}
else if(Gas[vehid]<70 || Gas[vehid]>=50)
{
format(string, sizeof(string), "~g~.....~w~.");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
else if(Gas[vehid]<50 || Gas[vehid]>=40)
{
format(string, sizeof(string), "~g~....~w~..");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
else if(Gas[vehid]<40 || Gas[vehid]>=30)
{
format(string, sizeof(string), "~y~...~w~...");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
else if(Gas[vehid]<30 || Gas[vehid]>=20)
{
format(string, sizeof(string), "~r~..~w~....");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
else if(Gas[vehid]<20 || Gas[vehid]>=1)
{
format(string, sizeof(string), "~r~.~w~.....");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
else if(Gas[vehid]<=0)
{
format(string, sizeof(string), "~r~......");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}
}
else
{
format(string, sizeof(string), "......");
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
}




Re: TextDraw is duplicated unnecessarily - Tass007 - 18.08.2016

This is untested but this may help.
PHP код:
if(GPLon[vehid]==1)
{
    if(
Gas[vehid]<=100 || Gas[vehid]>=70)
    {
        
format(stringsizeof(string), "~g~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
        
PlayerTextDrawFont(playeridSpeedometerText[playerid][3], 1);
    }
    else if(
Gas[vehid]<70 || Gas[vehid]>=50)
    {
        
format(stringsizeof(string), "~g~.....~w~.");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<50 || Gas[vehid]>=40)
    {
        
format(stringsizeof(string), "~g~....~w~..");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<40 || Gas[vehid]>=30)
    {
        
format(stringsizeof(string), "~y~...~w~...");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<30 || Gas[vehid]>=20)
    {
        
format(stringsizeof(string), "~r~..~w~....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<20 || Gas[vehid]>=1)
    {
        
format(stringsizeof(string), "~r~.~w~.....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<=0)
    {
        
format(stringsizeof(string), "~r~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }




Re: TextDraw is duplicated unnecessarily - mikianto - 18.08.2016

Quote:
Originally Posted by Tass007
Посмотреть сообщение
This is untested but this may help.
PHP код:
if(GPLon[vehid]==1)
{
    if(
Gas[vehid]<=100 || Gas[vehid]>=70)
    {
        
format(stringsizeof(string), "~g~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
        
PlayerTextDrawFont(playeridSpeedometerText[playerid][3], 1);
    }
    else if(
Gas[vehid]<70 || Gas[vehid]>=50)
    {
        
format(stringsizeof(string), "~g~.....~w~.");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<50 || Gas[vehid]>=40)
    {
        
format(stringsizeof(string), "~g~....~w~..");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<40 || Gas[vehid]>=30)
    {
        
format(stringsizeof(string), "~y~...~w~...");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<30 || Gas[vehid]>=20)
    {
        
format(stringsizeof(string), "~r~..~w~....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<20 || Gas[vehid]>=1)
    {
        
format(stringsizeof(string), "~r~.~w~.....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }
    else if(
Gas[vehid]<=0)
    {
        
format(stringsizeof(string), "~r~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
        
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
        
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
        
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
        
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    }

Equal...


Re: TextDraw is duplicated unnecessarily - Tass007 - 18.08.2016

Are you showing this textdraw anywhere else within your script?


Re: TextDraw is duplicated unnecessarily - Vince - 18.08.2016

The whole block of code is essentially unnecessary because the only thing that changes is the amount of colored dots. Textdraw does not need to be reshown or recreated if the text is changed.


Re: TextDraw is duplicated unnecessarily - mikianto - 18.08.2016

Quote:
Originally Posted by Tass007
Посмотреть сообщение
Are you showing this textdraw anywhere else within your script?
Only OnPlayerStateChange


Re: TextDraw is duplicated unnecessarily - mikianto - 18.08.2016

Quote:
Originally Posted by Vince
Посмотреть сообщение
The whole block of code is essentially unnecessary because the only thing that changes is the amount of colored dots. Textdraw does not need to be reshown or recreated if the text is changed.
It has to change color according to the quantity of the gas


Re: TextDraw is duplicated unnecessarily - Tass007 - 18.08.2016

I'd say. Don't constantly show the textdraw, just set the string.
PHP код:
if(GPLon[vehid]==1)
{
    if(
Gas[vehid]<=100 || Gas[vehid]>=70)
    {
        
format(stringsizeof(string), "~g~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<70 || Gas[vehid]>=50)
    {
        
format(stringsizeof(string), "~g~.....~w~.");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<50 || Gas[vehid]>=40)
    {
        
format(stringsizeof(string), "~g~....~w~..");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<40 || Gas[vehid]>=30)
    {
        
format(stringsizeof(string), "~y~...~w~...");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<30 || Gas[vehid]>=20)
    {
        
format(stringsizeof(string), "~r~..~w~....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<20 || Gas[vehid]>=1)
    {
        
format(stringsizeof(string), "~r~.~w~.....");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    else if(
Gas[vehid]<=0)
    {
        
format(stringsizeof(string), "~r~......");
        
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    }
    
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
    
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
    
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
    
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);
    
PlayerTextDrawFont(playeridSpeedometerText[playerid][3], 1);
}
else
{
    
format(stringsizeof(string), "......");
    
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],string);
    
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
    
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
    
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
    
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);




Re: TextDraw is duplicated unnecessarily - Vince - 18.08.2016

Quote:
Originally Posted by mikianto
Посмотреть сообщение
It has to change color according to the quantity of the gas
Color codes don't count. They're still part of the text.

Quote:
Originally Posted by Tass007
Посмотреть сообщение
I'd say. Don't constantly show the textdraw, just set the string.
PHP код:
// ... 
That's still a lot more code than needed because the entire thing can essentially be compressed to this:

PHP код:
new gasText[16] = "......";
if(
GPLon[vehid]==1)
{
    switch(
Gas[vehid])
    {
        case 
0:            gasText "~r~......";
        case 
1..19:        gasText "~r~.~w~.....";
        case 
20..29:    gasText "~r~..~w~....";
        case 
30..39:    gasText "~y~...~w~...";
        case 
40..49:    gasText "~g~....~w~..";
        case 
50..69:    gasText "~g~.....~w~.";
        case 
70..100:    gasText "~g~......";
        default:        
gasText "Malfunction";
    }
}
PlayerTextDrawSetString(playerid,SpeedometerText[playerid][3],gasText);
PlayerTextDrawTextSize(playerid,SpeedometerText[playerid][3], 522+(iValue*89/200), 0);
PlayerTextDrawShow(playerid,SpeedometerText[playerid][3]);
PlayerTextDrawUseBox(playerid,SpeedometerText[playerid][3], 1);
PlayerTextDrawBoxColor(playerid,SpeedometerText[playerid][3], 0xFFFFFF00);