Vehicle Velocity to Kilometers Per Hour
#1

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

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

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

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);
Reply
#4

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

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

So should i multiply with 200 or 198?
Reply
#7

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

198.
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)