Repair and Refuel

ihatetn931

Well-Known Member
Will someone be kind enough to tell me what is wrong with this script? I tried to combine a refuel and repair script together but i can't get it, after hours of messing with it i just got fustrated with it

I think it has to do with but i haven't quite figure out how it selects from the other script

Code:
_target = _this select 0;
_caller = _this select 1;
_vehicle_refuel_id = _this select 2;
_vehicle_repair_id = _this select 3;
_argsRefuel = _this select 3;
_argsRepair = _this select 4;
__fuelAmount = _argsRefuel select 0;
__repairAmount = _argsRepair select 0;

kh_actions.sqf
Code:
private ["_refuelVehicle","_repairVehicle","_vehicle_refuel_id","_vehicle_repair_id"];
//Awesomely Edited by Seven, Then modified by Muddr
_refuelVehicle = objNull;
_repairVehicle = objNull;
diag_log "Running ""kh_actions"".";
 
_distance = 15; // Distance from object to display Refuel Message
_fuelAmount = 0.02; // Amount of fuel to add per loop. Default was 0.005
_damageAmount = 0.02; // Amount of damage to remove per loop.
 
while {true} do
{
    if (!isNull player) then {
 
        private ["_vehicleRefuel","_vehicleRepair", "_isNearFeed", "_countFuel","_isNearRepair","_countDamage"];
_vehicleRefuel = vehicle player;
 
_countFuel = (count ((position _vehicleRefuel) nearObjects ["Land_Fuel_tank_big", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["Land_A_FuelStation_Feed", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["Land_Ind_TankSmall", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["Land_Ind_TankSmall2", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["Land_Ind_TankSmall2_EP1", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["Land_fuel_tank_stairs", _distance]));
_countFuel = _countFuel + (count ((position _vehicleRefuel) nearObjects ["UralRefuel_INS", _distance]));
_isNearFeed = _countFuel > 0;
 
_vehicleRepair = vehicle player;
 
_countDamage = (count ((position _vehicleRepair) nearObjects ["UralRepair_CDF", _distance]));
_isNearRepair = _countDamage > 0;
 
 
        if (_refuelVehicle != _vehicleRefuel) then {
            if (!isNull _refuelVehicle) then {
 
                _refuelVehicle removeAction _vehicle_refuel_id;
                _refuelVehicle = objNull;
            };
 
            if (_vehicleRefuel != player && _isNearFeed && !(_vehicleRefuel isKindof "Bicycle")) then {
                _refuelVehicle = _vehicleRefuel;
 
                _vehicle_refuel_id = _refuelVehicle addAction ["Refuel", "Scripts\Repair_Refuel\kh_refuel_repair.sqf", [_refuelAmount], -1, false, true, "", "vehicle _this == _target && local _target"];
            };
        };
 
if (_repairVehicle != _vehicleRepair) then {
            if (!isNull _repairVehicle) then {
 
_repairVehicle removeAction _vehicle_repair_id;
                _repairVehicle = objNull;
            };
 
if (_vehicleRepair != player && _isNearRepair && !(_vehicleRepair isKindof "Bicycle")) then {
                _repairVehicle = _vehicleRepair;
 
                _vehicle_repair_id = _repairVehicle addAction ["Repair", "Scripts\Repair_Refuel\kh_refuel_repair.sqf", [_repairAmount], -1, false, true, "", "vehicle _this == _target && local _target"];
            };
};
 
        if (!_isNearFeed) then {
            _refuelVehicle removeAction _vehicle_refuel_id;
            _refuelVehicle = objNull;
        };
if (!_isNearRepair) then {
            _repairVehicle removeAction _vehicle_repair_id;
            _repairVehicle = objNull;
        };
    };
    sleep 2;
}

kh_refuel_repair.sqf

Code:
private ["_target", "_caller", "_vehicle_refuel_id","_vehicle_repair_id"];
 
_target = _this select 0;
_caller = _this select 1;
_vehicle_refuel_id = _this select 2;
_vehicle_repair_id = _this select 3;
_argsRefuel = _this select 3;
_argsRepair = _this select 4;
__fuelAmount = _argsRefuel select 0;
__repairAmount = _argsRepair select 0;
 
if (isNil "ib_refueling_in_progress") then { ib_refueling_in_progress = false; };
if (isNil "ib_repairing_in_progress") then { ib_reparing_in_progress = false; };
 
if (!ib_refueling_in_progress) then {
 
ib_refueling_in_progress = true;
 
titleText ["Refueling", "PLAIN DOWN", 3];
 
while {(vehicle _caller == _target) and (local _target)} do {
private ["_velocity", "_cfcustRefuel"];
   
_velocity = velocity _target;
_cfcustRefuel = fuel _target;
 
if ((_velocity select 0 > 1) or (_velocity select 1 > 1) or (_velocity select 2 > 1)) exitWith {
titleText ["Refueling Stopped", "PLAIN DOWN", 3];
};
if (_cfcustRefuel >= 1.0) exitWith {
titleText ["Done Refueling", "PLAIN DOWN", 3];
};
 
sleep 0.5;
 
_cfcustRefuel = _cfcustRefuel + _fuelAmount;
 
if (_cfcustRefuel >= 1.0) then { _cfcustRefuel = 1.0; };
 
_target setFuel _cfcustRefuel;
};
 
titleFadeOut 1;
 
ib_refueling_in_progress = false;
};
 
 
if (!ib_reparing_in_progress) then {
 
ib_reparing_in_progress = true;
 
titleText ["Reparing", "PLAIN DOWN", 3];
 
while {(vehicle _caller == _target) and (local _target)} do {
private ["_velocity", "_cfcustRepair"];
   
_velocity = velocity _target;
_cfcustRepair = damage _target;
 
if ((_velocity select 0 > 1) or (_velocity select 1 > 1) or (_velocity select 2 > 1)) exitWith {
titleText ["Reparing Stopped", "PLAIN DOWN", 3];
};
if (_cfcustRepair == 0) exitWith {
titleText ["Done Reparing", "PLAIN DOWN", 3];
};
 
sleep 0.5;
 
_cfcustRepair = _cfcustRepair - _repairAmount;
 
if (_cfcustRepair == 0) then { _cfcustRepair = 0; };
 
_target setDamage _cfcustRepair;
};
 
titleFadeOut 1;
 
ib_reparing_in_progress = false;
};
 
In kh_vehicle_refuel.sqf

Find
Code:
_cfcust = fuel _target;
Add under it
Code:
_damage = getDammage _target;

Find
Code:
_cfcust = _cfcust + _amount;
and add under it
Code:
if ((_damage > 0) && (_damage != 0)) then {
                    _damage = (_damage - _amount);
                    if (_damage < 0) then {
                        _damage = 0;
                    };
                };

and under
Code:
_target setFuel _cfcust;
add
Code:
_target setdammage _damage;

That should make kh refuel also repair vehicles while it refuels them. It does it based on the speed you have set in kh_actions.sqf

It won't repair blown up vehicles (as that code doesn't from experience) and I'm not sure if it'll save their undamaged state unless the vehicle takes more damage after getting repaired at the pump.
 
To also add repairing at repair trucks it's a little more code, probably in a different script.
 
Oh see what i tried to do is combine the 2 script together to mimize the amount of files i had, so i'll split the 2 scripts and see what i come up with.

I noticed i was using the wrong global . Thank you
 
Well you could add in for it to detect nearobjects as the repair trucks, count them, use a global variable as the count, and if it is greater than 0 to repair and refuel.

If you only want repair at the trucks and not at pumps then I'd just toss together a simple script to do so, or use a different one like you mentioned.
 
I did that but i think my main issue was the _this select shiznit, still trying to figure out how it works, i know it's selecting from the other script but i'm not sure where.

Code:
[FONT=Consolas]_countDamage = (count ((position _vehicleRepair) nearObjects ["UralRepair_CDF", _distance]));
_isNearRepair = _countDamage > 0;[/FONT]
[FONT=Consolas]
[/FONT]
 
You want to make sure you add in a line for all 4 repair trucks
(Ural, MTVR, Kamaz, V3S)

Make _isNearRepair isNearRepair (no underscore thus a global variable instead of a local/private variable)

Then in kh_vehicle_refuel something like
Code:
if ((_damage > 0) && (_damage != 0) && (isNearRepair >= 1)) then {
                    _damage = (_damage - _amount);
                    if (_damage < 0) then {
                        _damage = 0;
                    };
                };

Not sure if you only want repair at trucks, or at pumps too.
 
Just at the trucks, i've only got one truck on there cause it's the only ural repair i've got spawned in my server
 
well thank you, i wasn't expecting you to code it.

Much apperciated, this lang, is way diffrent then any type i know but i'm eventually gonna figure out how everthing works.

2 likes ftw :-D.

When i eventually figure out how everything works i'm gonna give back to the commiunty for helping me out for being a arma 2 lang. noob
 
1 more question, is there a way to save it to green after server restart?

I can repair somthing that is missin a wheel and it fixes it but when i restart the server the wheel is missin again but the damage in the database is 0 so i can't repair it again.

I got this so it force saves it to the database.

[_target , _vehicleType] call server_updateObject;

I'm assumin i'm gonna have to make the code attach each part if it's missin correct?

somthing like this
Code:
if(wheel1 > 0) then
{
//attach wheel
};

Know where i can get the variables for the parts on the vehicles?
 
Does [_target , _vehicleType] call server_updateObject; not work already?

_vehicleType = typeOf _target;
[_target , _vehicleType] call server_updateObject;
 
It saves the vehicle damage to 0 but it dosen't save the parts that are missin, How you have it is exactly how i have it.

Code:
_vehicleType = typeOf _target;
[_target , _vehicleType] call server_updateObject;

It saves the damage to 0 but for some odd reason it dosen't keep the parts that were broken fixed.

So say i have a uaz missin 1 tire i repair it, it repairs the tire then when i restart the server that tire is missin again and i can't repair due to the fact that the damag is picking up 0
 
It must be updating the damage but not the hitpoints table.

Under
Code:
if ((_damage > 0) && (_damage != 0) && (isNearRepair >= 1)) then {
                    _damage = (_damage - _amount);
                    if (_damage < 0) then {
                        _damage = 0;
                    };
                };
add
Code:
if ((_damage <= .3) && (_damage != 0)) then {
    _target setHitPointDamage ["HitEngine", 0];
    _target setHitPointDamage ["HitFuel", 0];
    _target setHitPointDamage ["HitLFWheel", 0];
    _target setHitPointDamage ["HitRFWheel", 0];
    _target setHitPointDamage ["HitRMWheel", 0];
    _target setHitPointDamage ["HitLMWheel", 0];
    _target setHitPointDamage ["HitRF2Wheel", 0];
    _target setHitPointDamage ["HitLF2heel", 0];
    _target setHitPointDamage ["HitLBWheel", 0];
    _target setHitPointDamage ["HitRBWheel", 0];
    _target setHitPointDamage ["HitGlass1", 0];
    _target setHitPointDamage ["HitGlass2", 0];
    _target setHitPointDamage ["HitGlass3", 0];
    _target setHitPointDamage ["HitGlass4", 0];
    _target setHitPointDamage ["HitGlass5", 0];
    _target setHitPointDamage ["HitGlass6", 0];
    _target setHitPointDamage ["HitVRotor", 0];
    _target setHitPointDamage ["HitHRotor", 0];
    _target setHitPointDamage ["HitHull", 0];
    _target setHitPointDamage ["HitAvionics", 0];
    _target setHitPointDamage ["HitMissiles", 0];
    _target setHitPointDamage ["HitRGlass", 0];
    _target setHitPointDamage ["HitLGlass", 0];
}:

That should cover everything. After that force an update.
 
I had a feeling it had somthing to do with the hitpoints but i wasn't sure what the global variable for the hit points where. I'm trying it now, will edit this post. Thank you again :-D
 
Anytime i add the sethitpointdamage i get an error, i've gone over it numerous times and found no issues what so ever.

I can remove and the script works fine but as soon as i add a sethitpointdamage i get this.

Code:
Error in expression <amage <= 0) then {
_damage = 0;
_target setHitPointDamage ["HitEngine", 0];
};
}>
  Error position: <setHitPointDamage ["HitEngine", 0];
};
}>
  Error Missing ;
