WORKING - Siphon Fuel Script

TorturedChunk

Valued Member!
Well, I spent some time with this and built a working siphon fuel script.
One issue I ran into was the jerry can size and refueling under 20 liters of fuel in the vehicle. You could siphon 20 liters of fuel regardless of fuel level. To avoid exploitation, I made it so you cannot siphon a vehicle with 20 liters or less of fuel. If anyone has a way around that, let me know.

This allows you to siphon fuel from any vehicle as long as the vehicle fuel level is above 20 liters and you have an empty jerry can in your inventory.

I also got lazy on the translations for the strings. If you don't want to use strings you can edit the strings in the code to be a static value.

Anyway, on to the CODE!

dayz_code.pbo >> actions >> siphon.sqf
Create This:
Code:
private["_vehicle","_curFuel","_newFuel","_timeLeft","_newFuel"];
_vehicle =cursorTarget;
 
_canSize =getNumber(configFile >> "cfgMagazines" >> "ItemJerrycan" >> "fuelQuantity");
_configVeh =configFile >> "cfgVehicles" >> TypeOf(_vehicle);
_capacity =getNumber(_configVeh >> "fuelCapacity");
_nameType =getText(_configVeh >> "displayName");
_curFuel =((fuel _vehicle) * _capacity);
_newFuel =(_curFuel - _canSize);
 
//if (_newFuel < _capacity * 0) then {_newFuel = 0};
if (_curFuel < _canSize) then {
cutText [format[localize "str_player_siphon_2",_text], "PLAIN DOWN"];
} else {
_newFuel = (_newFuel / _capacity);
 
player removeMagazine "ItemJerrycanEmpty";
player addMagazine "ItemJerrycan";
 
player playActionNow "Medic";
_dis=10;
_sfx = "refuel";
[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
sleep 6;
 
dayzSetFuel = [_vehicle,_newFuel];
dayzSetFuel spawn local_setFuel;
publicVariable "dayzSetFuel";
 
cutText [format[localize "str_player_siphon",_nameType,_canSize], "PLAIN DOWN"];
sleep 1;
 
call fnc_usec_medic_removeActions;
r_action = false;
};


dayz_code.pbo >> compile >> fn_damageActions.sqf

Below This:
Code:
_hasJerry ="ItemJerrycan" in magazines player;
Insert This:
Code:
_hasJerryE =    "ItemJerrycanEmpty" in magazines player;
Below This:
Code:
        //CAN WE REFUEL THE OBJECT?
        if ((fuel _unit < 1) and _hasJerry) then {
            r_action = true;
            _action = _unit addAction [format[localize "str_actions_medical_10",_typeVeh], "\z\addons\dayz_code\actions\refuel.sqf",[_unit], 0, true, true, "", "'ItemJerrycan' in magazines player"];
            r_player_actions set [count r_player_actions,_action];
        };
Insert This:
Code:
        //CAN WE SIPHON THE OBJECT?
        if ((fuel _unit > 0) and _hasJerryE) then {
            r_action = true;
            _action = _unit addAction [format[localize "str_actions_siphon_1",_typeVeh], "\z\addons\dayz_code\actions\siphon.sqf",[_unit], 0, true, true, "", "'ItemJerrycanEmpty' in magazines player"];
            r_player_actions set [count r_player_actions,_action];
        };



dayz_code.pbo >> strinables.xml
Add These:
Code:
        <Key ID="str_actions_siphon_1">
            <Original>Siphon %1</Original>
            <English>Siphon %1</English>
            <German>Siphon %1</German>
            <Russian>Siphon %1</Russian>
            <Spanish>Siphon %1</Spanish>
            <Dutch>Siphon %1</Dutch>
            <French>Siphon %1</French>
            <Czech>Siphon %1</Czech>
        </Key>

Code:
        <Key ID="str_player_siphon">
            <Original>%2 liters of Fuel has been siphoned from %1</Original>
            <English>%2 liters of Fuel has been siphoned from %1</English>
            <German>%2 liters of Fuel has been siphoned from %1</German>
            <Russian>%2 liters of Fuel has been siphoned from %1</Russian>
            <Spanish>%2 liters of Fuel has been siphoned from %1</Spanish>
            <Dutch>%2 liters of Fuel has been siphoned from %1</Dutch>
            <French>%2 liters of Fuel has been siphoned from %1</French>
            <Czech>%2 liters of Fuel has been siphoned from %1</Czech>
        </Key>
Code:
        <Key ID="str_player_siphon_2">
            <Original>You cannot siphon less than 20 liters from a vehicle.</Original>
            <English>You cannot siphon less than 20 liters from a vehicle.</English>
            <German>You cannot siphon less than 20 liters from a vehicle.</German>
            <Russian>You cannot siphon less than 20 liters from a vehicle.</Russian>
            <Spanish>You cannot siphon less than 20 liters from a vehicle.</Spanish>
            <Dutch>You cannot siphon less than 20 liters from a vehicle.</Dutch>
            <French>You cannot siphon less than 20 liters from a vehicle.</French>
            <Czech>You cannot siphon less than 20 liters from a vehicle.</Czech>
        </Key>



If anyone wants to write this up as a "fixes" hook, I'm sure there are plenty of people who would appreciate it.

I will be launching this in DayZ Mercenary 1.4.1 this weekend and have tested it fully on my development server.

Any questions, let me know! :D

ADMIN EDIT: ORIGINAL CONCEPT OF THIS SCRIPT IS LOCATED HERE. The code on the GitHub was posted 2 months ago. This post was posted on March 19. This is a friendly reminder to give everyone credit where it is due.
 
Was gonna sleep. Now gonna play with this. BRB with results! Thanks for the work!

Edit: A few questions on behalf of us noobs:

1) Do we take the siphon.sqf, fn_damaageActions.sqf and the stringtable.xml and add them all to 1 folder (Calling it Siphoning?

2) In the fn_damageActions.sqf this line here: "\z\addons\dayz_code\actions\siphon.sqf" is it supposed to be altered to match the new siphon.sqf location? in this case siphoning\siphon.sqf?

