Advertisement
Guest User

ai_death.sqf

a guest
Jul 19th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. /*
  2. DZAI_unitDeath
  3.  
  4. Description: Called when AI unit blood level drops below zero to process unit death.
  5.  
  6. Usage: [_unit,_killer] call DZAI_unitDeath;
  7.  
  8. Last updated: 7:09 PM 12/15/2013
  9. */
  10.  
  11. private["_victim","_killer","_unitGroup","_unitType","_launchWeapon","_launchAmmo","_deathType"];
  12. _victim = _this select 0;
  13. _killer = _this select 1;
  14. _deathType = if ((count _this) > 2) then {_this select 2} else {"bled"};
  15.  
  16. if (_victim getVariable ["deathhandled",false]) exitWith {};
  17. _victim setVariable ["deathhandled",true];
  18. _victim setDamage 1;
  19. _victim removeAllEventHandlers DZAI_healthType;
  20.  
  21. if (_deathType == "shothead") then { //no need for isplayer check since "shothead" is only possible if killer is a player
  22. _nul = _killer spawn {
  23. _headshots = _this getVariable["headShots",0];
  24. _headshots = _headshots + 1;
  25. _this setVariable["headShots",_headshots,true];
  26. };
  27. };
  28.  
  29. _unitGroup = (group _victim);
  30. _unitsAlive = ({alive _x} count (units _unitGroup));
  31. _unitGroup setVariable ["GroupSize",((_unitGroup getVariable ["GroupSize",0]) - 1)];
  32. _unitType = _unitGroup getVariable ["unitType",""];
  33. call {
  34. if (_unitType == "static") exitWith {
  35. [_victim,_killer,_unitGroup,_unitsAlive] call DZAI_AI_killed_static;
  36. 0 = [_victim,_killer,_unitGroup,_unitType,_unitsAlive] call DZAI_AI_killed_all;
  37. DZAI_numAIUnits = DZAI_numAIUnits - 1;
  38. };
  39. if (_unitType == "dynamic") exitWith {
  40. [_victim,_killer,_unitGroup,_unitsAlive] call DZAI_AI_killed_dynamic;
  41. 0 = [_victim,_killer,_unitGroup,_unitType,_unitsAlive] call DZAI_AI_killed_all;
  42. DZAI_numAIUnits = DZAI_numAIUnits - 1;
  43. };
  44. if (_unitType in ["air","aircustom"]) exitWith {
  45. [_victim,_unitGroup] call DZAI_AI_killed_air;
  46. };
  47. if (_unitType in ["land","landcustom"]) exitWith {
  48. 0 = [_victim,_killer,_unitGroup,_unitType] call DZAI_AI_killed_all;
  49. if (_unitsAlive == 0) then {
  50. [_unitGroup] call DZAI_AI_killed_land;
  51. };
  52. };
  53. if (_unitType == "aircrashed") exitWith {};
  54. //Default case starts here
  55. if (_unitsAlive == 0) then {
  56. _nul = [_unitGroup,30] spawn DZAI_deleteGroupTimed;
  57. };
  58. };
  59.  
  60. _launchWeapon = (secondaryWeapon _victim);
  61. if (_launchWeapon in DZAI_launcherTypes) then {
  62. _launchAmmo = getArray (configFile >> "CfgWeapons" >> _launchWeapon >> "magazines") select 0;
  63. _victim removeWeapon _launchWeapon;
  64. _victim removeMagazines _launchAmmo;
  65. //if (_launchWeapon in (weapons _victim)) then {diag_log format ["Warning: Unable to remove launcher weapon %1 from unit %2.",_launchWeapon,_victim]};
  66. //if (_launchAmmo in (magazines _victim)) then {diag_log format ["Warning: Unable to remove launcher ammo %1 from unit %2.",_launchWeapon,_victim]};
  67. //if (DZAI_debugLevel > 1) then {diag_log format ["DZAI Extended Debug: Removed launcher weapon %1 and ammo %2 from unit %3.",_launchWeapon,_launchAmmo,_victim]};
  68. };
  69.  
  70. if (_victim getVariable ["removeNVG",true]) then {
  71. _victim removeWeapon "NVGoggles";
  72. };
  73.  
  74. //Script addition to add skin to units gear
  75. _skin = (typeOf _victim);
  76. _skin = "Skin_" + _skin;
  77. _okSkin = isClass (configFile >> "CfgMagazines" >> _skin);
  78.  
  79. if (_okSkin) then {
  80.  
  81. _result = [_victim,_skin] call BIS_fnc_invAdd;
  82. if (_result) then {
  83. hintSilent "";
  84.  
  85. } else {
  86.  
  87. _bp = unitBackpack _victim;
  88. _bp addMagazineCargoGlobal [_skin,1];
  89.  
  90. };
  91. };
  92. //Script end
  93.  
  94.  
  95. _victim spawn DZAI_deathFlies;
  96. _victim setVariable ["bodyName",_victim getVariable ["bodyName","unknown"],true]; //Broadcast the unit's name (was previously a private variable).
  97. _victim setVariable ["deathType",_deathType,true];
  98. _victim setVariable ["DZAI_deathTime",(diag_tickTime + DZAI_cleanupDelay)];
  99. _victim setVariable ["unconscious",true];
  100.  
  101. _victim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement