a3_exile_occupation/scripts/reactions/driverKilled.sqf

83 lines
2.4 KiB
Plaintext
Raw Normal View History

2016-04-02 19:06:53 +00:00
// 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];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
_deadDriver = _this select 0;
_deadDriver removeAllMPEventHandlers "mpkilled";
2016-04-08 13:48:25 +00:00
_vehicle = _deadDriver getVariable "SC_drivenVehicle";
2016-04-02 19:06:53 +00:00
if(SC_debug) then
{
2016-04-02 19:06:53 +00:00
{ detach _x; deleteVehicle _x; } forEach attachedObjects _deadDriver;
};
2016-04-02 19:06:53 +00:00
// Select a replacement driver
2016-04-08 13:48:25 +00:00
_vehicle removeAllMPEventHandlers "mphit";
_group = group _vehicle;
2016-04-09 18:28:01 +00:00
// Remove dead units from the group
{
2016-04-08 13:48:25 +00:00
if(!alive _x) then { [_x] join grpNull; };
}forEach units _group;
if(count units _group > 0) then
{
if(SC_extendedLogging) then
{
2016-04-08 13:48:25 +00:00
_logDetail = format ["[OCCUPATION:Vehicle]:: vehicle: %1 group: %2 units left:%3",_vehicle,_group,count units _group];
[_logDetail] call SC_fnc_log;
};
2016-04-02 19:06:53 +00:00
2016-04-08 13:48:25 +00:00
_groupMembers = units _group;
_driver = _groupMembers call BIS_fnc_selectRandom;
2016-04-08 13:48:25 +00:00
_driver disableAI "TARGET";
_driver disableAI "AUTOTARGET";
_driver disableAI "AUTOCOMBAT";
_driver disableAI "COVER";
2016-04-02 19:06:53 +00:00
2016-04-08 13:48:25 +00:00
_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
{
2016-04-08 13:48:25 +00:00
_tag = createVehicle ["Sign_Arrow_Green_F", position _driver, [], 0, "CAN_COLLIDE"];
_tag attachTo [_driver,[0,0,0.6],"Head"];
};
2016-04-08 13:48:25 +00:00
_driver doMove (position _vehicle);
_driver action ["movetodriver", _vehicle];
2016-04-02 19:06:53 +00:00
2016-04-02 19:06:53 +00:00
if(SC_extendedLogging) then
{
2016-04-08 13:48:25 +00:00
_logDetail = format ["[OCCUPATION:Vehicle]:: Replacement Driver found (%1) for vehicle %2",_driver,_vehicle];
2016-04-02 19:06:53 +00:00
[_logDetail] call SC_fnc_log;
};
2016-04-08 13:48:25 +00:00
if(damage _vehicle > 0) then
2016-04-02 19:06:53 +00:00
{
2016-04-09 18:28:01 +00:00
[_vehicle] call SC_fnc_repairVehicle;
2016-04-02 19:06:53 +00:00
};
2016-04-08 13:48:25 +00:00
}
else
{
_logDetail = format ["[OCCUPATION:Vehicle]:: No replacement Driver found for vehicle %1",_vehicle];
[_logDetail] call SC_fnc_log;
2016-04-11 20:17:34 +00:00
_vehicle lock 0;
_vehicle setVehicleLock "UNLOCKED";
_vehicle setVariable ["ExileIsLocked", 0, true];
2016-04-02 19:06:53 +00:00
};