2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-11-26 15:53:12 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
|
|
|
* Manually Apply Damage to a unit (can cause lethal damage)
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: The Unit <OBJECT>
|
|
|
|
* 1: Damage to Add <NUMBER>
|
2016-10-05 22:54:57 +00:00
|
|
|
* 2: Body part ("Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg") <STRING>
|
2015-11-26 15:53:12 +00:00
|
|
|
* 3: Projectile Type <STRING>
|
2017-04-26 15:16:09 +00:00
|
|
|
* 4: Source <OBJECT>
|
2022-02-17 20:03:12 +00:00
|
|
|
* 5: Unused parameter maintained for backwards compatibility <ARRAY> (default: [])
|
2021-11-08 18:03:59 +00:00
|
|
|
* 6: Override Invulnerability <BOOL> (default: true)
|
2015-11-26 15:53:12 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-03-06 21:06:01 +00:00
|
|
|
* Successful <BOOL>
|
2015-11-26 15:53:12 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2016-10-05 22:54:57 +00:00
|
|
|
* [player, 0.8, "rightleg", "bullet"] call ace_medical_fnc_addDamageToUnit
|
2017-03-06 21:06:01 +00:00
|
|
|
* [cursorTarget, 1, "body", "stab", player] call ace_medical_fnc_addDamageToUnit
|
2015-11-26 15:53:12 +00:00
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
2015-12-05 18:19:34 +00:00
|
|
|
// #define DEBUG_TESTRESULTS
|
2015-11-26 15:53:12 +00:00
|
|
|
|
2021-11-08 18:03:59 +00:00
|
|
|
params [
|
|
|
|
["_unit", objNull, [objNull]],
|
|
|
|
["_damageToAdd", -1, [0]],
|
|
|
|
["_bodyPart", "", [""]],
|
|
|
|
["_typeOfDamage", "", [""]],
|
|
|
|
["_instigator", objNull, [objNull]],
|
2022-02-17 20:03:12 +00:00
|
|
|
"",
|
2021-11-08 18:03:59 +00:00
|
|
|
["_overrideInvuln", true, [true]]
|
|
|
|
];
|
|
|
|
TRACE_7("addDamageToUnit",_unit,_damageToAdd,_bodyPart,_typeOfDamage,_instigator,_damageSelectionArray,_overrideInvuln);
|
2015-11-26 15:53:12 +00:00
|
|
|
|
2024-03-07 21:08:13 +00:00
|
|
|
_bodyPart = toLowerANSI _bodyPart;
|
2019-10-05 20:31:40 +00:00
|
|
|
private _bodyPartIndex = ALL_BODY_PARTS find _bodyPart;
|
2019-10-20 21:48:26 +00:00
|
|
|
if (_bodyPartIndex < 0) then { _bodyPartIndex = ALL_SELECTIONS find _bodyPart; }; // 2nd attempt with selection names ("hand_l", "hand_r", "leg_l", "leg_r")
|
2024-02-05 17:04:24 +00:00
|
|
|
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};
|
2015-11-26 15:53:12 +00:00
|
|
|
|
2021-11-08 18:03:59 +00:00
|
|
|
if (!_overrideInvuln && {!((isDamageAllowed _unit) && {_unit getVariable [QEGVAR(medical,allowDamage), true]})}) exitWith {
|
2024-02-05 17:04:24 +00:00
|
|
|
ERROR_1("addDamageToUnit - unit invulnerable %1",_this); false
|
2021-11-08 18:03:59 +00:00
|
|
|
};
|
|
|
|
|
2017-03-06 21:06:01 +00:00
|
|
|
// Extension is case sensitive and expects this format (different from ALL_BODY_PARTS)
|
|
|
|
_bodyPart = ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"] select _bodyPartIndex;
|
2015-11-26 15:53:12 +00:00
|
|
|
|
2017-03-06 21:06:01 +00:00
|
|
|
if (!isNull _instigator) then {
|
2019-04-27 19:04:31 +00:00
|
|
|
_unit setVariable [QEGVAR(medical,lastDamageSource), _instigator];
|
|
|
|
_unit setVariable [QEGVAR(medical,lastInstigator), _instigator];
|
2017-03-06 21:06:01 +00:00
|
|
|
};
|
2015-11-26 15:53:12 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_TESTRESULTS
|
2019-10-20 21:48:26 +00:00
|
|
|
private _startDmg = +(_unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]]);
|
2018-05-11 14:28:25 +00:00
|
|
|
private _startPain = GET_PAIN(_unit);
|
2015-11-26 15:53:12 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-17 20:03:12 +00:00
|
|
|
[QEGVAR(medical,woundReceived), [_unit, [[_damageToAdd, _bodyPart, _damageToAdd]], _instigator, _typeOfDamage]] call CBA_fnc_localEvent;
|
2017-03-06 21:06:01 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_TESTRESULTS
|
2019-10-20 21:48:26 +00:00
|
|
|
private _endDmg = _unit getVariable [QEGVAR(medical,bodyPartDamage), [0,0,0,0,0,0]];
|
2018-05-11 14:28:25 +00:00
|
|
|
private _endPain = GET_PAIN(_unit);
|
2017-03-06 21:06:01 +00:00
|
|
|
private _typeOfDamageAdj = _typeOfDamage call EFUNC(medical_damage,getTypeOfDamage);
|
|
|
|
private _config = configFile >> "ACE_Medical_Injuries" >> "damageTypes" >> _typeOfDamageAdj;
|
|
|
|
private _selectionSpecific = true;
|
|
|
|
if (isClass _config) then {
|
|
|
|
_selectionSpecific = (getNumber (_config >> "selectionSpecific")) == 1;
|
|
|
|
} else {
|
2024-02-05 17:04:24 +00:00
|
|
|
WARNING_2("Damage type not in config [%1:%2]",_typeOfDamage,_config);
|
2017-03-06 21:06:01 +00:00
|
|
|
};
|
|
|
|
INFO_4("Debug AddDamageToUnit: Type [%1] - Selection Specific [%2] - HitPoint [%3 -> %4]",_typeOfDamage,_selectionSpecific,_startDmg select _bodyPartIndex,_endDmg select _bodyPartIndex);
|
|
|
|
INFO_4("Pain Change [%1 -> %2] - BodyPartDamage Change [%3 -> %4]",_startPain,_endPain,_startDmg,_endDmg);
|
|
|
|
#endif
|
2015-11-26 15:53:12 +00:00
|
|
|
|
2017-03-06 21:06:01 +00:00
|
|
|
true
|