2015-02-03 19:09:25 +00:00
|
|
|
/*
|
2015-02-28 18:22:46 +00:00
|
|
|
* Author: KoffeinFlummi, Glowbal
|
2015-02-03 19:09:25 +00:00
|
|
|
* Main HandleDamage EH function.
|
2015-01-18 21:16:35 +00:00
|
|
|
*
|
2015-02-03 19:09:25 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: Unit That Was Hit <OBJECT>
|
|
|
|
* 1: Name Of Hit Selection <STRING>
|
|
|
|
* 2: Amount Of Damage <NUMBER>
|
|
|
|
* 3: Shooter <OBJECT>
|
|
|
|
* 4: Projectile <OBJECT/STRING>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Damage To Be Inflicted <NUMBER>
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-18 21:16:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-04-30 23:34:38 +00:00
|
|
|
private ["_unit", "_selection", "_damage", "_shooter", "_projectile", "_damageReturn", "_typeOfDamage", "_minLethalDamage", "_newDamage", "_typeIndex", "_preventDeath"];
|
|
|
|
_unit = _this select 0;
|
|
|
|
_selection = _this select 1;
|
|
|
|
_damage = _this select 2;
|
|
|
|
_shooter = _this select 3;
|
|
|
|
_projectile = _this select 4;
|
2015-01-20 17:57:33 +00:00
|
|
|
|
2015-02-06 12:47:17 +00:00
|
|
|
if !(local _unit) exitWith {nil};
|
|
|
|
|
|
|
|
if (typeName _projectile == "OBJECT") then {
|
|
|
|
_projectile = typeOf _projectile;
|
|
|
|
_this set [4, _projectile];
|
2015-01-18 21:16:35 +00:00
|
|
|
};
|
|
|
|
|
2015-02-06 12:47:17 +00:00
|
|
|
// If the damage is being weird, we just tell it to fuck off.
|
2015-04-11 20:30:52 +00:00
|
|
|
if !(_selection in (GVAR(SELECTIONS) + [""])) exitWith {0};
|
2015-02-06 12:47:17 +00:00
|
|
|
|
2015-04-30 23:38:36 +00:00
|
|
|
// Exit if we disable damage temporarily
|
|
|
|
_damageOld = damage _unit;
|
|
|
|
if (_selection in GVAR(SELECTIONS)) then {
|
|
|
|
_damageOld = _unit getHit _selection;
|
|
|
|
};
|
|
|
|
if !(_unit getVariable [QGVAR(allowDamage), true]) exitWith {_damageOld};
|
|
|
|
|
|
|
|
// Figure out whether to prevent death before handling damage
|
|
|
|
if (diag_frameno > (_unit getVariable [QGVAR(frameNo), -3]) + 2) then {
|
|
|
|
_unit setVariable [QGVAR(frameNo), diag_frameno];
|
|
|
|
_unit setVariable [QGVAR(wasUnconscious), _unit getVariable ["ACE_isUnconscious", false]];
|
|
|
|
|
|
|
|
_preventDeath = _unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)];
|
|
|
|
if (_unit getVariable ["ACE_isUnconscious", false]) then {
|
|
|
|
_preventDeath = _unit getVariable [QGVAR(enableRevive), GVAR(enableRevive)];
|
|
|
|
if !([_unit] call EFUNC(common,isPlayer)) then {
|
|
|
|
_preventDeath = _preventDeath - 1;
|
|
|
|
};
|
|
|
|
_preventDeath = _preventDeath > 0;
|
|
|
|
};
|
|
|
|
_unit setVariable [QGVAR(preventDeath), _preventDeath];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get return damage
|
2015-02-06 12:47:17 +00:00
|
|
|
_damageReturn = _damage;
|
2015-04-03 20:40:36 +00:00
|
|
|
if (GVAR(level) < 2) then {
|
2015-04-03 19:59:47 +00:00
|
|
|
_damageReturn = _this call FUNC(handleDamage_basic);
|
2015-04-29 20:54:58 +00:00
|
|
|
} else {
|
2015-04-03 20:40:36 +00:00
|
|
|
if !([_unit] call FUNC(hasMedicalEnabled)) exitwith {
|
|
|
|
// Because of the config changes, we cannot properly disable the medical system for a unit.
|
|
|
|
// lets use basic for the time being..
|
2015-04-04 14:27:44 +00:00
|
|
|
_damageReturn = _this call FUNC(handleDamage_basic);
|
2015-04-03 20:40:36 +00:00
|
|
|
};
|
2015-04-11 20:30:52 +00:00
|
|
|
_newDamage = _this call FUNC(handleDamage_caching);
|
2015-04-29 20:54:58 +00:00
|
|
|
_typeOfDamage = [_projectile] call FUNC(getTypeOfDamage);
|
2015-02-13 21:55:13 +00:00
|
|
|
|
2015-04-29 20:54:58 +00:00
|
|
|
_typeIndex = (GVAR(allAvailableDamageTypes) find _typeOfDamage);
|
|
|
|
_minLethalDamage = 0.01;
|
|
|
|
if (_typeIndex >= 0) then {
|
|
|
|
_minLethalDamage = GVAR(minLethalDamages) select _typeIndex;
|
|
|
|
};
|
2015-04-05 13:51:28 +00:00
|
|
|
|
2015-04-30 06:17:26 +00:00
|
|
|
if (vehicle _unit != _unit && {!(vehicle _unit isKindOf "StaticWeapon")} && {isNull _shooter} && {_projectile == ""} && {_selection == ""}) then {
|
2015-04-29 20:54:58 +00:00
|
|
|
if (GVAR(enableVehicleCrashes)) then {
|
|
|
|
_selection = GVAR(SELECTIONS) select (floor(random(count GVAR(SELECTIONS))));
|
2015-04-05 13:51:28 +00:00
|
|
|
};
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
2015-04-02 20:57:35 +00:00
|
|
|
|
2015-04-29 20:54:58 +00:00
|
|
|
if ((_minLethalDamage <= _newDamage) && {[_unit, [_selection] call FUNC(selectionNameToNumber), _newDamage] call FUNC(determineIfFatal)} || !alive vehicle _unit) then {
|
|
|
|
if ((_unit getVariable [QGVAR(preventInstaDeath), GVAR(preventInstaDeath)])) exitwith {
|
|
|
|
_damageReturn = 0.9;
|
2015-04-17 21:15:41 +00:00
|
|
|
};
|
2015-04-29 21:44:47 +00:00
|
|
|
if ([_unit] call FUNC(setDead)) then {
|
2015-04-29 20:54:58 +00:00
|
|
|
_damageReturn = 1;
|
2015-02-28 18:22:46 +00:00
|
|
|
} else {
|
2015-04-27 14:36:00 +00:00
|
|
|
_damageReturn = _damageReturn min 0.89;
|
2015-02-28 18:22:46 +00:00
|
|
|
};
|
2015-04-29 20:54:58 +00:00
|
|
|
} else {
|
|
|
|
_damageReturn = _damageReturn min 0.89;
|
|
|
|
};
|
2015-01-18 21:16:35 +00:00
|
|
|
};
|
2015-03-05 17:42:08 +00:00
|
|
|
[_unit] call FUNC(addToInjuredCollection);
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2015-04-30 23:38:36 +00:00
|
|
|
// Prevent death if necessary
|
|
|
|
if (_unit getVariable QGVAR(preventDeath)) then {
|
|
|
|
if (_selection in ["", "head", "body"]) then {
|
|
|
|
_damageReturn = _damageReturn min 0.89;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Move the unit out of the vehicle if necessary
|
|
|
|
if (vehicle _unit != _unit and damage (vehicle _unit) == 1) then {
|
|
|
|
[_unit] call EFUNC(common,unloadPerson);
|
|
|
|
if (_unit getVariable QGVAR(wasUnconscious)) then {
|
2015-04-29 20:54:58 +00:00
|
|
|
[_unit] call FUNC(setDead);
|
2015-04-30 23:38:36 +00:00
|
|
|
} else {
|
|
|
|
[_unit, true] call FUNC(setUnconscious);
|
2015-04-29 20:54:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-04-30 23:38:36 +00:00
|
|
|
// Temporarily disable all damage to prevent stuff like
|
|
|
|
// being killed during the animation etc.
|
|
|
|
if (!_wasUnconscious and (_unit getVariable ["ACE_isUnconscious", false])) then {
|
|
|
|
_unit setVariable [QGVAR(allowDamage), false];
|
|
|
|
[{
|
|
|
|
_this setVariable [QGVAR(allowDamage), true];
|
|
|
|
}, _unit, 0.7, 0] call EFUNC(common,waitAndExecute);
|
2015-02-10 12:33:40 +00:00
|
|
|
};
|
2015-01-18 21:16:35 +00:00
|
|
|
};
|
2015-02-07 22:48:24 +00:00
|
|
|
|
2015-02-03 19:09:25 +00:00
|
|
|
_damageReturn
|