All pastes #2081964 Raw Edit

Unnamed

public text v1 · immutable
#2081964 ·published 2011-09-21 22:23 UTC
rendered paste body
// #define DEBUG_MODE_FULL
#include "script_component.hpp"

#define __unitcfg configFile >> "cfgVehicles" >> _to
#define __ammocfg configFile >> "cfgAmmo" >> _ammo

/*

0: injured [Object]
1: part hit [String]
2: new overall part damage [Number]
3: injurer [Object]
4: class of ammo causing the damage [String]

For each hit this EH triggers 5 times within a frame, always in this sequence of parts:
1. "" - info on overall damage
2. "head_hit"
3. "body"
4. "hands"
5. "legs"

Multiple hits within one frame are handled one by one, not causing mixups
(1-2-3-4-5 - 1-2-3-4-5  - etc)

All 5 will trigger if at least 1 of the parts receives non-zero damage.
Damage values causing the triggering may be as low as 0.0001, so filtering might be advised.

Triggered by falling or collisions returns the unit itself as the injurer, ammo class is an empty string.
Example: [unit1,"head_hit",0.000253947,unit1,""]

Damage in destroyed vehicles only triggers the 1st type (""), then unit ejects.

using BIS configs:
head_hit:
armor = 0.6;  ==  no helmet
armor = 0.7; == for example pilot helmet
armor = 0.85; == normal helmet

body:
armor = 1;
passThrough = 0.8; == bulletproof west

armor = 0.8;
passThrough = 1; == NO bulletproof west


by q1184
*/
private "_isp";
PARAMS_1(_u);
_isp = isPlayer _u;

if ((isNil "ace_sys_wounds_enabled") || (!_isp && !isNil "ace_sys_wounds_noai")) then {
	if (!alive _u) then {
		_hdh = _u getVariable QUOTE(GVAR(hdeh));
		if (!isNil "_hdh") then {
			_u removeEventHandler ["handleDamage", _hdh];
			_u setVariable [QUOTE(GVAR(hdeh)), nil];
		};
	};
	if (_isp) then {if (vehicle _u == _u) then {[_u, _this select 4, ""] call FUNC(effect)}};
	if (!isNil {_unit getVariable "ace_w_allow_dam"}) then { 0 } else { _this select 2 };
} else {
    //hint "blah";
	_unit       = _this select 0;
	_part       = _this select 1;

	if (_part == "") then {
		_unit setVariable [QUOTE(GVAR(hds)), [_this]];
		_unit setVariable [QUOTE(GVAR(handled)), false];
	} else {
		if (!(_unit getVariable [QUOTE(GVAR(handled)), false])) then {
			_unit setVariable [QUOTE(GVAR(hds)), (_unit getVariable QUOTE(GVAR(hds))) + [_this]];

			if (_part == "body") then { // check for head hit
				_hds    = _unit getVariable QUOTE(GVAR(hds));
				_hdHead = _hds select 1;
				_hdBody = _hds select 2;
				if (_hdHead select 2 > _hdBody select 2) then { // hit in the head
					_hdHead call FUNC(hd3);
				};
			};

			if (_part == "hands") then {
				// last chance to go to hd3 if legs don't fire
				_hds    = _unit getVariable QUOTE(GVAR(hds));
				_hdTotal = _hds select 0;
				_hdHead  = _hds select 1;
				_hdBody  = _hds select 2;
				_hdHands = _hds select 3;
				//if (_hdHead select 2 > 0.5 * (_hdBody select 2)) then { // upper body hit, resolve now
				if (_hdHead select 2 > 0) then { // upper body hit, resolve now
					hint "2";
					_hdHit = _hdBody;
					if ( (_hdHands select 2 >= 2 * (_hdBody select 2)) ) then {
						_hdHit = _hdHands;
					};
					_hdHit call FUNC(hd3);
				}
			};

			if (_part == "legs") then { // last hit
				// determine hit location
				_hds    = _unit getVariable QUOTE(GVAR(hds));
				_hdTotal = _hds select 0;
				_hdHead  = _hds select 1;
				_hdBody  = _hds select 2;
				_hdHands = _hds select 3;
				_hdLegs  = _hds select 4;

				_hdHit = _hdBody;
				if ( (_hdHands select 2 >= 2 * (_hdBody select 2)) && (_hdHands select 2 >= 0.33 * (_hdLegs select 2)) ) then {
					_hdHit = _hdHands;
				};
				if ( (_hdLegs select 2 >= _hdBody select 2) && (_hdLegs select 2 >= 3 * (_hdHands select 2)) ) then {
					_hdHit = _hdLegs;
				};

				_hdHit call FUNC(hd3);
			};
		};
	};

	//_this call FUNC(hd2);
};