Posts: 7,801
Threads: 187
Joined: Feb 2010
Reputation:
0
Does anybody have a really efficient and accurate GetVehicleSpeed function? I have searched around the forums a little, but I can't seem to find any good functions...
EDIT: I need a function to retrieve both MPH and KPH...
Posts: 734
Threads: 8
Joined: Jun 2009
Here's what I use in my GM to get the vehicle speed in both MPH and KPH (please note that I use a player variable which holds that information, so I only use one of the two), and I'd say its enough optimized, and precise for what I use it to.
pawn Код:
#define MPH_KMH 1.609344
stock GetVehicleSpeed( vehicleid )
{
// Function: GetVehicleSpeed( vehicleid )
new
Float:x,
Float:y,
Float:z,
vel;
GetVehicleVelocity( vehicleid, x, y, z );
vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 ); // KM/H
// vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 / MPH_KMH ); // MPH
return vel;
}