Vehicle speed
#1

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...
Reply
#2

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
Reply
#3

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..
Reply
#4

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.
Reply
#5

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.
Reply
#6

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;
}
Reply
#7

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;
}
Reply
#8

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)