3) How do you want us to call them in the mission's init.sqf and what is to be done with the .xml?

4) Where do we put those additions to the .xml? - I've added them under last key (right above the /package/project lines at the bottom)
 
Sounds like you are using the mission method, and I haven't played with this method too much. I think it would go something like this.

EDIT: Dont forget to put the siphon.sqf in the fixes folder as well.

Create a "fixes" folder in your mission.pbo
Copy dayz_code >> init >> compiles.sqf and dayz_code >> compile >> fn_damageActions.sqf - to your fixes folder in mission.pbo

In your mission.pbo >> init.sqf

Change This:
Code:
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";                //Compile regular functions

To This:
Code:
call compile preprocessFileLineNumbers "fixes\compiles.sqf";                //Compile regular functions

In your mission.pbo >> fixes\complies.sqf
Change This:
Code:
fnc_usec_damageActions =    compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_damageActions.sqf";

To This:
Code:
fnc_usec_damageActions =    compile preprocessFileLineNumbers "fixes\fn_damageActions.sqf";

In fixes\fn_damageActions.sqf

Change This:
Code:
        if ((fuel _unit > 0) and _hasJerryE) then {
            r_action = true;
            _action = _unit addAction [format[localize "str_actions_siphon_1",_typeVeh], "\z\addons\dayz_code\actions\siphon.sqf",[_unit], 0, true, true, "", "'ItemJerrycanEmpty' in magazines player"];
            r_player_actions set [count r_player_actions,_action];
        };

To This:
Code:
        if ((fuel _unit > 0) and _hasJerryE) then {
            r_action = true;
            _action = _unit addAction [format[localize "str_actions_siphon_1",_typeVeh], "fixes\siphon.sqf",[_unit], 0, true, true, "", "'ItemJerrycanEmpty' in magazines player"];
            r_player_actions set [count r_player_actions,_action];
        };



Then make the changes as stated above. As far as the stringables, I think you can hook them like we just did here, but I am not sure. You could just find the strings calls in the code and put a static value.

example: "str_actions_siphon_1" change to "Siphon Fuel"
The only side affect is it wont say "Siphon "vehicle_name"" etc etc.

I bet there is someone here that can help more with the mission hook a whole lot better than I can. :)
 
Anybody got it work using mission method + DayzTaviana2.0 ?
I know there is autorefuel and lotsa gas stations but still nice script! :)

