SA-MP Forums Archive
Vehicle Velocity to Kilometers Per Hour - 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: Vehicle Velocity to Kilometers Per Hour (/showthread.php?tid=204914)



Vehicle Velocity to Kilometers Per Hour - [NWA]Hannes - 30.12.2010

How to convert vehicle velocity to KPH? (kilometers per hour)

I know you gotta divide and floatround but whats the numbers?


Re: Vehicle Velocity to Kilometers Per Hour - jameskmonger - 30.12.2010

I remember seeing someone who did it and then explained how to convert to MPH, I'll try and dig it up for you.


Re: Vehicle Velocity to Kilometers Per Hour - Kaylux - 30.12.2010

pawn Код:
if (strcmp(cmd, "/speed", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new giveplayerid;
            tmp = strtok(cmdtext, idx);
            new string[256];
            new Float:pos[4],Float:speed[2], final[2]; //Where [0] == MPH and [1] == KPH
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "[ERROR]USAGE: /speed [playerid/PartOfName]");
                return 1;
            }
            //giveplayerid = strval(tmp);
            giveplayerid = ReturnUser(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    if(IsPlayerInAnyVehicle(giveplayerid))GetVehicleVelocity(GetPlayerVehicleID(giveplayerid),pos[1],pos[2],pos[3]);
                    else GetPlayerVelocity(giveplayerid,pos[1],pos[2],pos[3]);
                    speed[0] = floatmul(floatsqroot(floatpower(pos[1],2)+floatpower(pos[2],2)+floatpower([pos[3],2)),125); //MPH
                    speed[1] = floatmul(floatsqroot(floatpower(pos[1],2)+floatpower(pos[2],2)+floatpower(pos[3],2)),200); //KPH
                    final[0] = floatround(speed[0]);
                    final[1] = floatround(speed[1]);
                    format(string, sizeof(string), " AdmCmd: %s has a speed of %d MPH and %d KPH", GetPlayerNameEx(giveplayerid), final[0], final[1]);
                    SendClientMessage(playerid, COLOR_YELLOW, string);

                }
                else SendClientMessage(playerid, COLOR_WHITE, "[ERROR]No Such Player");
            }
            else SendClientMessage(playerid, COLOR_WHITE, "[ERROR]Player Not Connected");
        }
        return 1;
    }
Thats how I would do it. Shows MPH and KPH.

So:
pawn Код:
floatmul(floatsqroot(floatpower( Pos X ,2) + floatpower( Pos Y ,2) + floatpower(Pos Z ,2)), 200);



Re: Vehicle Velocity to Kilometers Per Hour - jameskmonger - 30.12.2010

pawn Код:
new Float:x,Float:y,Float:z;
GetVehicleVelocity(vehicleid,x,y,z);
YourSpeedInkmph=floatsqroot((x*x)+(y*y)+(z*z))*198;
YourSpeedInMPH=YourSpeedInkmph*0.621371192;



Re: Vehicle Velocity to Kilometers Per Hour - jameskmonger - 30.12.2010

pawn Код:
new Float:x,Float:y,Float:z;
GetVehicleVelocity(vehicleid,x,y,z);
YourSpeedInkmph=floatsqroot((x*x)+(y*y)+(z*z))*198;
YourSpeedInMPH=YourSpeedInkmph*0.621371192;



Re: Vehicle Velocity to Kilometers Per Hour - [NWA]Hannes - 30.12.2010

So should i multiply with 200 or 198?


Re: Vehicle Velocity to Kilometers Per Hour - Kaylux - 30.12.2010

I use 200 and it's pretty accurate. No way of telling which way is best anyway. They wont be too far off.


Re: Vehicle Velocity to Kilometers Per Hour - jameskmonger - 30.12.2010

198.


Re: Vehicle Velocity to Kilometers Per Hour - pmk1 - 30.12.2010

go see my tutorial, i use 250 for kmph and 199 for mph