Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Add setDead API #10045

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];