2015-02-28 19:46:36 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi
|
2015-03-17 06:53:50 +00:00
|
|
|
* My very own setHitPointDamage since BIS' one is buggy when affecting a remote unit.
|
2015-02-28 19:46:36 +00:00
|
|
|
* It also doesn't change the overall damage. This does.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: HitPoint <STRING>
|
|
|
|
* 2: Damage <NUMBER>
|
2015-08-22 17:47:23 +00:00
|
|
|
* 3: Disable overall damage adjustment <BOOL> (default: false)
|
2015-02-28 19:46:36 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-08-22 17:47:23 +00:00
|
|
|
* None
|
2015-02-28 19:46:36 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [medic, "Leg", 2, false] call ace_medical_fnc_setHitPointDamage
|
|
|
|
*
|
2015-02-28 19:46:36 +00:00
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
2015-03-17 06:53:50 +00:00
|
|
|
#define LEGDAMAGETRESHOLD1 1
|
|
|
|
#define LEGDAMAGETRESHOLD2 1.7
|
|
|
|
#define ARMDAMAGETRESHOLD1 1
|
|
|
|
#define ARMDAMAGETRESHOLD2 1.7
|
2015-02-28 19:46:36 +00:00
|
|
|
|
2015-08-23 12:13:55 +00:00
|
|
|
params ["_unit", "_selection", "_damage", ["_disabled", false]];
|
2015-02-28 19:46:36 +00:00
|
|
|
|
|
|
|
// Unit isn't local, give function to machine where it is.
|
|
|
|
if !(local _unit) exitWith {
|
2016-06-03 18:57:21 +00:00
|
|
|
[QGVAR(setHitPointDamage), _this, _unit] call CBA_fnc_targetEvent;
|
2015-02-28 19:46:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check if overall damage adjustment is disabled
|
2015-08-23 12:13:55 +00:00
|
|
|
if (_disabled) exitWith {
|
2015-02-28 19:46:36 +00:00
|
|
|
_unit setHitPointDamage [_selection, _damage];
|
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _selections = [
|
2015-02-28 19:46:36 +00:00
|
|
|
"HitHead",
|
|
|
|
"HitBody",
|
|
|
|
"HitLeftArm",
|
|
|
|
"HitRightArm",
|
|
|
|
"HitLeftLeg",
|
|
|
|
"HitRightLeg"
|
|
|
|
];
|
|
|
|
|
|
|
|
if !(_selection in _selections) exitWith {
|
|
|
|
_unit setHitPointDamage [_selection, _damage];
|
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damages = _selections apply {_unit getHitPointDamage _x};
|
2015-02-28 19:46:36 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageOld = damage _unit;
|
|
|
|
private _damageSumOld = 0;
|
2015-02-28 19:46:36 +00:00
|
|
|
{
|
|
|
|
_damageSumOld = _damageSumOld + _x;
|
|
|
|
} forEach _damages;
|
|
|
|
_damageSumOld = _damageSumOld max 0.001;
|
|
|
|
|
|
|
|
_damages set [_selections find _selection, _damage];
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageSumNew = 0;
|
2015-02-28 19:46:36 +00:00
|
|
|
{
|
|
|
|
_damageSumNew = _damageSumNew + _x;
|
|
|
|
} forEach _damages;
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageNew = _damageSumNew / 6;
|
2015-02-28 19:46:36 +00:00
|
|
|
if (_damageOld > 0) then {
|
|
|
|
_damageNew = _damageOld * (_damageSumNew / _damageSumOld);
|
|
|
|
};
|
|
|
|
|
2015-04-04 14:28:09 +00:00
|
|
|
// prevent death
|
|
|
|
if (_damageNew >= 0.9) then {
|
|
|
|
_unit setDamage 0.9;
|
|
|
|
[_unit] call FUNC(setDead);
|
|
|
|
} else {
|
|
|
|
_unit setDamage _damageNew;
|
|
|
|
};
|
2015-02-28 19:46:36 +00:00
|
|
|
|
|
|
|
{
|
2017-10-10 14:39:59 +00:00
|
|
|
private _damageFinal = (_damages select _forEachIndex);
|
2015-02-28 19:46:36 +00:00
|
|
|
_unit setHitPointDamage [_x, _damageFinal];
|
|
|
|
} forEach _selections;
|
2015-03-17 06:53:50 +00:00
|
|
|
|
|
|
|
// Leg Damage
|
2017-10-10 14:39:59 +00:00
|
|
|
private _legdamage = (_unit getHitPointDamage "HitLeftLeg") + (_unit getHitPointDamage "HitRightLeg");
|
2015-03-17 06:53:50 +00:00
|
|
|
if (_legdamage >= LEGDAMAGETRESHOLD1) then {
|
|
|
|
if (_unit getHitPointDamage "HitLegs" != 1) then {_unit setHitPointDamage ["HitLegs", 1]};
|
|
|
|
} else {
|
|
|
|
if (_unit getHitPointDamage "HitLegs" != 0) then {_unit setHitPointDamage ["HitLegs", 0]};
|
|
|
|
};
|
2015-04-04 14:28:09 +00:00
|
|
|
// @todo: force prone for completely fucked up legs.
|
2015-03-17 06:53:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Arm Damage
|
2017-10-10 14:39:59 +00:00
|
|
|
private _armdamage = (_unit getHitPointDamage "HitLeftArm") + (_unit getHitPointDamage "HitRightArm");
|
2015-03-17 06:53:50 +00:00
|
|
|
if (_armdamage >= ARMDAMAGETRESHOLD1) then {
|
|
|
|
if (_unit getHitPointDamage "HitHands" != 1) then {_unit setHitPointDamage ["HitHands", 1]};
|
|
|
|
} else {
|
|
|
|
if (_unit getHitPointDamage "HitHands" != 0) then {_unit setHitPointDamage ["HitHands", 0]};
|
|
|
|
};
|
|
|
|
// @todo: Drop weapon for full damage.
|