Improved Siphon Fuel Script [1.7.7.1]

After looking at some of the other fuel siphon scripts out there I decided to write my own. This script is derived from @DayZ\Addons\dayz_code\actions\jerry_fill.sqf (1.7.7.1) and is a fully server-side mod contained in mission.pbo.

FEATURES
This script will siphon fuel into all suitable containers in the players inventory (empty Jerry cans and empty fuel cans). The time it takes to perform the action is adjusted based on the number and size of containers to fill. The action can be interrupted.

KNOWN BUGS
None; find some and let me know.

INSTALL INSTRUCTIONS
These are the same as many of the other mods. If you cannot figure it out, you shouldn't be trying to modify your server until you do some research and understand what you're doing.

init.sqf
Code:
call compile preprocessFileLineNumbers "custom\compiles.sqf";

custom\fn_selfActions.sqf
Code:
_isBike = (cursorTarget isKindOf "Old_bike_TK_INS_EP1" || cursorTarget isKindOf "Old_bike_TK_CIV_EP1");
if((_hasFuelE20 or _hasFuelE5) and _isVehicle and !_isBike and (fuel cursorTarget > 0) and !a_player_jerryfilling) then {
    if (s_player_siphonfuel < 0) then {
        s_player_siphonfuel = player addAction [("<t color=""#c70000"">" + ("Siphon Vehicle Fuel") + "</t>"), "custom\player_siphonFuel.sqf", cursorTarget, 1, false, true, "", ""];
    };
} else {
    player removeAction s_player_siphonfuel;
    s_player_siphonfuel = -1;
};

custom\player_siphonFuel.sqf
Code:
//-----------------------------------------------------------------------------
// Siphon Fuel from Vehicles
//    Gives players the ability to siphon fuel from vehicles into empty fuel
//    containers.
//
// DayZ Version: 1.7.7.1 - Chernarus
//
// Author: KungFuCharlie
// Contributors: 
//      Script derived from @DayZ\Addons\dayz_code\actions\jerry_fill.sqf
//
// Change Log:
//      Version 1.0.0 - [July 6, 2013]
//          Initial release of script that works on 1.7.7.1 - Chernarus
//-----------------------------------------------------------------------------
 
private ["_siphonTimeQty20","_siphonTimeQty5","_vehicle","_configVehicle","_vehicleName","_fuelCapacity","_currentFuelQty","_startFuelQty","_newFuel","_qty20","_qty5","_startSiphonTime","_totalSiphonTime","_dis","_sfx"];
 
// Configure the time it takes to siphon a 20L and 5L can of fuel.
// We could just make siphon time for 20L equal to siphon time for 5L * 4.
// But breaking it out this way gives server admins more control over how they
// want the timing to be on their server.
_siphonTimeQty20 = 10;        // Time it takes to siphon 20L of fuel
_siphonTimeQty5 = 5;          // Time it takes to siphon 5L of fuel
 
player removeAction s_player_siphonfuel;
//s_player_siphonfuel = -1;
 
_qty20 = {_x == "ItemJerrycanEmpty"} count magazines player;
_qty5 = {_x == "ItemFuelcanEmpty"} count magazines player;
 
_vehicle = cursorTarget;                                              // The vehicle to siphon fuel from
_configVehicle = configFile >> "cfgVehicles" >> TypeOf(_vehicle);     // Configuration parameters for the vehicle
_vehicleName = getText(_configVehicle >> "displayName");              // Vehicle name
_fuelCapacity = getNumber(_configVehicle >> "fuelCapacity");          // Vehicles fuel capacity
_startFuelQty = ((fuel _vehicle) * _fuelCapacity);                    // Fuel quantity before siphoning any fuel
_currentFuelQty = _startFuelQty;                                      // Current fuel level (used to track level as siphoning occurs)
 
_startSiphonTime = time;
_totalSiphonTime = ((_siphonTimeQty20 * _qty20) + (_siphonTimeQty5 * _qty5));
 
