[Release] Proper Repair Truck Script Add-On (DayZ 1.8+/rMod 2.1)

BDC

Well-Known Member
Hi gang, this is a repair truck script I wrote to replace the pseudo-working Repair option that pops up for drivers in vehicles when targeting an Arma-esque repair truck. This script balances out the process by splitting up the repair process on each damage point, adds sound, plus writes the repaired damage point to the database.

Only two files need to be modified for this - variables.SQF and fn_SelfActions. For those unfamiliar with gaining access to these server-side, search the forums as there should be many threads on how to extract from the dayz_code.pbo.

On to the addon.

Step 1) Modify variables.SQF

On or around line 230, look for a small section titled (commented out) "//actions blockers
And below it, add this chunk:

Code:
// Repair truck addon for rMod 2.1+ by ^bdc
RepairTrucks = ["KamazRepair","MTVRRepair","UralRepair_CDF","UralRepair_INS","MTVRRepair_DES_EP1","UralRepair_TK_EP1","V3S_Repair_TK_GUE_EP1"]; // list of valid repair truck types
s_player_repairingvehicle = false; // default flag set to false

This is the global action flag and global array I use for determining which vehicle object qualifies as a repair truck. I've picked all of the repair trucks from Arma 2 and Operation Arrowhead already so it does not need to be modified.

Also, if you do not have this chunk of code or any other used to prevent multiple actions from popping up when entering and exiting the same vehicle, add this section directly below:

// Multiple (ever-duplicating) action removal flags
s_player_inVehicle = false; // fn_selfActions.sqf
s_player_inVehicleObj = nil;

Step 2) Modify fn_selfActions.SQF

At the very top, find this section:

Code:
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_cursorTarget = cursorTarget;
_primaryWeapon = primaryWeapon player;
_currentWeapon = currentWeapon player;
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;

Directly below it, if you do not already have this or some other way to prevent multiple actions of the same action, add this section:

Code:
// In Vehicle/Out of vehicle duplicate/multiple action clearing - ^bdc (thanks, Thumper)
if ((!s_player_inVehicle) and (_inVehicle)) then {
    s_player_inVehicle = true; // flag until player leaves
    s_player_inVehicleObj = _vehicle;
};

if ((s_player_inVehicle) and (!_inVehicle)) then {
    s_player_inVehicle = false;
    _tmpaction = s_player_inVehicleObj addAction["junk", "junk.sqf"];
    while {_tmpaction >= 0} do {
        s_player_inVehicleObj removeAction _tmpaction;
        _tmpaction = _tmpaction - 1;
    };
    diag_log format["fn_selfActions.SQF: Player dismounted from vehicle object %1. Clearing all actions.",s_player_inVehicleObj];
    s_player_inVehicleObj = nil;
};
// End In Vehicle/Out of vehicle

At the very bottom of the file, add this large chunk which adds the brown-coloured option for Repairing your vehicle while sitting in it and pointing at a repair truck:

Code:
// Repair truck repair option addon by ^bdc (rMod 2.1+)
if (_inVehicle) then {
    _NeedsRepair = false;
    _isValidRepairTruck = false;
    _hitpoints = _vehicle call vehicle_getHitpoints;
    {
        _damage = [_vehicle,_x] call object_getHit;           
        if (_damage > 0) then {
            _NeedsRepair = true;
        };
    } forEach _hitpoints;       
    if (_NeedsRepair) then {
        _count = count RepairTrucks; // variables.sqf
        for "_x" from 0 to _count do {   
            _truck = RepairTrucks select _x;
            if (_cursorTarget isKindOf _truck) then {
                _isValidRepairTruck = true;
                _x = _count;
            };
        };
    };
    _repairingvehicle = false;
    _repairingvehicle = _vehicle getVariable ["repairing",false];
    _maxRange = 15;
    if (_isValidRepairTruck and _NeedsRepair and (player distance _cursorTarget <= _maxRange) and (!_repairingvehicle) and (driver _vehicle == player) and (alive _cursorTarget)) then {
        _reptrucktxt = getText (configFile >> "CfgVehicles" >> typeOf _cursorTarget >> "displayName");
        _vehtxt = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");
        if (s_player_repairtruckop < 0) then {
            _fstr = format["<t color='#C7A500'>Repair %1 with %2</t>",_vehtxt,_reptrucktxt];
            s_player_repairtruckop = _vehicle addAction [_fstr, "fixes\vehicle_repairvehicle.sqf", [_cursorTarget]];
        };
    } else {
        _vehicle removeAction s_player_repairtruckop;
        s_player_repairtruckop = -1;
    };
} else {
    _vehicle removeAction s_player_repairtruckop;
    s_player_repairtruckop = -1;
};

Step 3) Download the vehicle_repairvehicle.SQF script

It can be found on my Mediafire page here: -> https://www.mediafire.com/?5s2a72b31wr6a7m

Be sure to put it in the \dayz_server folder\MPMissions\dayz_1.Chernarus\fixes folder or use a different folder (other than fixes) and then change the code above to reflect that folder name.

That's it!

B
 
Back
Top