Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.37 KB | None | 0 0
  1. #include "script_component.hpp"
  2. /*
  3.  * Author: KoffeinFlummi, Glowbal, commy2
  4.  * Main HandleDamage EH function.
  5.  *
  6.  * Arguments:
  7.  * 0: Unit That Was Hit <OBJECT>
  8.  * 1: Name Of Hit Selection <STRING>
  9.  * 2: Amount Of Damage <NUMBER>
  10.  * 3: Shooter <OBJECT>
  11.  * 4: Projectile <OBJECT, STRING>
  12.  * 5: HitPointIndex (-1 for structural) <NUMBER>
  13.  * 6: Shooter <OBJECT>
  14.  *
  15.  * Return Value:
  16.  * Damage To Be Inflicted <NUMBER>
  17.  *
  18.  * Example:
  19.  * [bob, "leg", 2, kevin, "bullet", -1, kevin] call ACE_medical_fnc_handleDamage
  20.  *
  21.  * Public: No
  22.  */
  23.  
  24. _this = _this select [0, 7];
  25. params ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_hitPointIndex"];
  26. TRACE_5("ACE_DEBUG: HandleDamage Called",_unit, _selection, _damage, _shooter, _projectile);
  27.  
  28. // bug, apparently can fire for remote units in special cases
  29. if !(local _unit) exitWith {
  30.     TRACE_2("ACE_DEBUG: HandleDamage on remote unit!",_unit, isServer);
  31.     nil
  32. };
  33.  
  34. // bug, assumed fixed, @todo excessive testing, if nothing happens remove
  35. if (_projectile isEqualType objNull) then {
  36.     _projectile = typeOf _projectile;
  37.     _this set [4, _projectile];
  38. };
  39.  
  40. TRACE_3("ACE_DEBUG: HandleDamage",_selection,_damage,_unit);
  41.  
  42. // If damage is in dummy hitpoints, "hands" and "legs", don't change anything
  43. if (_selection == "hands") exitWith {_unit getHit "hands"};
  44. if (_selection == "legs") exitWith {_unit getHit "legs"};
  45. if (_selection == "arms") exitWith {_unit getHit "arms"};
  46.  
  47. // Deal with the new hitpoint and selection names introduced with Arma v1.50 and later.
  48. // This will convert new selection names into selection names that the medical system understands
  49. // TODO This should be cleaned up when we revisit the medical system at a later stage
  50. // and instead we should deal with the new hitpoints directly
  51. _selection = [_unit, _selection, _hitPointIndex] call FUNC(translateSelections);
  52. _this set [1, _selection]; // ensure that the parameters are set correctly
  53.  
  54. // If the damage is being weird, we just tell it to fuck off. Ignore: "hands", "legs", "arms"
  55. if (_selection != "" && {!(_selection in GVAR(SELECTIONS))}) exitWith {0};
  56.  
  57. // Exit if we disable damage temporarily
  58. if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {
  59.     TRACE_3("ACE_DEBUG: HandleDamage damage disabled.",_selection,damage _unit,_unit);
  60.     if (_selection == "") then {
  61.         damage _unit
  62.     } else {
  63.         _unit getHit _selection
  64.     };
  65. };
  66.  
  67. // Get return damage
  68. private _damageReturn = _damage;
  69.  
  70. private _newDamage = _this call FUNC(handleDamage_caching);
  71. // handleDamage_caching may have modified the projectile string
  72. private _typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
  73.  
  74. TRACE_3("ACE_DEBUG: HandleDamage caching new damage",_selection,_newDamage,_unit);
  75.  
  76. private _typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
  77. private _minLethalDamage = if (_typeIndex >= 0) then {
  78.     GVAR(minLethalDamages) select _typeIndex
  79. } else {
  80.     0.01
  81. };
  82.  
  83. if (!isNull _shooter) then {
  84.     _unit setvariable [QGVAR(lastDamageSource), _shooter, false];
  85. };
  86.  
  87. private _vehicle = vehicle _unit;
  88. private _effectiveSelectionName = _selection;
  89. if ((_vehicle != _unit) && {!(_vehicle isKindOf "StaticWeapon")} && {_shooter in [objNull, driver _vehicle, _vehicle]} && {_projectile == ""} && {_selection == ""}) then {
  90.     if (GVAR(enableVehicleCrashes)) then {
  91.         _effectiveSelectionName = _this select 1; //pull random selection from HDC
  92.     };
  93. };
  94.  
  95. if ((_minLethalDamage <= _newDamage) && {[_unit, [_effectiveSelectionName] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)}) then {
  96.     if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
  97.         _damageReturn = 0.9;
  98.     };
  99.     if ([_unit, false, true] call FUNC(setDead)) then {
  100.         _damageReturn = 1;
  101.     } else {
  102.         _damageReturn = _damageReturn min 0.89;
  103.     };
  104. } else {
  105.     _damageReturn = _damageReturn min 0.89;
  106. };
  107.  
  108. // Start the loop that tracks the unit vitals
  109. [_unit] call FUNC(addVitalLoop);
  110.  
  111. if (_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)]) exitWith {
  112.     private _delayedUnconsicous = false;
  113.     if (_vehicle != _unit and {damage _vehicle >= 1}) then {
  114.         [_unit] call EFUNC(common,unloadPerson);
  115.         _delayedUnconsicous = true;
  116.     };
  117.  
  118.     if (_damageReturn >= 0.9 && {_selection in ["", "head", "body"]}) exitWith {
  119.         if (_unit getVariable ["ACE_isUnconscious", false]) exitwith {
  120.             [_unit, false, true] call FUNC(setDead);
  121.             0.89;
  122.         };
  123.         if (_delayedUnconsicous) then {
  124.             [{
  125.                 [_this select 0, true] call FUNC(setUnconscious);
  126.             }, [_unit], 0.7] call CBA_fnc_waitAndExecute;
  127.         } else {
  128.             [{
  129.                 [_this select 0, true] call FUNC(setUnconscious);
  130.             }, [_unit]] call CBA_fnc_execNextFrame;
  131.         };
  132.         0.89;
  133.     };
  134.     _damageReturn min 0.89;
  135. };
  136.  
  137. if (((_unit getVariable [QGVAR(enableRevive), GVAR(enableRevive)]) > 0) && {_damageReturn >= 0.9} && {_selection in ["", "head", "body"]}) exitWith {
  138.     if (vehicle _unit != _unit and {damage (vehicle _unit) >= 1}) then {
  139.         [_unit] call EFUNC(common,unloadPerson);
  140.     };
  141.     [_unit, false, true] call FUNC(setDead);
  142.     0.89;
  143. };
  144.  
  145. TRACE_3("ACE_DEBUG: HandleDamage damage return",_selection,_damageReturn,_unit);
  146.  
  147. [] spawn life_fnc_hudUpdate;
  148.  
  149. _damageReturn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement