SA-MP Forums Archive
SpeedoMeter Simple Bug! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SpeedoMeter Simple Bug! (/showthread.php?tid=223152)



SpeedoMeter Simple Bug! - Yaszine - 08.02.2011

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


Re: SpeedoMeter Simple Bug! - -Rebel Son- - 09.02.2011

Your creating two textdraws, Remove one and use TextDrawSetString


Re : SpeedoMeter Simple Bug! - Yaszine - 09.02.2011

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


Re : SpeedoMeter Simple Bug! - Yaszine - 09.02.2011

Please !


Re : SpeedoMeter Simple Bug! - Yaszine - 10.02.2011

Up Up


Re: SpeedoMeter Simple Bug! - -Rebel Son- - 10.02.2011

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.


Re : SpeedoMeter Simple Bug! - Yaszine - 11.02.2011

Can you give it to me!


Re: SpeedoMeter Simple Bug! - Baboon - 11.02.2011

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.


Re : SpeedoMeter Simple Bug! - Yaszine - 11.02.2011

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


Re : SpeedoMeter Simple Bug! - Yaszine - 11.02.2011

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 ~