From 20dd8f34fcc771c7922a75150777beee7f2b4d5e Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 15:06:51 +0100 Subject: [PATCH 1/3] fall down after getting shot while moving --- addons/hitreactions/$PBOPREFIX$ | 1 + addons/hitreactions/CfgEventHandlers.hpp | 14 +++++ addons/hitreactions/XEH_preInit.sqf | 7 +++ addons/hitreactions/config.cpp | 15 +++++ .../hitreactions/functions/fnc_fallDown.sqf | 57 +++++++++++++++++++ .../functions/script_component.hpp | 1 + addons/hitreactions/script_component.hpp | 12 ++++ 7 files changed, 107 insertions(+) create mode 100644 addons/hitreactions/$PBOPREFIX$ create mode 100644 addons/hitreactions/CfgEventHandlers.hpp create mode 100644 addons/hitreactions/XEH_preInit.sqf create mode 100644 addons/hitreactions/config.cpp create mode 100644 addons/hitreactions/functions/fnc_fallDown.sqf create mode 100644 addons/hitreactions/functions/script_component.hpp create mode 100644 addons/hitreactions/script_component.hpp diff --git a/addons/hitreactions/$PBOPREFIX$ b/addons/hitreactions/$PBOPREFIX$ new file mode 100644 index 0000000000..b2a9a05ac5 --- /dev/null +++ b/addons/hitreactions/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\hitreactions \ No newline at end of file diff --git a/addons/hitreactions/CfgEventHandlers.hpp b/addons/hitreactions/CfgEventHandlers.hpp new file mode 100644 index 0000000000..1eea968973 --- /dev/null +++ b/addons/hitreactions/CfgEventHandlers.hpp @@ -0,0 +1,14 @@ + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; + +class Extended_Hit_EventHandlers { + class CAManBase { + class ADDON { + hit = QUOTE(_this call FUNC(fallDown)); + }; + }; +}; diff --git a/addons/hitreactions/XEH_preInit.sqf b/addons/hitreactions/XEH_preInit.sqf new file mode 100644 index 0000000000..d3c0973ee7 --- /dev/null +++ b/addons/hitreactions/XEH_preInit.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +ADDON = false; + +PREP(fallDown); + +ADDON = true; diff --git a/addons/hitreactions/config.cpp b/addons/hitreactions/config.cpp new file mode 100644 index 0000000000..33d2665311 --- /dev/null +++ b/addons/hitreactions/config.cpp @@ -0,0 +1,15 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common"}; + author[] = {"commy2"}; + authorUrl = "https://github.com/commy2"; + VERSION_CONFIG; + }; +}; + +#include "CfgEventHandlers.hpp" diff --git a/addons/hitreactions/functions/fnc_fallDown.sqf b/addons/hitreactions/functions/fnc_fallDown.sqf new file mode 100644 index 0000000000..dc6b9703fd --- /dev/null +++ b/addons/hitreactions/functions/fnc_fallDown.sqf @@ -0,0 +1,57 @@ +// by commy2 +#include "script_component.hpp" + +private "_unit"; + +_unit = _this select 0; +_firer = _this select 1; +_damage = _this select 2; + +// don't fall on collision damage +if (_unit == _firer) exitWith {}; + +// don't fall after minor damage +if (_damage < 0.1) exitWith {}; + +// this checks most things, so it doesn't mess with being inside vehicles or while dragging etc. +if !([_unit, vehicle _unit] call EFUNC(common,canInteractWith)) exitWith {}; + +// 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 +private "_anim"; +_anim = switch (currentWeapon _unit) do { + case (""): {"AmovPercMsprSnonWnonDf_AmovPpneMstpSnonWnonDnon"}; + case (primaryWeapon _unit): { + [ + ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select (_velocity > 4), + ["AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon_2", "AmovPercMsprSlowWrfldf_AmovPpneMstpSrasWrflDnon"] select (_velocity > 4), + "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDleft", + "AmovPercMstpSrasWrflDnon_AadjPpneMstpSrasWrflDright" + ] select floor random 4; + }; + case (handgunWeapon _unit): { + [ + "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", + "AmovPercMsprSlowWpstDf_AmovPpneMstpSrasWpstDnon", + "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDleft", + "AmovPercMstpSrasWpstDnon_AadjPpneMstpSrasWpstDright" + ] select floor random 4; + }; + default {""}; +}; + +// 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. +if ([_unit] call EFUNC(common,inTransitionAnim)) exitWith {}; + +[_unit, _anim, 2] call EFUNC(common,doAnimation); diff --git a/addons/hitreactions/functions/script_component.hpp b/addons/hitreactions/functions/script_component.hpp new file mode 100644 index 0000000000..ba26402e2b --- /dev/null +++ b/addons/hitreactions/functions/script_component.hpp @@ -0,0 +1 @@ +#include "\z\ace\addons\hitreactions\script_component.hpp" \ No newline at end of file diff --git a/addons/hitreactions/script_component.hpp b/addons/hitreactions/script_component.hpp new file mode 100644 index 0000000000..011a3b6c31 --- /dev/null +++ b/addons/hitreactions/script_component.hpp @@ -0,0 +1,12 @@ +#define COMPONENT hitreactions +#include "\z\ace\addons\main\script_mod.hpp" + +#ifdef DEBUG_ENABLED_HITREACTIONS + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_ENABLED_HITREACTIONS + #define DEBUG_SETTINGS DEBUG_ENABLED_HITREACTIONS +#endif + +#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file From cf2b7d3bfbd380d821950a42af039bcfabfc1747 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 15:19:13 +0100 Subject: [PATCH 2/3] private --- addons/hitreactions/functions/fnc_fallDown.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_fallDown.sqf b/addons/hitreactions/functions/fnc_fallDown.sqf index dc6b9703fd..5bfc8332ad 100644 --- a/addons/hitreactions/functions/fnc_fallDown.sqf +++ b/addons/hitreactions/functions/fnc_fallDown.sqf @@ -1,7 +1,7 @@ // by commy2 #include "script_component.hpp" -private "_unit"; +private ["_unit", "_firer", "_damage"]; _unit = _this select 0; _firer = _this select 1; From 9a0f0cb47b512fcd9f2fb0bb66da825f1ec78485 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 26 Mar 2015 16:58:41 +0100 Subject: [PATCH 3/3] stuff from medical --- .../hitreactions/functions/fnc_fallDown.sqf | 28 +++++++++- addons/medical/XEH_preInit.sqf | 1 - .../functions/fnc_handleDamage_advanced.sqf | 2 - .../functions/fnc_reactionToDamage.sqf | 52 ------------------- 4 files changed, 27 insertions(+), 56 deletions(-) delete mode 100644 addons/medical/functions/fnc_reactionToDamage.sqf diff --git a/addons/hitreactions/functions/fnc_fallDown.sqf b/addons/hitreactions/functions/fnc_fallDown.sqf index 5bfc8332ad..ea368b79af 100644 --- a/addons/hitreactions/functions/fnc_fallDown.sqf +++ b/addons/hitreactions/functions/fnc_fallDown.sqf @@ -10,11 +10,37 @@ _damage = _this select 2; // don't fall on collision damage if (_unit == _firer) exitWith {}; +// cam shake for player +if (_unit == ACE_player) then { + addCamShake [3, 5, _damage + random 10]; +}; + +private "_vehicle"; +_vehicle = vehicle _unit; + +// handle static weapons +if (_vehicle isKindOf "StaticWeapon") exitwith { + if (!alive _unit) then { + _unit action ["Eject", _vehicle]; + unassignVehicle _unit; + }; +}; + // don't fall after minor damage if (_damage < 0.1) exitWith {}; +// play sound +if (!isNil QUOTE(EFUNC(medical,playInjuredSound))) then { + [_unit] call EFUNC(medical,playInjuredSound); +}; + // this checks most things, so it doesn't mess with being inside vehicles or while dragging etc. -if !([_unit, vehicle _unit] call EFUNC(common,canInteractWith)) exitWith {}; +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 {}; diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index c72407b199..04fb2364a8 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -59,7 +59,6 @@ PREP(onPropagateWound); PREP(onCarryObjectDropped); PREP(parseConfigForInjuries); PREP(playInjuredSound); -PREP(reactionToDamage); PREP(selectionNameToNumber); PREP(setCardiacArrest); PREP(setDead); diff --git a/addons/medical/functions/fnc_handleDamage_advanced.sqf b/addons/medical/functions/fnc_handleDamage_advanced.sqf index 8d4f14315a..1f943d98d0 100644 --- a/addons/medical/functions/fnc_handleDamage_advanced.sqf +++ b/addons/medical/functions/fnc_handleDamage_advanced.sqf @@ -57,8 +57,6 @@ _unit setvariable [QGVAR(bodyPartStatus), _damageBodyParts, true]; //}; if (alive _unit && {!(_unit getvariable ["ACE_isUnconscious", false])}) then { - [_unit, _newDamage] call FUNC(reactionToDamage); - // If it reaches this, we can assume that the hit did not kill this unit, as this function is called 3 frames after the damage has been passed. if ([_unit, _part, if (_part > 1) then {_newDamage * 1.3} else {_newDamage * 2}] call FUNC(determineIfFatal)) then { [_unit] call FUNC(setUnconscious); diff --git a/addons/medical/functions/fnc_reactionToDamage.sqf b/addons/medical/functions/fnc_reactionToDamage.sqf deleted file mode 100644 index b8c9256bde..0000000000 --- a/addons/medical/functions/fnc_reactionToDamage.sqf +++ /dev/null @@ -1,52 +0,0 @@ -/** - * fn_handleReactionHit.sqf - * @Descr: triggers a reaction to being hit for a unit and spawns on screen effects. - * @Author: Glowbal - * - * @Arguments: [] - * @Return: - * @PublicAPI: false - */ - -#include "script_component.hpp" - -private ["_unit","_amountOfDamage"]; -_unit = _this select 0; -_amountOfDamage = _this select 1; - -if (_amountOfDamage > 0.2) then { - - [_unit] call FUNC(playInjuredSound); - if ((vehicle _unit) isKindOf "StaticWeapon") exitwith { - if (_amountOfDamage > 1) then { - _unit action ["eject", vehicle _unit]; - unassignVehicle _unit; - }; - }; - if (animationState _unit in ["ladderriflestatic","laddercivilstatic"]) exitwith { - _unit action ["ladderOff", (nearestBuilding _unit)]; - }; - - if (vehicle _unit == _unit && [_unit] call EFUNC(common,isAwake)) then { - if (random(1) > 0.5) then { - _unit setDir ((getDir _unit) + 1 + random(30)); - } else { - _unit setDir ((getDir _unit) - (1 + random(30))); - }; - }; - if (_amountOfDamage > 0.6) then { - if (random(1)>0.6) then { - [_unit] call EFUNC(common,setProne); - }; - }; - if (_unit == ACE_player) then { - //76 cutRsc [QGVAR(ScreenEffectsHit),"PLAIN"]; - addCamShake [3, 5, _amountOfDamage + random 10]; - }; -} else { - if (_amountOfDamage > 0) then { - if (_unit == ACE_player) then { - // 76 cutRsc [QGVAR(ScreenEffectsHit),"PLAIN"]; - }; - }; -};