2015-09-26 19:23:18 +00:00
/*
* Author: commy2
2015-09-26 19:27:00 +00:00
* Adds reactions to a unit that was hit. EH only runs where to unit is local. Adds screams, falling down, falling from ladders, ejecting from static weapons and camshake for players
2015-09-26 19:23:18 +00:00
*
* Arguments:
* 0: unit <OBJECT>
* 1: firer <OBJECT>
* 2: damage taken <NUMBER>
*
* Return Value:
* None
*
* Public: No
*/
2015-03-26 14:06:51 +00:00
#include "script_component.hpp"
2015-08-13 21:50:51 +00:00
params ["_unit", "_firer", "_damage"];
2015-03-26 14:06:51 +00:00
2015-09-26 19:23:18 +00:00
// exit if system is disabled
if (GVAR(minDamageToTrigger) == -1) exitWith {};
// don't fall after minor damage
if (_damage < GVAR(minDamageToTrigger)) exitWith {};
2015-03-26 14:06:51 +00:00
// don't fall on collision damage
if (_unit == _firer) exitWith {};
2015-09-26 19:23:18 +00:00
// camshake for player
2015-03-26 15:58:41 +00:00
if (_unit == ACE_player) then {
2017-05-10 16:29:26 +00:00
if (visibleMap) then {
openMap false;
};
2015-03-26 15:58:41 +00:00
addCamShake [3, 5, _damage + random 10];
};
2015-09-26 19:23:18 +00:00
// play scream sound
2016-04-08 18:43:26 +00:00
if (!isNil QEFUNC(medical,playInjuredSound)) then {
2015-09-26 19:23:18 +00:00
[_unit] call EFUNC(medical,playInjuredSound);
};
2016-01-06 21:42:02 +00:00
private _vehicle = vehicle _unit;
2015-03-26 15:58:41 +00:00
// handle static weapons
2015-09-26 19:23:18 +00:00
if (_vehicle isKindOf "StaticWeapon") exitWith {
2015-03-26 15:58:41 +00:00
if (!alive _unit) then {
_unit action ["Eject", _vehicle];
unassignVehicle _unit;
};
};
2015-09-26 19:23:18 +00:00
// don't do animations if in a vehicle (looks weird and animations never reset):
2015-05-31 21:16:14 +00:00
if (_vehicle != _unit) exitWith {};
2015-03-26 14:06:51 +00:00
// this checks most things, so it doesn't mess with being inside vehicles or while dragging etc.
2015-03-26 15:58:41 +00:00
if !([_unit, _vehicle] call EFUNC(common,canInteractWith)) exitWith {};
// handle ladders
2016-01-06 21:42:02 +00:00
if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _unit >> "ACE_isLadder") == 1) exitWith {
2015-03-26 15:58:41 +00:00
_unit action ["LadderOff", nearestObject [position _unit, "House"]];
};
2015-03-26 14:06:51 +00:00
// only play animation when standing due to lack of animations, sry
if !(stance _unit in ["CROUCH", "STAND"]) exitWith {};
2016-01-06 21:42:02 +00:00
private _velocity = vectorMagnitude velocity _unit;
2015-03-26 14:06:51 +00:00
// only fall when moving
if (_velocity < 2) exitWith {};
// get correct animation by weapon
2016-01-06 21:42:02 +00:00
private _anim = _unit call FUNC(getRandomAnimation);
2015-03-26 14:06:51 +00:00
2015-09-26 19:23:18 +00:00
// exit if no animation for this weapon exists, i.e. binocular or rocket launcher
2015-03-26 14:06:51 +00:00
if (_anim == "") exitWith {};
// don't mess with transitions. don't fall then.
2015-09-26 19:23:18 +00:00
if !([_unit] call EFUNC(common,inTransitionAnim)) then {
[_unit, _anim, 2] call EFUNC(common,doAnimation);
};