SA-MP Forums Archive
Realistic Fuel Consumption - 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)
+--- Thread: Realistic Fuel Consumption (/showthread.php?tid=550227)



Realistic Fuel Consumption - Luis- - 11.12.2014

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.


Re: Realistic Fuel Consumption - Schneider - 11.12.2014

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);


Re: Realistic Fuel Consumption - Luis- - 11.12.2014

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.


Re: Realistic Fuel Consumption - Clad - 11.12.2014

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.


Re: Realistic Fuel Consumption - Luis- - 11.12.2014

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?


Re: Realistic Fuel Consumption - Schneider - 11.12.2014

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


Re: Realistic Fuel Consumption - Clad - 11.12.2014

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.


Re: Realistic Fuel Consumption - Luis- - 11.12.2014

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?


Re: Realistic Fuel Consumption - Schneider - 11.12.2014

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]


Re: Realistic Fuel Consumption - Luis- - 11.12.2014

Ah, right! So it's pretty much where the person parked the vehicle?