From f9d181c72e3cf1b3a93efb51dad75f4fb4c0f35d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 20 Oct 2019 16:48:26 -0500 Subject: [PATCH] Medical - Fix addDamageToUnit (#7247) --- .../medical/functions/fnc_addDamageToUnit.sqf | 18 +++++++++++------- .../functions/fnc_handleDamage.sqf | 6 +++--- .../overpressure/functions/fnc_firedEHBB.sqf | 2 +- .../functions/fnc_overpressureDamage.sqf | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/addons/medical/functions/fnc_addDamageToUnit.sqf b/addons/medical/functions/fnc_addDamageToUnit.sqf index 4e2561438e..f571d27726 100644 --- a/addons/medical/functions/fnc_addDamageToUnit.sqf +++ b/addons/medical/functions/fnc_addDamageToUnit.sqf @@ -2,7 +2,6 @@ /* * Author: PabstMirror * Manually Apply Damage to a unit (can cause lethal damage) - * NOTE: because of caching, this will not have instant effects (~3 frame delay) * * Arguments: * 0: The Unit @@ -10,6 +9,7 @@ * 2: Body part ("Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg") * 3: Projectile Type * 4: Source + * 5: Non-directional damage source array (Optional) * * Return Value: * Successful @@ -22,12 +22,12 @@ */ // #define DEBUG_TESTRESULTS -params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]], ["_instigator", objNull, [objNull]]]; -TRACE_5("addDamageToUnit",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator); +params [["_unit", objNull, [objNull]], ["_damageToAdd", -1, [0]], ["_bodyPart", "", [""]], ["_typeOfDamage", "", [""]], ["_instigator", objNull, [objNull]], ["_damageSelectionArray", [], [[]]]]; +TRACE_6("addDamageToUnit",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator,_damageSelectionArray); _bodyPart = toLower _bodyPart; private _bodyPartIndex = ALL_BODY_PARTS find _bodyPart; -if (_bodyPartIndex < 0) then { _bodyPartIndex = ALL_SELECTIONS find _bodyPart; }; // 2nd attempt with selection names ("hand_l", "hand_r", "leg_l", "leg_r") +if (_bodyPartIndex < 0) then { _bodyPartIndex = ALL_SELECTIONS find _bodyPart; }; // 2nd attempt with selection names ("hand_l", "hand_r", "leg_l", "leg_r") if (_bodyPartIndex < 0) exitWith {ERROR_1("addDamageToUnit - bad selection %1", _this); false}; if (isNull _unit || {!local _unit} || {!alive _unit}) exitWith {ERROR_2("addDamageToUnit - badUnit %1 [local %2]", _this, local _unit); false}; if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this); false}; @@ -35,20 +35,24 @@ if (_damageToAdd < 0) exitWith {ERROR_1("addDamageToUnit - bad damage %1", _this // Extension is case sensitive and expects this format (different from ALL_BODY_PARTS) _bodyPart = ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"] select _bodyPartIndex; +if (_damageSelectionArray isEqualTo []) then { // this will only be used if damage type is not location specific + _damageSelectionArray = [HITPOINT_INDEX_HEAD, 1, HITPOINT_INDEX_BODY, 1, HITPOINT_INDEX_LARM, 1, HITPOINT_INDEX_RARM, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1]; +}; + if (!isNull _instigator) then { _unit setVariable [QEGVAR(medical,lastDamageSource), _instigator]; _unit setVariable [QEGVAR(medical,lastInstigator), _instigator]; }; #ifdef DEBUG_TESTRESULTS -private _startDmg = +(_unit getVariable [QEGVAR(medical,bodyPartDamage), [-1]]); +private _startDmg = +(_unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]); private _startPain = GET_PAIN(_unit); #endif -[QEGVAR(medical,woundReceived), [_unit, _bodyPart, _damageToAdd, _instigator, _typeOfDamage]] call CBA_fnc_localEvent; +[QEGVAR(medical,woundReceived), [_unit, _bodyPart, _damageToAdd, _instigator, _typeOfDamage, _damageSelectionArray]] call CBA_fnc_localEvent; #ifdef DEBUG_TESTRESULTS -private _endDmg = _unit getVariable [QEGVAR(medical,bodyPartDamage), [-1]]; +private _endDmg = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]; private _endPain = GET_PAIN(_unit); private _typeOfDamageAdj = _typeOfDamage call EFUNC(medical_damage,getTypeOfDamage); private _config = configFile >> "ACE_Medical_Injuries" >> "damageTypes" >> _typeOfDamageAdj; diff --git a/addons/medical_engine/functions/fnc_handleDamage.sqf b/addons/medical_engine/functions/fnc_handleDamage.sqf index 000c90b911..19240824aa 100644 --- a/addons/medical_engine/functions/fnc_handleDamage.sqf +++ b/addons/medical_engine/functions/fnc_handleDamage.sqf @@ -118,10 +118,10 @@ if (_hitPoint isEqualTo "ace_hdbracket") exitWith { */ if (_shooter == _unit && {(velocity _unit select 2) < -2}) then { _ammo = "#falling"; // non-selectionSpecific so only _damageSelectionArray matters - _damageSelectionArray = [4, 1, 5, 1]; // selectRandom ["RightLeg", "LeftLeg"]; + _damageSelectionArray = [HITPOINT_INDEX_RLEG, 1, HITPOINT_INDEX_LLEG, 1]; TRACE_5("Fall",_unit,_shooter,_instigator,_damage,_receivedDamage); } else { - _damageSelectionArray = [2, 1, 3, 1, 4, 1, 5, 1]; // selectRandom ["RightArm", "LeftArm", "RightLeg", "LeftLeg"]; + _damageSelectionArray = [HITPOINT_INDEX_RARM, 1, HITPOINT_INDEX_LARM, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1]; TRACE_5("Collision",_unit,_shooter,_instigator,_damage,_receivedDamage); }; @@ -138,7 +138,7 @@ if (_hitPoint isEqualTo "ace_hdbracket") exitWith { }; } else { // Anything else is almost guaranteed to be fire damage - _damageSelectionArray = [1, 1, 4, 1, 5, 1]; // selectRandom ["Body", "LeftLeg", "RightLeg"]; + _damageSelectionArray = [HITPOINT_INDEX_BODY, 1, HITPOINT_INDEX_LLEG, 1, HITPOINT_INDEX_RLEG, 1];; _ammo = "#unknown"; // non-selectionSpecific so only _damageSelectionArray matters // Fire damage can occur as lots of minor damage events diff --git a/addons/overpressure/functions/fnc_firedEHBB.sqf b/addons/overpressure/functions/fnc_firedEHBB.sqf index fc5070e8a8..2d1d0f783c 100644 --- a/addons/overpressure/functions/fnc_firedEHBB.sqf +++ b/addons/overpressure/functions/fnc_firedEHBB.sqf @@ -52,7 +52,7 @@ if (_distance < _backblastRange) then { [_damage * 100] call BIS_fnc_bloodEffect; if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { - [_unit, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); + [_unit, _damage, "body", "backblast", _unit] call EFUNC(medical,addDamageToUnit); } else { TRACE_1("",isDamageAllowed _unit); if (!isDamageAllowed _unit) exitWith {}; // Skip damage if not allowed diff --git a/addons/overpressure/functions/fnc_overpressureDamage.sqf b/addons/overpressure/functions/fnc_overpressureDamage.sqf index b648d291d0..c898347969 100644 --- a/addons/overpressure/functions/fnc_overpressureDamage.sqf +++ b/addons/overpressure/functions/fnc_overpressureDamage.sqf @@ -57,7 +57,7 @@ TRACE_3("cache",_overpressureAngle,_overpressureRange,_overpressureDamage); if (_x == ACE_player) then {[_damage * 100] call BIS_fnc_bloodEffect}; if (isClass (configFile >> "CfgPatches" >> "ACE_Medical")) then { - [_x, _damage, "body", "backblast"] call EFUNC(medical,addDamageToUnit); + [_x, _damage, "body", "backblast", _firer] call EFUNC(medical,addDamageToUnit); } else { TRACE_1("",isDamageAllowed _x); if (!isDamageAllowed _x) exitWith {}; // Skip damage if not allowed