Realistic Fuel Consumption
#6

Alright, this is how I update my vehicles fuel: (It's inside a timer).

Obviously it's just a little piece, but you'll know how to implement it in your code.

pawn Код:
new Float:consumption, Float:distance;
if((X != lastX) || (Y != lastY)|| (Z != lastZ))  //Check if player has moved
{
   distance = floatround(floatsqroot(floatpower(floatabs(floatsub(X,lastX)),2)+floatpower(floatabs(floatsub(Y,lastY)),2)+floatpower(floatabs(floatsub(Z,lastZ)),2)));
    distance = distance / 50;
    consumption = floatdiv(distance, VehicleInfo[vehicleID][FuelConsumption]);  //devide the distance with its distance/liter
    VehicleInfo[vehicleID][Fuel] = floatsub(VehicleInfo[vehicleID][Fuel], consumption);
    LastX = X;
    LastY = Y;
    LastZ = Z;
}
Edit: My fuelsystem is based on the Metric System (kilometers/liters). I don't know if it works right for Miles/gallon
Reply


Messages In This Thread
Realistic Fuel Consumption - by Luis- - 11.12.2014, 15:44
Re: Realistic Fuel Consumption - by Schneider - 11.12.2014, 15:54
Re: Realistic Fuel Consumption - by Luis- - 11.12.2014, 15:58
Re: Realistic Fuel Consumption - by Clad - 11.12.2014, 16:05
Re: Realistic Fuel Consumption - by Luis- - 11.12.2014, 16:07
Re: Realistic Fuel Consumption - by Schneider - 11.12.2014, 16:11
Re: Realistic Fuel Consumption - by Clad - 11.12.2014, 16:12
Re: Realistic Fuel Consumption - by Luis- - 11.12.2014, 16:25
Re: Realistic Fuel Consumption - by Schneider - 11.12.2014, 16:30
Re: Realistic Fuel Consumption - by Luis- - 11.12.2014, 16:32

Forum Jump:


Users browsing this thread: 1 Guest(s)