I must admit, this has been asked and requested many times and I was too lazy to publish something about it… But, today, I’m in holiday and have some free time to do it…
The concept is pretty simple, it increases the fuel uptake taking into account the speed of the player vehicle.
This script is release as it is, you may need to do some adjustments :)
Used values are defined in an array named tm4_prom_spotrebaPaliva that you can define inside the script or anywhere during your initialization (e.g. init.sqf, initPlayerLocal.sqf). If you define tm4_prom_spotrebaPaliva before starting this script, your settings will be used and the default one ignored.
Note that trucks, vans and helicopters are concerned by the base value (index 0) only because the default fuel uptake from the game is superior than a SUV for example.
So, hereafter, we define the consumption. The first index is the base and will be applied on every vehicle (whatever its kind) with 5 ticks per seconds and used when the speed is inferior to 10 KM h. Then, seconde is for a speed between 10 Km h and 90 Km h, the next (index 2) is for a speed between 91 Km h and 130 Km h and the last (index 3) will be used for a speed superior to 130 Km h.
1 2 3 4 5 6 |
tm4_prom_spotrebaPaliva = [ [] call {(0.00066314157*1.00619)}, [] call {((0.0016314157+0.00014159)/(pi*2))}, [] call {((0.0026314157+0.00025159)/(pi*2))}, [] call {((0.0036314157+0.00026159)/(pi*2))} ]; |
Let’s take cases, a truck and a SUV:
- SUV:
- When:
isEngineOn AND speed < 10
Consumption per second: Default + ((0.00066314157 * 1.00619) * 5) - When:
isEngineOn AND speed > 130
Consumption per second: Default + ((0.00066314157 * 1.00619) * 5) + ((0.0036314157 + 0.00026159)/(pi*2) * 5)
- When:
isEngineOn AND speed < 10
- Truck
- When:
isEngineOn AND speed < 10
Consumption per second: Default + ((0.00066314157 * 1.00619) * 5) - When:
isEngineOn AND speed > 130
Consumption per second: Default + ((0.00066314157 * 1.00619) * 5)
- When:
isEngineOn AND speed < 10
As you can see, the increase for a truck is smaller than for a SUV because we don’t cancel and replace the default, we just add to it and the base consumption of truck is already greater.
There you go then, the script itself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
scriptName "tm4_fuelUptake"; /*-------------------------------------------------------------------- file: tm4_fuelUptake.sqf ======================== Author: Tom_48_97 <@Tom_48_97> Description: This script increases the fuel consumption of the player's vehicle. It just needs to be exec on client side --------------------------------------------------------------------*/ #define __filename "tm4_fuelUptake.sqf" if (isServer and isDedicated) exitWith {}; waitUntil {!isNull player && player == player}; if (isNil "tm4_handler_fuelUptake") then { tm4_handler_fuelUptake = [] spawn { if (isNil "tm4_prom_spotrebaPaliva") then { tm4_prom_spotrebaPaliva = [[] call {(0.00066314157*1.00619)}, [] call {((0.0016314157+0.00014159)/(pi*2))}, [] call {((0.0026314157+0.00025159)/(pi*2))}, [] call {((0.0036314157+0.00026159)/(pi*2))} ]; }; while {alive player} do { diag_log ["LOG:", __filename, diag_tickTime, "THREAD STARTED"]; waitUntil { sleep 1; alive player }; while {alive player} do { waitUntil {vehicle player != player && player == driver vehicle player }; _vh = vehicle player; while {vehicle player != player && player == driver (vehicle player) && alive player} do { waitUntil {isEngineOn _vh}; diag_log ["LOG:", __filename, "isEngineOn vehicle player == TRUE"]; while {isEngineOn _vh && alive player} do { if !(driver _vh == player || alive player || alive _vh) exitWith {}; _vh setFuel ((fuel _vh) - (tm4_prom_spotrebaPaliva select 0)); if !(_vh isKindOf "Truck_F" || _vh isKindOf "Van_01_base_F" || _vh isKindOf "Helicopter_Base_H") Then { if (speed _vh > 10 && speed _vh < 91) then { _vh setFuel ((fuel _vh) - (tm4_prom_spotrebaPaliva select 1)); }; if (speed _vh > 90 && speed _vh < 130) then { _vh setFuel ((fuel _vh) - (tm4_prom_spotrebaPaliva select 2)); }; if (speed _vh > 130) then { _vh setFuel ((fuel _vh) - (tm4_prom_spotrebaPaliva select 3)); }; sleep .20; }; if !(driver _vh == player || alive player || alive _vh || isEngineOn _vh) exitWith {}; sleep 1; }; diag_log ["LOG:", __filename, "isEngineOn vehicle player == FALSE || driver vehicle player == player || isEngineOn vehicle player"]; sleep .5; }; sleep 1; diag_log ["LOG:", __filename, "vehicle player != player || player == driver (vehicle player) || alive player"]; /*terminate tm4_handler_fuelUptake; */ }; diag_log ["LOG:", __filename, "terminated"]; }; diag_log ["LOG:", __filename, "exited"]; /*terminate tm4_handler_fuelUptake; */ }; } else { diag_log ["LOG:", __filename, diag_tickTime,"THREAD ALREADY EXISTS"]; }; |
You can simply add the script where you want it and execute it or its content in another script, for example the one you use to init the player. Personally, I recommend to execute it from initPlayerLocal.sqf which is the most suitable place for such script.
If you have any questions, feel free to post a comment in English or French ;)
# You’re not allowed to use this for the contest Make Arma Not War without telling me ;)
Merci beaucoup pour ton scrit !!
à t’on le droit de l’édité? En gardant t’es crédits bien sûre!
J’avais oublié la licence:
[X] Attribution – You must attribute the material in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the material).
[X] Noncommercial – You may not use this material for any commercial purposes.
[X] Arma Only – You may not convert or adapt this material to be used in other games than Arma.
[X] Share Alike – If you adapt, or build upon this material, you may distribute the resulting material only under the same license.
Hey,
first off all great script =) i like it a lot, but i got a little problem. sometimes its working and the gas is going down to 0 in like 10mins or something and sometimes it doesn’t.
I use it on my altis life server and people enjoy it too (most of the time)…
i call it this way:
[] execVM “scripts\tm4_fuelUptake.sqf”;
is this correct or do i need to change something?
Ahoy,
We agree that you’re calling it from initPlayerLocal.sqf?
Then, be aware that consumption may differs from a vehicle type to another, according to the initial design, you should be able to go to Sofia from Kavala with a speed of +/- 110 Km h, then, your fuel tank should be almost empty (if it’s not the case).
I will have a look at that, but if you’re able to find in which cases (at least, some parameters) it malfunctions, it will be great and faster to fix ;)
Hey… yeah i got this in my initPlayerLocal:
[] execVM “scripts\tm4_fuelUptake.sqf”;
or should i use
call “scripts\tm4_fuelUptake.sqf”;?
Null = [] execVM “scripts\tm4_fuelUptake.sqf”; is correct.
thx buddy, I will try it. keep up the good work ;)
I really coldun’t ask for more from this article.
arma 3
Just what I was looking for.. thanks