GetVehicleVelocity...
#1

Hello, I have decided to make an Speedometer for 0.3 and I got 1 problem...
Speedo only shows 1 KM\H when I enter a car.

Here is my code:
pawn Код:
public OnPlayerUpdate(playerid)
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      if(IsPlayerInAnyVehicle(i))
      {
        new Float:Velocity[3], output[20];
        format(output, sizeof(output), "~r~%i ~w~KM/H", GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[1], Velocity[2]));
        TextDrawSetString(Text:KMH[i], output);
        TextDrawShowForPlayer(i, Text:KMH[i]);
      }
      else
      {
        TextDrawHideForPlayer(i, Text:KMH[i]);
      }
    }
  }
  return 1;
}
What I am doing wrong?
Reply
#2

Function GetVehicleVelocity returns only true no value , and that Speedo doesnt Work cause
you must convert Float Values with floatpower, Floatsin ,Floatcos etc.
Reply
#3

Quote:
Originally Posted by -Alive
What I am doing wrong?
Almost everything.

Only use OnPlayerUpdate if you have any clue what it does and how to use it.

GetVehicleVelocity doesn't return the speed, it returns whether the calling was successful or not. Hence why you are always getting 1.
You have to process the x y and z outputs of GetVehicleVelocity to work out the speed.
Reply
#4

I have did the formula that BlackFox mean..

floatsqroot(floatadd(floatadd(floatpower(floatsub( X, OldX[i]), 2), floatpower(floatsub(Y, OldY[i]), 2)), floatpower(floatsub(Z, OldZ[i]), 2)))

How do I use GetVehicleVelocity with this?
Reply
#5

Код:
new Float:x,Float:y,Float:z;
GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);
Reply
#6

pawn Код:
new Float:x,Float:y,Float:z;
GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z) = floatsqroot(floatadd(floatadd(floatpower(floatsub(X, OldX), 2), floatpower(floatsub(Y, OldY), 2)), floatpower(floatsub(Z, OldZ), 2)))
something like this?

Reply
#7

http://forum.sa-mp.com/index.php?topic=120115.0
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)