SA-MP Forums Archive
Problems in Speedometer Textdraw - 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: Problems in Speedometer Textdraw (/showthread.php?tid=652090)



Problems in Speedometer Textdraw - JaskaranSingh - 02.04.2018

I have created a speedometer and I want that TextDraw to show if a player is driving a vehicle.

Everything works fine until the second player drives another car. I see two TextDraws when the other player drives his car. I have spent hours on this and need urgent help.

Speedometer Function
PHP код:
public Speedometer(playerid)
{
    new 
vehicleidFloat:health;
    new 
enginelightsalarmdoorsbonnetbootobjective;
    new 
fstring[32], string[512], string2[512];
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
        {
            
vehicleid GetPlayerVehicleID(i);
            
GetVehicleHealth(vehicleidhealth);
            
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
            
            
format(fstringsizeof(fstring),"Speed: %d Km/h"GetPlayerSpeed(itrue));
            
strcat(stringfstringsizeof(string));
            
strcat(string"~n~Fuel: "sizeof(string));
            
format(string2sizeof(string2), "%.0f%%"Fuel[vehicleid]);
            
            if(
Fuel[vehicleid] > 100)
                
strins(fstring"~r~"10sizeof(fstring));
            else if(
Fuel[vehicleid] < 0.0)
                
strins(fstring"~r~"0sizeof(fstring));
            else
                
strins(fstring"~r~"floatround(Fuel[vehicleid]/10.0), sizeof(fstring));
            
strcat(stringstring2sizeof(string));
            
            
strcat(string"~n~Status: "sizeof(string));
            if(
doors == 1)
                
strcat(string"~r~Locked"sizeof(string));
            else
                
strcat(string"~g~Unlocked"sizeof(string));
            
            
TextDrawSetString(SpeedoText[i], string);
        }
    }

OnPlayerEnterVehicle Function
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(!
ispassenger)
    {
        
SpeedoText[playerid] = TextDrawCreate(520.0180.0," ");
        
TextDrawAlignment(SpeedoText[playerid], 1);
        
TextDrawFont(SpeedoText[playerid], 1);
        
TextDrawLetterSize(SpeedoText[playerid], 0.2500.900);
        
TextDrawSetShadow(SpeedoText[playerid], 1);
        
TextDrawUseBox(SpeedoText[playerid], 0);
        
TextDrawBoxColor(SpeedoText[playerid], 0x99);
        
TextDrawSetOutline(SpeedoText[playerid], 1);
        
TextDrawTextSize(SpeedoText[playerid], 600.0000.000);
        
TextDrawShowForPlayer(playeridSpeedoText[playerid]);
    }
    
    return 
1;




Re: Problems in Speedometer Textdraw - jasperschellekens - 02.04.2018

Do you destroy/hide the textdraws when the player leaves the vehicle?