Mileage?
#3

Well, it's pure math actually. You set a timer to get the speed of the car. If you go 60 miles per hour, you go 1 mile per minute.

That basically means if you divide the Km/h with 60, you get per minute. There's 3600 second in an hour, so that means if you divide it by 3600, you get 0,0167 miles per second.

If you want it to be saved in a float, it would be something like this

pawn Код:
new Float:MileageTimer[MAX_PLAYERS];

enum cInfo
{
    Float:cMileage
}
new CarInfo[MAX_VEHICLES][cInfo];


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger)
    {
        MileageTimer[playerid] = SetTimerEx("GetPlayerSpeed", 1000, true, "ii", playerid, vehicleid); // Sets a timer for every second
    }
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    KillTimer(MileageTimer[playerid]);
    return 1;
}

stock GetPlayerSpeed(playerid, vehicleid)
{
    new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,final_speed_int;
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136;
        final_speed_int = floatround(final_speed,floatround_round);
        CarInfo[vehicleid][cMileage] += final_speed_int / 3600; // Saves the mileage every second
    }
    return final_speed_int;
}
This function will both set the mileage of the car, and return the speed, if you wish to use it in a speedometer.
Reply


Messages In This Thread
Mileage? - by MassDivide - 11.05.2013, 11:09
Re: Mileage? - by MassDivide - 11.05.2013, 23:24
Re: Mileage? - by Knappen - 11.05.2013, 23:41
Re: Mileage? - by MassDivide - 12.05.2013, 00:51
Re: Mileage? - by Knappen - 12.05.2013, 01:07
Re: Mileage? - by MassDivide - 12.05.2013, 01:14
Re: Mileage? - by Knappen - 12.05.2013, 01:18
Re: Mileage? - by MassDivide - 12.05.2013, 01:22

Forum Jump:


Users browsing this thread: 1 Guest(s)