SpeedoMeter Simple Bug!
#1

Hello everyone

pawn Код:
forward UpdateSpeed();
public UpdateSpeed()
{
    new Float:vh;
    new S_string[256];
    new Float:Sp_x, Float:Sp_y, Float:Sp_z;
    new Float:kmh_speed, kmh_speed_int;
    new bool:HasSpeedo[MAX_PLAYERS];
   
    for(new i=0; i<MAX_PLAYERS; i++)
    {
    new vehicleid; vehicleid = GetPlayerVehicleID(i);
        if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && Dash[i] == 1) //Dash = enable/disable Speedometer
        {
            if(HasSpeedo[i])
            {
                GetVehicleHealth(vehicleid, vh);
                GetVehicleVelocity(vehicleid,Sp_x,Sp_y,Sp_z);
                kmh_speed = floatsqroot(((Sp_x*Sp_x)+(Sp_y*Sp_y))+(Sp_z*Sp_z))*136.666667;
                kmh_speed_int = floatround(kmh_speed,floatround_round);
            format(S_string,256,"~g~Vehicle : ~w~%s ~n~ ~b~KM/H : ~w~%d ~n~~r~Vehicle Health:~w~ %.2f",CarName[GetVehicleModel(GetPlayerVehicleID(i))-400],kmh_speed_int,vh);
                TextDrawHideForPlayer(i, Speedo[i]);
                TextDrawSetString(Speedo[i], S_string);
                TextDrawShowForPlayer(i, Speedo[i]);
            }
            else
            {
                GetVehicleHealth(vehicleid, vh);
                GetVehicleVelocity(vehicleid,Sp_x,Sp_y,Sp_z);
                kmh_speed = floatsqroot(((Sp_x*Sp_x)+(Sp_y*Sp_y))+(Sp_z*Sp_z))*136.666667;
                kmh_speed_int = floatround(kmh_speed,floatround_round);
                format(S_string,256,"~g~Vehicle : ~w~%s ~n~ ~b~KM/H : ~w~%d ~n~~r~Vehicle Health:~w~ %.2f",CarName[GetVehicleModel(GetPlayerVehicleID(i))-400],kmh_speed_int,vh);
                Speedo[i] = TextDrawCreate(320.00, 370.00, S_string);
                TextDrawSetOutline(Speedo[i], 1);
                TextDrawFont(Speedo[i], 1);
                TextDrawSetProportional(Speedo[i], 2);
                TextDrawAlignment(Speedo[i], 2);
                TextDrawSetShadow(Speedo[i],1);
                TextDrawShowForPlayer(i, Speedo[i]);
                HasSpeedo[i] = true;
            }
        }
    }
}
and a Timer OnGameModeInit for UpdateSpeed
BUT: when I take a car the speedometer show but when the timer will SetString it creat another TextDraw on the Old
and there is many TextDraws
HOW can I do for it show one TextDraw and it SetString without another one
AND if I exit car TextDraw will hidden !

Sorry for my bad English
I hope I'll find someone to solve it
Thanks as begin =)
Reply
#2

Your creating two textdraws, Remove one and use TextDrawSetString
Reply
#3

Not two, there is a function if the textdraw was created, it just setstring and show it, if not it create the textdraw and show it
Reply
#4

Please !
Reply
#5

Up Up
Reply
#6

Make the textdraw global, then Use TextdrawSetString, you ARE Creating it a Second time when you update the string with a formatted text like your doing.
Reply
#7

Can you give it to me!
Reply
#8

hmm, onplayerentervehicle put textdrawshowforplayer(playerid, Speedo[i]); with has speedo etc. Btw, why making it with a loop, use SetTimerEx("UpdateSpeed", time, true, "d", playerid); it creates one time for the playerid, put it under onplayerentervehicle and destroy it under onplayerexitvehicle...

UpdateSpeed() will become UpdateSpeed(playerid)

Remove the TextDrawHideForPlayer and ShowForPlayer and just change the textdrawsetstring each time.
Reply
#9

Yes it works, But it creats many textdraws ?
Is any way to SetTimer once ? just once
Reply
#10

I have maked this:
pawn Код:
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid)
{
            KillTimer(UTimer[playerid]); //Utimer = UpdateSpeed timer
            STimer[playerid] = SetTimerEx("SpeedoSetString", 250, true, "i", playerid);
           
    //}
}
pawn Код:
stock SpeedoSetString(playerid)
{
                //SpeedoMeter getplayerping, velocity .. again, and not creat textdraw just for SetString
        TextDrawSetString(Speedo[playerid], S_string);
        return TextDrawShowForPlayer(playerid, Speedo[playerid]);
    //}
}
But textdraw show until take a car and freeze without it set the string
ExitCar = destroycar / kill STimer ~
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)