Jump to content
Sign in to follow this  
Kolmain

Increased Fuel Loss?

Recommended Posts

I've never had a scenario where we ran out of fuel (apart from damage) and was wondering If I could write a script to run through a mission that if a player is in a vehicle it can increase the rate of fuel loss? I know its been done but cant remember where, anyone have any ideas?

Share this post


Link to post
Share on other sites

Well I would go with something like this in the init file of the mission for SP or as an eventhandler for MP

private ["_vehicle", "_curFuel", "_newFuel"];
while {true} do
{
if (vehicle player != player) then	//If player is inside a vehicle
{
_vehicle = vehicle player; // the name of the vehicle
sleep 60;	//Wait a minute
if (vehicle player == _vehicle ) then    //Check if the player is still inside the vehicle
	{
	_curFuel = fuel _vehicle;  //get the fuel of the vehicle
	_newFuel = _curFuel * 0.01;
	_vehicle setfuel _newFuel;  //decrease the fuel by 1% 
	};
};
sleep 1;	//For FPS preservations
};

Well this script ain't complete as it have some flaws like in MP or when the player leaves the vehicle before the if check or just after, but if you know your way a bit in scripting you can put more then one minure to think on it.

Edited by shay_gman

Share this post


Link to post
Share on other sites

How do you check if the engine is on? and this has to be MP compatible so hm....

EDIT: What if we checked via event handler that the player was driver? the current code woudl decrease it 1% for each player in the vehicle...

Share this post


Link to post
Share on other sites

You can always change it to engine on so it wil work in MP. Just call the script fuelLoss.sqf and in the init line of the vehicle put this

[this] execVM "fuelLoss.sqf";

private ["_vehicle", "_curFuel", "_newFuel"];

_vehicle = _this select 0;

while {true} do
{
if (isEngineOn _vehicle ) then	//If Engine on
  {
  sleep 10;	//Wait 10 seconds
  _curFuel = fuel _vehicle;  //get the fuel of the vehicle
  _newFuel = _curFuel * 0.01;
  _vehicle setfuel _newFuel;  //decrease the fuel by 1% for 10 seconds 
  };
sleep 1;	//For FPS preservations
};

Share this post


Link to post
Share on other sites
  {
  sleep 10;    //Wait 10 seconds
  _curFuel = fuel _vehicle;  //get the fuel of the vehicle
  _newFuel = _curFuel * 0.01;
  _vehicle setfuel _newFuel;  //decrease the fuel by 1% for 10 seconds 
  };

This will instantly set your fuel level to 1%. I expect that the intention was to have
_newFuel = _curFuel * 0.99;

This will leave 99% of the existing fuel (so decrease by 1%).

Share this post


Link to post
Share on other sites

That will unfortunately give your fuel consumption a curvature, which, although I'm sure it's not really supposed to be linear, is also nowhere near the curve you will get with that. Instead perhaps you should set a reference variable for however much 0.01 * fuel _vehicle would be, and iterate while the engine is on until the fuel is empty subtracting that amount from whatever _curFuel is.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×