Merge pull request #256 from KoffeinFlummi/hitreactions

fall down after getting shot while moving
This commit is contained in:
commy2 2015-03-26 17:56:51 +01:00
commit d9e59aba3e
10 changed files with 133 additions and 55 deletions

View File

@ -0,0 +1 @@
z\ace\addons\hitreactions

View File

@ -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));
};
};
};

View File

@ -0,0 +1,7 @@
#include "script_component.hpp"
ADDON = false;
PREP(fallDown);
ADDON = true;

View File

@ -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"

View File

@ -0,0 +1,83 @@
// by commy2
#include "script_component.hpp"
private ["_unit", "_firer", "_damage"];
_unit = _this select 0;
_firer = _this select 1;
_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] 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
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);

View File

@ -0,0 +1 @@
#include "\z\ace\addons\hitreactions\script_component.hpp"

View File

@ -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"

View File

@ -59,7 +59,6 @@ PREP(onPropagateWound);
PREP(onCarryObjectDropped);
PREP(parseConfigForInjuries);
PREP(playInjuredSound);
PREP(reactionToDamage);
PREP(selectionNameToNumber);
PREP(setCardiacArrest);
PREP(setDead);

View File

@ -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);

View File

@ -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"];
};
};
};