Speedometer formula for OnPlayerUpdate
#1

Hello, i need a new OnPlayerUpdate speedometer formula. Because the one i have is pretty buggy. When you turn for ex. to left your speed grows, when you turn to right - the speed drops.
Here is my formula:
Код:
GetSpeed(id) {
 new Float:s[4];
 GetVehicleVelocity(GetPlayerVehicleID(id),s[0],s[1],s[2]);
 return floatround(1.61*floatsqroot(floatabs(floatpower(s[0]+s[1]+s[2],2)))*100); }
I also use this on cops speedometer( to catch people with speed over 90 ).

Maybe some one could share the formula?
Reply
#2

Код:
GetSpeed(vehicleid) {
	  new Float:vehsX, Float:vehsY, Float:vehsZ;
	  GetVehicleVelocity(vehicleid, vehsX, vehsY, vehsZ);
	  return floatsqroot(vehsX*vehsX + vehsY*vehsY + vehsZ*vehsZ)*200;}
Reply
#3

I have a tag mismatch on this line. return floatsqroot(vehsX*vehsX + vehsY*vehsY + vehsZ*vehsZ)*200;
But, i tried it out and it shows numbers like 111423452345345 Help pls
Код:
GetSpeed(id) {
	  new Float:vehsX, Float:vehsY, Float:vehsZ;
	  GetVehicleVelocity(GetPlayerVehicleID(id), vehsX, vehsY, vehsZ);
	  return floatsqroot(vehsX*vehsX + vehsY*vehsY + vehsZ*vehsZ)*200;}
Reply
#4

Use what I'm using ^^
pawn Код:
stock GetPlayerSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 100.3;
    return floatround(ST[3]);
}
Reply
#5

FYI - it is more accurate to use a repeating timer, say every 800ms, to calculate a players speed then it is to do distance/speed calculations in OnPlayerUpdate. Just a tip .
Reply
#6

Thanks for a tip, but i think i will stay with this.
Thanks - [XST]O_x ! It works fine.
Reply
#7

Just for the info

To calculate the speed you have to use the following formula:
√((x ^ 2) + (y ^ 2) + (z ^ 2))

Then just multiply with a value to become the correct results.
Reply
#8

Sorry for the bump, I just wanted to say thanks to O_x. It is the only function I found that works. /credits for you.
Reply
#9

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Sorry for the bump, I just wanted to say thanks to O_x. It is the only function I found that works. /credits for you.
Good to hear this,though I may not take any credits for that formula as I haven't made it,I found it somewhere and since then I saved it on my PC.
I just give it to people that needs it,and thanking to whoever made it
Reply
#10

Yeah, cool. To get the right speed make it: GetPlayerSpeed(playerid)*2.7570093
I checked the speed of Cheetah (107 at yours). Real Testarossa drives ~295km/h => 295/107 = 2.7570093.
So you can get the real speed. I use it for anti-speed-hax.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)