Speedo not updating
#1

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"
Reply
#2

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

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

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

But what will be the difference =/

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

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

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

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,
Reply
#9

It works now, thank you.

+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)