a3_exile_occupation/scripts/reactions/driverKilled.sqf
2016-04-08 14:48:25 +01:00

80 lines
2.3 KiB
Plaintext

// Triggered when the designated driver for a vehicle is killed
// Attempts to select a new driver from the same group
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Vehicle]:: Unit %2 (driver) killed at %1",time,_this select 0];
[_logDetail] call SC_fnc_log;
};
_deadDriver = _this select 0;
_deadDriver removeAllMPEventHandlers "mpkilled";
_vehicle = _deadDriver getVariable "SC_drivenVehicle";
if(SC_debug) then
{
{ detach _x; deleteVehicle _x; } forEach attachedObjects _deadDriver;
};
// Select a replacement driver
_vehicle removeAllMPEventHandlers "mphit";
_group = group _vehicle;
[_deadDriver] join grpNull;
{
if(!alive _x) then { [_x] join grpNull; };
}forEach units _group;
if(count units _group > 0) then
{
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Vehicle]:: vehicle: %1 group: %2 units left:%3",_vehicle,_group,count units _group];
[_logDetail] call SC_fnc_log;
};
_groupMembers = units _group;
_driver = _groupMembers call BIS_fnc_selectRandom;
_driver disableAI "TARGET";
_driver disableAI "AUTOTARGET";
_driver disableAI "AUTOCOMBAT";
_driver disableAI "COVER";
_driver assignAsDriver _vehicle;
_driver setVariable ["DMS_AssignedVeh",_vehicle];
_driver setVariable ["SC_drivenVehicle", _vehicle,true];
_vehicle setVariable ["SC_assignedDriver", _driver,true];
_vehicle addMPEventHandler ["mphit", "_this call SC_fnc_repairVehicle;"];
_driver addMPEventHandler ["mpkilled", "_this call SC_fnc_driverKilled;"];
if(SC_debug) then
{
_tag = createVehicle ["Sign_Arrow_Green_F", position _driver, [], 0, "CAN_COLLIDE"];
_tag attachTo [_driver,[0,0,0.6],"Head"];
};
_driver doMove (position _vehicle);
_driver action ["movetodriver", _vehicle];
if(SC_extendedLogging) then
{
_logDetail = format ["[OCCUPATION:Vehicle]:: Replacement Driver found (%1) for vehicle %2",_driver,_vehicle];
[_logDetail] call SC_fnc_log;
};
if(damage _vehicle > 0) then
{
[_driver] call SC_fnc_repairVehicle;
};
}
else
{
_logDetail = format ["[OCCUPATION:Vehicle]:: No replacement Driver found for vehicle %1",_vehicle];
[_logDetail] call SC_fnc_log;
};