Vehicle speed - 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: Vehicle speed (
/showthread.php?tid=311053)
Vehicle speed -
Scenario - 14.01.2012
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...
Re: Vehicle speed -
Jakku - 14.01.2012
Is this efficient enough?
pawn Код:
GetVehicleSpeed(vehicleid)
{
new Float:Vx, Float:Vy, Float:Vz;
GetVehicleVelocity(vehicleid, Vx, Vy, Vz);
new Float:rtn;
rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));
rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));
return floatround(rtn);
}
EDIT: Awesome avatar
Re: Vehicle speed -
Laronic - 14.01.2012
I use this and it works great
pawn Код:
stock GetVehicleSpeed(vehicleid)
{
new Float:xPos[3]:
GetVehicleVelocity(vehicleid, xPos[0], xPos[1], xPos[2]);
return floatround(floatsqroot(xPos[0] * xPos[0] + xPos[1] * xPos[1] + xPos[2] * xPos[2]) * 170.00);
}
Edit: Saw your last post, this just reutrn the KMH though..
Re: Vehicle speed -
Steven82 - 14.01.2012
Quote:
Originally Posted by RealCop228
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...
|
I was also looking for a very efficient one too. I know that there is the GetVehicleSpeed functions(posted above) but they are not that accurate for my servers for some reason.
Re: Vehicle speed -
Scenario - 14.01.2012
Quote:
Originally Posted by Jakku
Is this efficient enough?
pawn Код:
GetVehicleSpeed(vehicleid) { new Float:Vx, Float:Vy, Float:Vz; GetVehicleVelocity(vehicleid, Vx, Vy, Vz); new Float:rtn; rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2)); rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2)); return floatround(rtn); }
|
Not really sure how to tell. Although, I need a function which can allow me to retrieve it in MPH and KPH.
Re: Vehicle speed -
iTorran - 14.01.2012
pawn Код:
// Taken from gLibrary - Gamer93
stock Float:GetVehicleSpeed(vehicleid,UseMPH = 0)
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:temp_speed;
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
if(UseMPH == 0)
{
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
} else {
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*85.4166672;
}
floatround(temp_speed,floatround_round);return temp_speed;
}
Re: Vehicle speed -
Virtual1ty - 14.01.2012
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;
}
Re: Vehicle speed -
Scenario - 14.01.2012
Thanks guys.