Skip to content

Commit

Permalink
Common - Add setDead API (acemod#10045)
Browse files Browse the repository at this point in the history
* Added `setDead` API

* Update XEH_PREP.hpp

* Update fnc_setDead.sqf

* Update addons/common/functions/fnc_disableUserInput.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* Update fnc_setDead.sqf

* Added warning for non-local units

---------

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
  • Loading branch information
2 people authored and blake8090 committed Aug 18, 2024
1 parent 5043ee8 commit 24ec086
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ PREP(sendRequest);
PREP(serverLog);
PREP(setAimCoef);
PREP(setApproximateVariablePublic);
PREP(setDead);
PREP(setDefinedVariable);
PREP(setDisableUserInputStatus);
PREP(setHearingCapability);
Expand Down
6 changes: 1 addition & 5 deletions addons/common/functions/fnc_disableUserInput.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ if (_state) then {
_ctrl ctrlSetEventHandler ["ButtonClick", toString {
closeDialog 0;

if (["ace_medical"] call FUNC(isModLoaded)) then {
[player, "respawn_button"] call EFUNC(medical_status,setDead);
} else {
player setDamage 1;
};
[player, "respawn_button"] call FUNC(setDead);

[false] call FUNC(disableUserInput);
}];
Expand Down
44 changes: 44 additions & 0 deletions addons/common/functions/fnc_setDead.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "..\script_component.hpp"
/*
* Author: johnb43
* Kills a unit without changing visual appearance.
*
* Arguments:
* 0: Unit <ARRAY>
* 1: Reason for death (only used if ace_medical is loaded) <STRING> (default: "")
* 2: Killer (vehicle that killed unit) <ARRAY> (default: objNull)
* 3: Instigator (unit who pulled trigger) <ARRAY> (default: objNull)
*
* Return Value:
* None
*
* Example:
* [cursorObject, "", player, player] call ace_common_fnc_setDead;
*
* Public: Yes
*/

params [["_unit", objNull, [objNull]], ["_reason", "", [""]], ["_source", objNull, [objNull]], ["_instigator", objNull, [objNull]]];

if (!local _unit) exitWith {
WARNING_1("setDead executed on non-local unit - %1",_this);
};

if (["ace_medical"] call EFUNC(common,isModLoaded)) then {
[_unit, _reason, _source, _instigator] call EFUNC(medical_status,setDead);
} else {
// From 'ace_medical_status_fnc_setDead': Kill the unit without changing visual appearance

// (#8803) Reenable damage if disabled to prevent having live units in dead state
// Keep this after death event for compatibility with third party hooks
if (!isDamageAllowed _unit) then {
WARNING_1("setDead executed on unit with damage blocked - %1",_this);
_unit allowDamage true;
};

private _currentDamage = _unit getHitPointDamage "HitHead";

_unit setHitPointDamage ["HitHead", 1, true, _source, _instigator];

_unit setHitPointDamage ["HitHead", _currentDamage, true, _source, _instigator];
};
6 changes: 1 addition & 5 deletions addons/field_rations/functions/fnc_handleEffects.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ params ["_player", "_thirst", "_hunger"];

// Kill unit with max thirst or hunger
if ((_thirst > 99.9 || {_hunger > 99.9}) && {random 1 < 0.5}) exitWith {
if (["ace_medical"] call EFUNC(common,isModLoaded)) then {
[_player, "Hunger/Thirst empty"] call EFUNC(medical_status,setDead);
} else {
_player setDamage 1;
};
[_player, "Hunger/Thirst empty"] call EFUNC(common,setDead);
};

// Exit if unit is not awake, below are animation based consequences
Expand Down
12 changes: 6 additions & 6 deletions addons/medical_status/functions/fnc_setDead.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
* 0: The unit <OBJECT>
* 1: Reason for death <STRING>
* 2: Killer <OBJECT>
* 3: Instigator <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/

params ["_unit", ["_reason", "#setDead"], ["_instigator", objNull]];
TRACE_3("setDead",_unit,_reason,_instigator);

params ["_unit", ["_reason", "#setDead"], ["_source", objNull], ["_instigator", objNull]];
TRACE_4("setDead",_unit,_reason,_source,_instigator);

// No heart rate or blood pressure to measure when dead
_unit setVariable [VAR_HEART_RATE, 0, true];
Expand All @@ -38,14 +38,14 @@ if (_unitState isNotEqualTo "Dead") then {

// (#8803) Reenable damage if disabled to prevent having live units in dead state
// Keep this after death event for compatibility with third party hooks
if !(isDamageAllowed _unit) then {
if (!isDamageAllowed _unit) then {
WARNING_1("setDead executed on unit with damage blocked - %1",_this);
_unit allowDamage true;
};

// Kill the unit without changing visual apperance
private _prevDamage = _unit getHitPointDamage "HitHead";

_unit setHitPointDamage ["HitHead", 1, true, _instigator];
_unit setHitPointDamage ["HitHead", 1, true, _source, _instigator];

_unit setHitPointDamage ["HitHead", _prevDamage];
_unit setHitPointDamage ["HitHead", _prevDamage, true, _source, _instigator];

0 comments on commit 24ec086

Please sign in to comment.