ACE3/addons/hitreactions/functions/fnc_fallDown.sqf

119 lines
3.6 KiB
Plaintext
Raw Normal View History

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
*/
#include "script_component.hpp"
2015-08-13 21:50:51 +00:00
params ["_unit", "_firer", "_damage"];
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 {};
// 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 {
addCamShake [3, 5, _damage + random 10];
};
2015-09-26 19:23:18 +00:00
// play scream sound
if (!isNil QUOTE(EFUNC(medical,playInjuredSound))) then {
[_unit] call EFUNC(medical,playInjuredSound);
};
2015-03-26 15:58:41 +00:00
private "_vehicle";
_vehicle = vehicle _unit;
// 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):
if (_vehicle != _unit) exitWith {};
// 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
if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _unit >> "AGM_isLadder") == 1) exitWith {
_unit action ["LadderOff", nearestObject [position _unit, "House"]];
};
// only play animation when standing due to lack of animations, sry
if !(stance _unit in ["CROUCH", "STAND"]) exitWith {};
private "_velocity";
_velocity = vectorMagnitude velocity _unit;
// only fall when moving
if (_velocity < 2) exitWith {};
// get correct animation by weapon
2015-09-26 19:23:18 +00:00
private "_anim";
call {
private "_weapon";
_weapon = currentWeapon _unit;
if (_weapon == "") exitWith {
_anim = "AmovPercMsprSnonWnonDf_AmovPpneMstpSnonWnonDnon"
};
2015-09-26 19:23:18 +00:00
if (_weapon == primaryWeapon _unit) exitWith {
if ([_unit] call EFUNC(common,isPlayer)) then {
private "_isRunning";
_isRunning = _velocity > 4;
_anim = [
["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning,
["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select _isRunning,
"AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDleft",
"AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright"
] select floor random 4;
} else {
_anim = "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon";
};
};
if (_weapon == handgunWeapon _unit) exitWith {
if ([_unit] call EFUNC(common,isPlayer)) then {
_anim = [
"AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon",
"AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon",
"AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft",
"AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDright"
] select floor random 4;
} else {
_anim = "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon";
};
};
2015-09-26 19:23:18 +00:00
_anim = "";
};
2015-09-26 19:23:18 +00:00
// exit if no animation for this weapon exists, i.e. binocular or rocket launcher
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);
};