Skip to content

Commit

Permalink
Vehicle Damage - Fix applying medical damage to non-local and invulne…
Browse files Browse the repository at this point in the history
…rable units (acemod#9988)

* Make medical damage apply to non-local units

* Update addons/vehicle_damage/functions/fnc_medicalDamage.sqf

Co-authored-by: PabstMirror <[email protected]>

* Update addons/vehicle_damage/functions/fnc_medicalDamage.sqf

* Update fnc_medicalDamage.sqf

* Specify reason for death

---------

Co-authored-by: PabstMirror <[email protected]>
  • Loading branch information
2 people authored and blake8090 committed Aug 18, 2024
1 parent 24ec086 commit 1ff5886
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions addons/vehicle_damage/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ PREP(knockOut);
PREP(addDamage);
PREP(handleDamageEjectIfDestroyed);
PREP(blowOffTurret);
PREP(medicalDamage);
2 changes: 2 additions & 0 deletions addons/vehicle_damage/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
["ace_settingsInitialized", {
TRACE_1("settings init",GVAR(enabled));
if (GVAR(enabled)) then {
[QGVAR(medicalDamage), LINKFUNC(medicalDamage)] call CBA_fnc_addEventHandler;

[QGVAR(bailOut), {
params ["_center", "_crewman", "_vehicle"];
TRACE_3("bailOut",_center,_crewman,_vehicle);
Expand Down
7 changes: 2 additions & 5 deletions addons/vehicle_damage/functions/fnc_detonate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ if (_vehicleAmmo isEqualTo []) then {

if ((_vehicleAmmo select 1) > 0) then {
{
// random amount of injuries
for "_i" from 0 to random 5 do {
[_x, random 1 , selectRandom ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"], selectRandom ["bullet", "shell", "explosive"], _injurer] call EFUNC(medical,addDamageToUnit);
};
} forEach crew _vehicle;
[QGVAR(medicalDamage), [_x, _injurer, _injurer], _x] call CBA_fnc_targetEvent;
} forEach (crew _vehicle);
};
39 changes: 39 additions & 0 deletions addons/vehicle_damage/functions/fnc_medicalDamage.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Applies medical damage to a unit.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Source <OBJECT>
* 2: Instigator <OBJECT>
* 3: Guarantee death? <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* [cursorObject, player, player] call ace_vehicle_damage_fnc_medicalDamage;
*
* Public: No
*/

params ["_unit", "_source", "_instigator", ["_guaranteeDeath", false]];

// Check if unit is invulnerable
if !(isDamageAllowed _unit && {_unit getVariable [QEGVAR(medical,allowDamage), true]}) exitWith {};

if (["ace_medical"] call EFUNC(common,isModLoaded)) then {
for "_i" from 0 to floor (4 + random 3) do {
[_unit, random [0, 0.66, 1], selectRandom ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"], selectRandom ["bullet", "shell", "explosive"], _instigator] call EFUNC(medical,addDamageToUnit);
};
} else {
{
_unit setHitPointDamage [_x, (_unit getHitPointDamage _x) + random [0, 0.66, 1], true, _source, _instigator];
} forEach ["HitFace", "HitNeck", "HitHead", "HitPelvis", "HitAbdomen", "HitDiaphragm", "HitChest", "HitBody", "HitArms", "HitHands", "HitLegs"];
};

// If guaranteed death is wished
if (_guaranteeDeath && {alive _unit}) then {
[_unit, QGVAR(medicalDamage), _source, _instigator] call EFUNC(common,setDead);
};
8 changes: 3 additions & 5 deletions addons/vehicle_damage/functions/fnc_processHit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ if (_newDamage >= 15) exitWith {
TRACE_2("immediate destruction - high damage",_newDamage,_currentPartDamage);
[_vehicle] call FUNC(knockOut);
[_vehicle, 1] call FUNC(handleDetonation);
// kill everyone inside for very insane damage
// Kill everyone inside for very insane damage
{
_x setDamage 1;
_x setVariable [QEGVAR(medical,lastDamageSource), _injurer];
_x setVariable [QEGVAR(medical,lastInstigator), _injurer];
} forEach crew _vehicle;
[QGVAR(medicalDamage), [_x, _injurer, _injurer, true], _x] call CBA_fnc_targetEvent;
} forEach (crew _vehicle);
_vehicle setDamage 1;
_return = false;
_return
Expand Down

0 comments on commit 1ff5886

Please sign in to comment.