Realistic Fuel Consumption
I'm revamping my old vehicle system, the fuel system is one of my top priorities to make a lot more realistic, by adding consumption, and capacity for each vehicle type.

How would I go about doing something like this? The maths, formulas or whatever you'd have to use.

Thanks.
I would create an array which holds the consumption (km/liter or mi/gallon) for each vehicletype (e.a. motorbikes, small cars, streetcars, performancecars, trucks, small/large planes, et cetra);
Yeah, I already have that, holding both MPG & Capacity, I'd like to know how I would actually go about making it work, the array is in order of the vehicle ids.
Create a function which will count kilometers or meters the vehicle did pass, After that, You can set the fuel improvement, Let's say if vehicle go more than 50 kilometers NoFuel = 1; I did use something like that in past.
Ah, so for example, the the Landstalkers MPG is 25 & the capacity is 70. When the vehicle goes past 25 kilometers, i'd take 1 away from the fuel variable?
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
Well that's a suggestion but yes it work like that.

Or you can create a timer which will run after the player did pass some time you choose in vehicle and when the timer runs it will take from the vehicle an ammont of fuel.
Quote:
 Originally Posted by Schneider 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
Just a question, how are the x,y,z & lastx, lasty, lastz stored?
The x, y, z are created right in that timer (its used for GetVehiclePos to get the current position) and the lastx, lasty, lastZ are stored in the VehicleInfo-array/enum:
[VehicleInfo][VehicleID][LastX]
Ah, right! So it's pretty much where the person parked the vehicle?

Forum Jump:

Users browsing this thread: 1 Guest(s)