SA-MP Forums Archive
GetVehicleVelocity... - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetVehicleVelocity... (/showthread.php?tid=95420)



GetVehicleVelocity... - AiVAMAN - 03.09.2009

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?


Re: GetVehicleVelocity... - BlackFoX - 03.09.2009

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


Re: GetVehicleVelocity... - kc - 03.09.2009

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.


Re: GetVehicleVelocity... - AiVAMAN - 03.09.2009

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?


Re: GetVehicleVelocity... - BlackFoX - 03.09.2009

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



Re: GetVehicleVelocity... - AiVAMAN - 03.09.2009

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?




Re: GetVehicleVelocity... - [other]FreeWall - 03.09.2009

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