a3_exile_occupation/scripts/reactions/repairVehicle.sqf
2016-05-05 12:23:52 +01:00

104 lines
3.4 KiB
Plaintext

// Triggered when a ground vehicle takes damage
// Attempts to get the current vehicle driver to repair the vehicle
_vehicle = _this select 0;
_vehicle removeAllMPEventHandlers "mphit";
_vehicleDamage = damage _vehicle;
_damagedWheels = 0;
_damageLimit = 1;
_engineDamage = false;
_fueltankDamage = false;
_assignedDriver = _vehicle getVariable "SC_assignedDriver";
if(!alive _assignedDriver) exitWith
{
[_assignedDriver] call SC_fnc_driverKilled;
};
_wheels = ["HitLFWheel","HitLF2Wheel","HitRFWheel","HitRF2Wheel","HitLBWheel","HitLMWheel","HitRBWheel","HitRMWheel"];
_damagedWheels = 0;
{
if ((_vehicle getHitPointDamage _x) > 0) then
{
_damage = _vehicle getHitPointDamage _x;
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:repairVehicle]:: Vehicle %1 checking wheel %2 (damage: %4) @ %3",_vehicle, _x, time,_damage];
[_logDetail] call SC_fnc_log;
};
if(_damage == 1) then { _damagedWheels = _damagedWheels + 1; };
};
} forEach _wheels;
// Check Engine
if ((_vehicle getHitPointDamage "HitEngine") >= _damageLimit) then { _engineDamage = true; };
// Check Fuel Tank
if ((_vehicle getHitPointDamage "HitFuel") > 0) then { _fueltankDamage = true; };
if(_damagedWheels > 0 OR _engineDamage OR _fueltankDamage) then
{
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:repairVehicle]:: Unit %2 repairing vehicle at %1",time,_assignedDriver];
[_logDetail] call SC_fnc_log;
};
[_vehicle,_assignedDriver ] spawn
{
_vehicle = _this select 0;
_vehicle forceSpeed 0;
_group = group _vehicle;
_driver = _this select 1;
_driver disableAI "MOVE";
_driver disableAI "TARGET";
_driver disableAI "AUTOTARGET";
_driver disableAI "AUTOCOMBAT";
_driver disableAI "COVER";
_driver disableAI "SUPPRESSION";
_driver disableAI "FSM";
sleep 0.3;
_driver action ["getOut", _vehicle];
_driver doMove (position _vehicle);
_driverDir = _driver getDir _vehicle;
_driver setDir _driverDir;
_driver setUnitPos "MIDDLE";
sleep 0.5;
_driver playMoveNow "Acts_carFixingWheel";
sleep 4;
_driver switchMove "";
if(alive _driver) then
{
_vehicle setDamage 0;
_driver playMoveNow "Acts_carFixingWheel";
sleep 2;
_driver switchMove "";
_driver assignAsDriver _vehicle;
_driver moveInDriver _vehicle;
_driver action ["movetodriver", _vehicle];
};
_wp = _group addWaypoint [position _vehicle, 0] ;
_wp setWaypointFormation "Column";
_wp setWaypointCompletionRadius 1;
_wp setWaypointType "GETIN";
sleep 5;
_spawnLocation = _vehicle getVariable "SC_vehicleSpawnLocation";
_driver action ["movetodriver", _vehicle];
_vehicle forceSpeed -1;
[_group, _spawnLocation, 2000] call bis_fnc_taskPatrol;
_group setBehaviour "SAFE";
_group setCombatMode "RED";
};
}
else
{
_logDetail = format ["[OCCUPATION:repairVehicle]:: Not repairing %2, driver is %3 at %1",time,_vehicle,_assignedDriver];
[_logDetail] call SC_fnc_log;
_logDetail = format ["[OCCUPATION:repairVehicle]:: vehicle:%1 damage:%2 engine:%3 fuelTank:%4",_vehicle,_vehicleDamage,_engineDamage,_fueltankDamage];
[_logDetail] call SC_fnc_log;
};
_vehicle addMPEventHandler ["mphit", "_this call SC_fnc_repairVehicle;"];