Speed in KMPH - 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: Speed in KMPH (
/showthread.php?tid=393442)
Speed in KMPH -
Virus. - 18.11.2012
Hello guys.
Код:
GetVehicleVelocity(GetPlayerVehicleID(x),X,Y,Z);
new Float:temp=floatsqroot((((X ^ 2) + (Y ^ 2) + (Z ^ 2)) * 100) * 1.6);
new kmph[80];
format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
TextDrawSetString(speed[x], kmph);
I am not getting the speed in KMPH. It shows a very big number even when the vehicle is not moving.
Re: Speed in KMPH -
Vince - 18.11.2012
The circumflex character (^) isn't the power operator in Pawn, it is the bitwise XOR operator. The right formula is:
pawn Код:
floatsqroot(((x * x) + (y * y) + (z * z)) * 195.12)
Re: Speed in KMPH -
Virus. - 18.11.2012
tht gives 0 KMPH when the vehicle is not moving and when it starts moving it gives a very big number. Is
floatsqroot required infront of it??
Re: Speed in KMPH -
Vince - 18.11.2012
Yes. Sorry, forgot.
Re: Speed in KMPH -
Virus. - 18.11.2012
I get this speed.
Re: Speed in KMPH -
Vince - 18.11.2012
Usually happens when you try to print a float as an integer.
Re: Speed in KMPH -
2KY - 18.11.2012
Quote:
Originally Posted by Vince
Usually happens when you try to print a float as an integer.
|
I had the same 'issue' when I was creating my own. Use floatround to round up/down and then display it as an integer.
Re: Speed in KMPH -
Konstantinos - 18.11.2012
Quote:
Originally Posted by Vince
Usually happens when you try to print a float as an integer.
|
Do you mean, that it should be printed as a float, because he's using it as an integer.
pawn Код:
format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
Re: Speed in KMPH -
2KY - 18.11.2012
Quote:
Originally Posted by Dwane
Do you mean, that it should be printed as a float, because he's using it as an integer.
pawn Код:
format(kmph,sizeof(kmph),"Speed : %i KMP/H",temp);
|
He means that either you have to:
A) Display it as a float (horrible idea for speed-o-meters)
B) Use floatround, and get it into integer form and THEN display it
Re: Speed in KMPH -
Konstantinos - 18.11.2012
It can be done as a float without the rest after the dot '.'
If it's 12.45676, it'll display 12!