Kolmain 6 Posted March 6, 2011 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
shay_gman 272 Posted March 6, 2011 (edited) 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 March 6, 2011 by shay_gman Share this post Link to post Share on other sites
Kolmain 6 Posted March 6, 2011 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
shay_gman 272 Posted March 6, 2011 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
Kolmain 6 Posted March 6, 2011 Awesome, thanks mate! Share this post Link to post Share on other sites
HitmanFF 6 Posted March 7, 2011 { 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
shay_gman 272 Posted March 7, 2011 HitmanFF got it right :) Share this post Link to post Share on other sites
dwringer 45 Posted March 8, 2011 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