File mpmissions\__CUR_MP.Chernarus\Scripts\Repair\kh_repair.sqf, line 39

Line 39 being the very first sethitpointdamage

Code:
_target setHitPointDamage ["HitEngine", 0];

But if i remove all the setHitPointDamage then the script works fine, seems not to like the sethitpointdamage
 
Anytime i add the sethitpointdamage i get an error, i've gone over it numerous times and found no issues what so ever.

I can remove and the script works fine but as soon as i add a sethitpointdamage i get this.

Code:
Error in expression <amage <= 0) then {
_damage = 0;
_target setHitPointDamage ["HitEngine", 0];
};
}>
  Error position: <setHitPointDamage ["HitEngine", 0];
};
}>
  Error Missing ;
File mpmissions\__CUR_MP.Chernarus\Scripts\Repair\kh_repair.sqf, line 39

Line 39 being the very first sethitpointdamage

Code:
_target setHitPointDamage ["HitEngine", 0];

But if i remove all the setHitPointDamage then the script works fine, seems not to like the sethitpointdamage

the closing brace for

Code:
if ((_damage <= .3) && (_damage != 0)) then {
    _target setHitPointDamage ["HitEngine", 0];
    _target setHitPointDamage ["HitFuel", 0];
    _target setHitPointDamage ["HitLFWheel", 0];
    _target setHitPointDamage ["HitRFWheel", 0];
    _target setHitPointDamage ["HitRMWheel", 0];
    _target setHitPointDamage ["HitLMWheel", 0];
    _target setHitPointDamage ["HitRF2Wheel", 0];
    _target setHitPointDamage ["HitLF2Wheel", 0];
    _target setHitPointDamage ["HitLBWheel", 0];
    _target setHitPointDamage ["HitRBWheel", 0];
    _target setHitPointDamage ["HitGlass1", 0];
    _target setHitPointDamage ["HitGlass2", 0];
    _target setHitPointDamage ["HitGlass3", 0];
    _target setHitPointDamage ["HitGlass4", 0];
    _target setHitPointDamage ["HitGlass5", 0];
    _target setHitPointDamage ["HitGlass6", 0];
    _target setHitPointDamage ["HitVRotor", 0];
    _target setHitPointDamage ["HitHRotor", 0];
    _target setHitPointDamage ["HitHull", 0];
    _target setHitPointDamage ["HitAvionics", 0];
    _target setHitPointDamage ["HitMissiles", 0];
    _target setHitPointDamage ["HitRGlass", 0];
    _target setHitPointDamage ["HitLGlass", 0];
}:
has a colon instead of a semi colon replace the above code with
Code:
if ((_damage <= .3) && (_damage != 0)) then {
    _target setHitPointDamage ["HitEngine", 0];
    _target setHitPointDamage ["HitFuel", 0];
    _target setHitPointDamage ["HitLFWheel", 0];
    _target setHitPointDamage ["HitRFWheel", 0];
    _target setHitPointDamage ["HitRMWheel", 0];
    _target setHitPointDamage ["HitLMWheel", 0];
    _target setHitPointDamage ["HitRF2Wheel", 0];
    _target setHitPointDamage ["HitLF2Wheel", 0];
    _target setHitPointDamage ["HitLBWheel", 0];
    _target setHitPointDamage ["HitRBWheel", 0];
    _target setHitPointDamage ["HitGlass1", 0];
    _target setHitPointDamage ["HitGlass2", 0];
    _target setHitPointDamage ["HitGlass3", 0];
    _target setHitPointDamage ["HitGlass4", 0];
    _target setHitPointDamage ["HitGlass5", 0];
    _target setHitPointDamage ["HitGlass6", 0];
    _target setHitPointDamage ["HitVRotor", 0];
    _target setHitPointDamage ["HitHRotor", 0];
    _target setHitPointDamage ["HitHull", 0];
    _target setHitPointDamage ["HitAvionics", 0];
    _target setHitPointDamage ["HitMissiles", 0];
    _target setHitPointDamage ["HitRGlass", 0];
    _target setHitPointDamage ["HitLGlass", 0];
};
this and it will should work
 
I fixed that, i noticed that after i got the error the first time so that's not my issue
what mod is your server running?
as i modified the repair vehicle script from epoch and i can edit it for another mod but if you run epoch try using this code instaed of Vampire's

Code:
_type = typeOf _target;
_hitpoints = _target call vehicle_getHitpoints;
{
    _selection = getText(configFile >> "cfgVehicles" >> _type >> "HitPoints" >> _x >> "name");
    PVDZE_veh_SFix = [_target,_selection,0];
    publicVariable "PVDZE_veh_SFix";
    if (local _target) then {
        PVDZE_veh_SFix call object_setFixServer;
    };
    sleep 0.5;
} forEach _hitpoints;
 
Back
Top