SA-MP Forums Archive
Speedo not updating - 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: Speedo not updating (/showthread.php?tid=338094)



Speedo not updating +rep - Dripac - 28.04.2012

pawn Код:
stock SetSpeed(playerid)
{
for(new b = 0;b<currentid +1;b++)
{
new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(playerid),SpeedCameras[b][_usemph]));
new string[140];
if(speed < 100)
{
format(string, sizeof(string), "Speed: ~g~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 100)
{
format(string, sizeof(string), "Speed: ~y~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
if(speed > 119)
{
format(string, sizeof(string), "Speed: ~r~%d KM/h", speed);
TextDrawSetString(Speedo0[playerid],string);
}
}
}
pawn Код:
Speedo0[i] = TextDrawCreate(496.000000,336.000000,"Speed: ~g~0 KM/h");
The textdraw is showing, but it always says "Speed: 0 KM/h"


Re: Speedo not updating - The DeLuca - 28.04.2012

Make sure it updates OnPlayerUpdate or on a repeating timer every second.


Re: Speedo not updating - Dripac - 28.04.2012

Quote:
Originally Posted by The DeLuca
Посмотреть сообщение
Make sure it updates OnPlayerUpdate or on a repeating timer every second.
I have it at a timer which updates every 1 second

SetSpeed(i);


Re: Speedo not updating - The DeLuca - 28.04.2012

Make SetSpeed a public callback and forward it. See if that works for ya.


Re: Speedo not updating - Dripac - 28.04.2012

But what will be the difference =/

I also have a same thing with SetHealth (vehicle health), and it updates


Re: Speedo not updating - Jonny5 - 28.04.2012

you have not defined currentid

not sure if this is a global or not, only error i spotted.


i dont know this code well but seams more logical to me to have it something like
pawn Код:
stock SetSpeed(playerid)
{
    for(new b = 0,currentid=sizeof(SpeedCameras);b<currentid;b++)
    {
        new speed = floatround(GetVehicleSpeed(GetPlayerVehicleID(playerid),SpeedCameras[b][_usemph]));
        new string[140];
        if(speed < 100)
        {
            format(string, sizeof(string), "Speed: ~g~%d KM/h", speed);
            TextDrawSetString(Speedo0[playerid],string);
        }
        if(speed > 100)
        {
            format(string, sizeof(string), "Speed: ~y~%d KM/h", speed);
            TextDrawSetString(Speedo0[playerid],string);
        }
        if(speed > 119)
        {
            format(string, sizeof(string), "Speed: ~r~%d KM/h", speed);
            TextDrawSetString(Speedo0[playerid],string);
        }
    }
}



Re: Speedo not updating - Dripac - 28.04.2012

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
you have not defined currentid

not sure if this is a global or not, only error i spotted.
If i wouldn't have defined it, i would get errors at compiling...

// EDIT, lol your code works, but i get one warning

warning 219: local variable "currentid" shadows a variable at a preceding level

What should i change?


Re: Speedo not updating - Jonny5 - 28.04.2012

not always true!!!

btw are you using SetTimerEx or SetTimer?
also for it to find your SetSpeed it MUST be public and forward.
this is the ONLY way to use the function with a timer.

edit:

pawn Код:
for(new b = 0,cid=sizeof(SpeedCameras);b<cid;b++)
i made it cid..

regards,


Re: Speedo not updating - Dripac - 28.04.2012

It works now, thank you.

+rep