// In all reality this check isn't needed since I have the empty container
// check in fn_selfActions so the action won't be available if they don't
// have an empty container but a second check here won't hurt.
if (_totalSiphonTime > 0) then {
    cutText [format["You begin siphoning fuel from the %1.", _vehicleName], "PLAIN DOWN"];
    player playActionNow "Medic";
 
    // Notify nearby zombies and play sound effects
    _dis = 5;             // Zombie alert distance
    _sfx = "refuel";      // Refuel sound effects
    [player, _sfx, 0, false, _dis] call dayz_zombieSpeak;
    [player, _dis, true, (getPosATL player)] spawn player_alertZombies;
 
    // Do the player animation for the action (using the medic animation) 
    r_interrupt = false;
    r_doLoop = true;
    _started = false;
    _finished = false;
    while {r_doLoop} do {
        _animState = animationState player;
        _isSiphon = ["medic", _animState] call fnc_inString;
        if (_isSiphon) then {
            _started = true;
        } else {
            if (_started and !r_interrupt) then {
                if ((time - _startSiphonTime) <= _totalSiphonTime) then {
                    player playActionNow "Medic";
                    //_isSiphon = true;
                } else {                   //(time - _startSiphonTime) > _totalSiphonTime)
                    r_doLoop = false;
                    _finished = true;
                };
            };
        };
        
        // If the player action is interrupted break out of the loop.
        if (r_interrupt) then {
            r_doLoop = false;
        };    
        sleep 0.1;
    };
    r_doLoop = false;
 
    // Once the animation is completed, swap the correct number of 
    // empty cans in the players inventory with full cans. Only allow the 
    // proper number of cans to be filled based on the vehicles fuel qty.
    if (_finished) then {
        for "_x" from 1 to _qty20 do {
            if (_currentFuelQty >= 20) then {
                player removeMagazine "ItemJerrycanEmpty";
                player addMagazine "ItemJerrycan";
                _currentFuelQty = _currentFuelQty - 20;
            };
        };
        for "_x" from 1 to _qty5 do {
            if (_currentFuelQty >= 5) then {
                player removeMagazine "ItemFuelcanEmpty";
                player addMagazine "ItemFuelcan";
                _currentFuelQty = _currentFuelQty - 5;
            };
        };
    
        // Set new fuel level to vehicle and publish value to all clients
        if (_currentFuelQty < 0) then { _currentFuelQty = 0; };                            // Sanity check
        if (_currentFuelQty > _fuelCapacity) then { _currentFuelQty = _fuelCapacity; };    // Sanity check
        _newFuel = _currentFuelQty / _fuelCapacity;                                        // Convert back into scaled value (0 to 1)
        PVDZ_veh_SetFuel = [_vehicle, _newFuel]; 
        PVDZ_veh_SetFuel spawn local_setFuel;
        publicVariable "PVDZ_veh_SetFuel";
        cutText [format["You siphoned %1 liters of fuel from the %2.", (_startFuelQty - _currentFuelQty), _vehicleName], "PLAIN DOWN"];
    };
} else {
    cutText ["You do not have any suitable containers to siphon fuel with.", "PLAIN DOWN"];
};

FINAL THOUGHTS
None - go play and have fun.
 
Why are you calling for a "custom/compile" in the init.sqf? When I dont see any code from above actually editting the compile.sqf? I see a new .sqf and an edit in the fn_selfactions.sqf only. I know your going to have to edit the compile and change the path to your new selfactions.sqf. But why post the path change in the init.sqf and not the compile.sqf. It would be helpful to give people clearer instuctions.
 
The custom compile has a single line for preprocessing fn_selfActions. I didn't include every step since it is just like all the other mods out there. Refer to the first paragraph in my install instructions. :)
 
Yea I understand that. Just wondering :) Only thing Id change in your instructions is where to put your code in the selfactions as everything else is straight forward
 
I don't specify where to put the code in fn_selfActions because many people have different preferences on where to put it. It clearly needs to go after some of the variables that it uses get initialized. If someone doesn't know that then they'd have to go through the process of figuring it out and, in doing so, will learn something about scripting thus making the community a stronger / better place. Its tough love. :D
 
I can not get this to work? the menu does not seem to be appearing, im guessing its my AH and
I have whitelisted "s_player_siphonfuel" is this correct please?
 
Back
Top