For me I don't get siphon fuel option+ now I can't refuel cars with jerry cans either which seems odd ... gotta take closer look on my code lol
 
It could be the auto refuel causing that issue. Not sure.

Just go back over the inserts from above and make sure nothing is missing.
 
It works as posted by TorturedChunk - nothing more to it.
Just change the "localize" strings to normal format ones:

siphon.sqf

Code:
private["_vehicle","_curFuel","_newFuel","_timeLeft","_newFuel"];
_vehicle =cursorTarget;
 
_canSize =getNumber(configFile >> "cfgMagazines" >> "ItemJerrycan" >> "fuelQuantity");
_configVeh =configFile >> "cfgVehicles" >> TypeOf(_vehicle);
_capacity =getNumber(_configVeh >> "fuelCapacity");
_nameType =getText(_configVeh >> "displayName");
_curFuel =((fuel _vehicle) * _capacity);
_newFuel =(_curFuel - _canSize);
 
//if (_newFuel < _capacity * 0) then {_newFuel = 0};
if (_curFuel < _canSize) then {
cutText [format["You cannot siphon less than 20 liters from a vehicle."], "PLAIN DOWN"];
} else {
_newFuel = (_newFuel / _capacity);
 
player removeMagazine "ItemJerrycanEmpty";
player addMagazine "ItemJerrycan";
 
player playActionNow "Medic";
_dis=10;
_sfx = "refuel";
[player,_sfx,0,false,_dis] call dayz_zombieSpeak;
[player,_dis,true,(getPosATL player)] spawn player_alertZombies;
 
sleep 6;
 
dayzSetFuel = [_vehicle,_newFuel];
dayzSetFuel spawn local_setFuel;
publicVariable "dayzSetFuel";
 
cutText [format["%2 liters of Fuel has been siphoned from %1",_nameType,_canSize], "PLAIN DOWN"];
sleep 1;
 
call fnc_usec_medic_removeActions;
r_action = false;
};

fn_damageActions.sqf

Code:
        //CAN WE SIPHON THE OBJECT?
if ((fuel _unit > 0) and _hasJerryE) then {
            r_action = true;
            _action = _unit addAction [("<t color=""#FF9800"">" + ("Siphon Fuel") + "</t>"),"siphon\siphon.sqf",[_unit], 0, true, true, "", "'ItemJerrycanEmpty' in magazines player"];
            r_player_actions set [count r_player_actions,_action];
        };

The fn_damageActions.sqf could be done better - displaying the actual vehicle name, but i was to lazy ;)
 
guys if your having problems following this guide (and you are doing it mission pbo side) make sure that the references to "siphon.sqf" reference the correct xxx/xxx/siphon.sqf
 
Credit should be given where it's due. DayZ Epoch has had a working siphon system that looks almost the same as what you have done. We will also be updating ours to make it even better. Please feel free to head over and use it for your servers.


Proof: DayZ Epoch GitHub
 
Credit should be given where it's due. DayZ Epoch has had a working siphon system that looks almost the same as what you have done. We will also be updating ours to make it even better. Please feel free to head over and use it for your servers.


Proof: DayZ Epoch GitHub

I'm seeing some cool things here, trading?! ... Didn't find the "new" siphon, what's new and improved about it?
 
Credit should be given where it's due. DayZ Epoch has had a working siphon system that looks almost the same as what you have done. We will also be updating ours to make it even better. Please feel free to head over and use it for your servers.


Proof: DayZ Epoch GitHub


All do respect, I modified this from dayz vanilla my self, AND posted it here for everyone. Call it what you want, but what should I be giving you credit for?

It was easy considering all you have to is look at how you are filling jerry cans at pumps. All I did was reverse it and made it work on all vehicles.

If you feel there are "similarities" fine. Dont slam a thread that is for OPEN DAYZ. Had I wanted to use yours, I would have contacted you just like I did with Shinkicker.
 
Hey - is it possible to make fuel tanks have a limited quantity of fuel in them each restart? (Preferably a way to randomize it)

I've always liked the idea of having to travel far and wide to fuel up fully, rather than one spot from 0 to full.
 
I got this to work via mission with 3 edits. and those edits were to the cutText, removing localize. Awesome script man :)
 
Back
Top