TextDraw is duplicated unnecessarily
#1

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);
}

Reply
#2

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);
    }

Reply
#3

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...
Reply
#4

Are you showing this textdraw anywhere else within your script?
Reply
#5

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.
Reply
#6

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

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
Reply
#8

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);

Reply
#9

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); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)