Jump to content
Sign in to follow this  
Elite IV

[Tutorial] Fuel Usage

Recommended Posts

initPlayerLocal.sqf - Line 14

[] execVM "scripts\fn_fuelUsage.sqf";

Functions.h - Place

class fuelUsage {};

under Vehicle class.

Create a new file with the code below called "fn_fuelUsage.sqf" and save it in MPMISSIONS/CORE/VEHICLE

	private["_vehicleToFuel","_velocityOfVehicle","_fuelConsumption"];
	while{true} do
{
    _vehicleToFuel = (vehicle player);
    if(isEngineOn _vehicleToFuel && ((driver _vehicleToFuel) == player) && !(_vehicleToFuel isKindOf "Air") && (_vehicleToFuel != player) ) then
    {
        _velocityOfVehicle = sqrt(((velocity _vehicleToFuel select 0)^2)+((velocity _vehicleToFuel select 1)^2))*3.6;
        
        _fuelConsumption = _velocityOfVehicle/100000 + 0.0001;
        if(_fuelConsumption > 0.002) then
        {
            _fuelConsumption = 0.002;
        };
        _vehicleToFuel setFuel ((fuel _vehicleToFuel)-_fuelConsumption);
        
        //hint format["Benzinverbrauch: %1L/km",_fuelConsumption*10000/2];
	        if(fuel _vehicleToFuel < 0.2 && fuel _vehicleToFuel > 0.18) then
        {
            hint "Your gas tank is empty. Hurry to the next gas station!";
        }
        else
        {
            if(fuel _vehicleToFuel < 0.03) then
            {
                hint "I hope you can run - because you just ran out of gas!";
            };
        };
    };
    sleep 2;
};
	
Edited by Elite IV

Share this post


Link to post
Share on other sites

@Elite IV Your using 

[] execVM "scripts\fn_fuelUsage.sqf";

to execute the script but you told us to put nothing in the scripts folder? so i just get scripts/fuelusage.sqf etc not fount 

Share this post


Link to post
Share on other sites
29 minutes ago, Dave650 said:

@Elite IV Your using 

[] execVM "scripts\fn_fuelUsage.sqf";

to execute the script but you told us to put nothing in the scripts folder? so i just get scripts/fuelusage.sqf etc not fount 

Whoops, this is embarrassing. For starters i don't even know how i messed this up so bad.

That big section of code, create a file called "fuelUsage.sqf" and place it in a folder called "scripts" that should be located in the directory of your mission file.

Then place

[] execVM "scripts\fuelUsage.sqf";

in initPlayerLocal.sqf

 

Although you can place it anywhere you want. I think what i was originally trying to do with this script was call or spawn it rather than execVM it. Thats why i messed this up lol

 

Oh yeah if you do follow what i just said, remove the fuelUsage {}; from functions.hpp - Its not needed.

Edited by XtG Community

Share this post


Link to post
Share on other sites

with this default setting how does the gas go, like does it burn fast or slow? and what number do i change to increase/decrease ? thanks

Share this post


Link to post
Share on other sites
22 hours ago, MT519 said:

with this default setting how does the gas go, like does it burn fast or slow? and what number do i change to increase/decrease ? thanks

Look at:

On 1/25/2017 at 3:17 AM, Elite IV said:

_fuelConsumption = _velocityOfVehicle/100000 + 0.0001;         if(_fuelConsumption > 0.002) then         {             _fuelConsumption = 0.002;         };

Test it to see how fast it is.

 

Share this post


Link to post
Share on other sites
player addEventHandler ["GetInMan", {
	params ["_unit", "_role", "_vehicle", "_turret"];
	if (_role isEqualTo "driver") then {
		for "_i" from 0 to 1 step 0 do {
			private _usageMultiplier = 10000;
			if !((driver (vehicle player)) isEqualTo player) exitWith {};
			if (isNull (objectParent player)) exitWith {};
			if !(isEngineOn (vehicle player)) exitWith {};
			
			private _consumption = ((speed (vehicle player)) / _usageMultiplier) max 0.002;
			(vehicle player) setFuel ((fuel (vehicle player)) - _consumption);
			
			if (fuel _vehicleToFuel < 0.2 && fuel _vehicleToFuel > 0.18) then {
            	hint "Your gas tank is empty. Hurry to the next gas station!";
        	} else {
				if (fuel _vehicleToFuel < 0.03) then {
					hint "I hope you can run - because you just ran out of gas!";
				};
			};
			uiSleep 2;
		};
	};
}];

this is what i would use. 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×