From a9296f66d58dab75717d1e544009867da441e18c Mon Sep 17 00:00:00 2001 From: GhostIsSpooky <69561145+Salluci@users.noreply.github.com> Date: Mon, 15 Nov 2021 12:31:56 -0300 Subject: [PATCH] Medical - Update `setDead` to use `setHitpointDamage` instigator param (#8397) * Redoing this * Revert "Redoing this" This reverts commit 80ff709676c0e9ddd25992edde1e578523417686. * Do this properly * Update fnc_handleKilled.sqf * use setDead function directly * Handle scripted camera * redo #8387 I'm dumb. * try this * if construct outside of ctrlSetEventHandler Co-authored-by: Filip Maciejewski * tweak disableUserInput / handleKilled Co-authored-by: Filip Maciejewski Co-authored-by: PabstMirror --- .../common/functions/fnc_disableUserInput.sqf | 10 +++++++--- .../functions/fnc_enteredStateDeath.sqf | 3 ++- .../functions/fnc_handleKilled.sqf | 18 ++++++++++-------- .../functions/fnc_handleKilledMission.sqf | 14 +++++++------- .../medical_status/functions/fnc_initUnit.sqf | 3 +++ .../medical_status/functions/fnc_setDead.sqf | 11 ++++++++--- .../functions/fnc_placeInBodyBag.sqf | 2 +- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/addons/common/functions/fnc_disableUserInput.sqf b/addons/common/functions/fnc_disableUserInput.sqf index 514fa3601c..006f097266 100644 --- a/addons/common/functions/fnc_disableUserInput.sqf +++ b/addons/common/functions/fnc_disableUserInput.sqf @@ -66,9 +66,13 @@ if (_state) then { _ctrl ctrlSetTooltip "Abort."; _ctrl = _dlg displayctrl ([104, 1010] select isMultiplayer); - _ctrl ctrlSetEventHandler ["buttonClick", QUOTE(closeDialog 0; player setDamage 1; [false] call DFUNC(disableUserInput);)]; - _ctrl ctrlEnable (call {private _config = missionConfigFile >> "respawnButton"; !isNumber _config || {getNumber _config == 1}}); - _ctrl ctrlSetText "RESPAWN"; + if (["ace_medical"] call FUNC(isModLoaded)) then { + _ctrl ctrlSetEventHandler ["buttonClick", 'closeDialog 0; [player, "respawn_button"] call EFUNC(medical_status,setDead); [false] call DFUNC(disableUserInput);']; + } else { + _ctrl ctrlSetEventHandler ["buttonClick", QUOTE(closeDialog 0; player setDamage 1; [false] call DFUNC(disableUserInput);)]; + }; + _ctrl ctrlEnable ((getMissionConfigValue ["respawnButton", -1]) != 0); // handles 3den attribute or description.ext + _ctrl ctrlSetText localize "$str_3den_multiplayer_attributecategory_respawn_displayname"; _ctrl ctrlSetTooltip "Respawn."; }; diff --git a/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf index cb6f63c39a..913ffb075e 100644 --- a/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf +++ b/addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf @@ -22,6 +22,7 @@ if (isNull _unit) exitWith {}; TRACE_3("enteredStateDeath",_this,_thisOrigin,_thisTransition); private _causeOfDeath = format ["%1:%2", _thisOrigin, _thisTransition]; +private _instigator = _unit getVariable [QEGVAR(medical,lastInstigator), objNull]; // could delay a frame here to fix the double killed EH, but we lose it being a "native" kill (scoreboard / rating) -[_unit, _causeOfDeath] call EFUNC(medical_status,setDead); +[_unit, _causeOfDeath, _instigator] call EFUNC(medical_status,setDead); diff --git a/addons/medical_status/functions/fnc_handleKilled.sqf b/addons/medical_status/functions/fnc_handleKilled.sqf index a78c82bf55..f2b253cf3e 100644 --- a/addons/medical_status/functions/fnc_handleKilled.sqf +++ b/addons/medical_status/functions/fnc_handleKilled.sqf @@ -30,20 +30,22 @@ if (_unit isEqualTo (_unit getVariable [QGVAR(killed), objNull])) exitWith { _unit setVariable [QGVAR(killed), _unit]; private _causeOfDeath = _unit getVariable [QEGVAR(medical,causeOfDeath), "#scripted"]; +private _modifyKilledArray = missionNamespace getVariable [QEGVAR(medical,modifyKilledArray), true]; // getVar so this can be disabled -// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect) +// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect, forced respawn while conscious) if (_causeOfDeath != "#scripted") then { _killer = _unit getVariable [QEGVAR(medical,lastDamageSource), _killer]; // vehicle _instigator = _unit getVariable [QEGVAR(medical,lastInstigator), _instigator]; // unit in the turret - - // All Killed EHs uses the same array, so we can modify it now to pass the correct killer/instigator - if (missionNamespace getVariable [QEGVAR(medical,modifyKilledArray), true]) then { // getVar so this can be disabled - _this set [1, _killer]; - _this set [2, _instigator]; - }; -} else { // in that case, call setDead manually to prevent any issues +} else { + // call setDead manually to prevent any issues [_unit, "#scripted"] call FUNC(setDead); }; + +// All Killed EHs uses the same array, so we can modify it now to pass the correct killer/instigator +if (_modifyKilledArray) then { + _this set [1, _killer]; + _this set [2, _instigator]; +}; TRACE_3("killer info",_killer,_instigator,_causeOfDeath); if (_unit == player) then { diff --git a/addons/medical_status/functions/fnc_handleKilledMission.sqf b/addons/medical_status/functions/fnc_handleKilledMission.sqf index 67d1f050f4..bf8bd780ba 100644 --- a/addons/medical_status/functions/fnc_handleKilledMission.sqf +++ b/addons/medical_status/functions/fnc_handleKilledMission.sqf @@ -30,16 +30,16 @@ if (_unit isEqualTo (_unit getVariable [QGVAR(killedMission), objNull])) exitWit _unit setVariable [QGVAR(killedMission), _unit]; private _causeOfDeath = _unit getVariable [QEGVAR(medical,causeOfDeath), "#scripted"]; +private _modifyKilledArray = missionNamespace getVariable [QEGVAR(medical,modifyKilledArray), true]; // getVar so this can be disabled -// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect) +// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect, forced respawn while conscious) if (_causeOfDeath != "#scripted") then { _killer = _unit getVariable [QEGVAR(medical,lastDamageSource), _killer]; // vehicle _instigator = _unit getVariable [QEGVAR(medical,lastInstigator), _instigator]; // unit in the turret - - // All Killed EHs uses the same array, so we can modify it now to pass the correct killer/instigator - if (missionNamespace getVariable [QEGVAR(medical,modifyKilledArray), true]) then { // getVar so this can be disabled - _this set [1, _killer]; - _this set [2, _instigator]; - }; +}; +// All Killed EHs uses the same array, so we can modify it now to pass the correct killer/instigator +if (_modifyKilledArray) then { + _this set [1, _killer]; + _this set [2, _instigator]; }; TRACE_3("killer mission info",_killer,_instigator,_causeOfDeath); diff --git a/addons/medical_status/functions/fnc_initUnit.sqf b/addons/medical_status/functions/fnc_initUnit.sqf index 73ff2ce8b6..1b6c283664 100644 --- a/addons/medical_status/functions/fnc_initUnit.sqf +++ b/addons/medical_status/functions/fnc_initUnit.sqf @@ -75,6 +75,9 @@ if (_isRespawn) then { // Unconscious spontanious wake up chance _unit setVariable [QEGVAR(medical,lastWakeUpCheck), nil]; + + // Cause of death + _unit setVariable [QEGVAR(medical,causeOfDeath), nil]; }; [{ diff --git a/addons/medical_status/functions/fnc_setDead.sqf b/addons/medical_status/functions/fnc_setDead.sqf index 7f41ebf3da..ec85ad8a65 100644 --- a/addons/medical_status/functions/fnc_setDead.sqf +++ b/addons/medical_status/functions/fnc_setDead.sqf @@ -6,6 +6,7 @@ * Arguments: * 0: The unit * 1: Reason for death + * 2: Killer * * Return Value: * None @@ -13,8 +14,8 @@ * Public: No */ -params ["_unit", ["_reason", "#setDead"]]; -TRACE_2("setDead",_unit,_reason); +params ["_unit", ["_reason", "#setDead"], ["_instigator", objNull]]; +TRACE_3("setDead",_unit,_reason,_instigator); // No heart rate or blood pressure to measure when dead _unit setVariable [VAR_HEART_RATE, 0, true]; @@ -26,4 +27,8 @@ _unit setVariable [QEGVAR(medical,causeOfDeath), _reason, true]; [QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent; // Kill the unit without changing visual apperance -[_unit, 1] call EFUNC(medical_engine,setStructuralDamage); +private _prevDamage = _unit getHitPointDamage "HitHead"; + +_unit setHitPointDamage ["HitHead", 1, true, _instigator]; + +_unit setHitPointDamage ["HitHead", _prevDamage]; diff --git a/addons/medical_treatment/functions/fnc_placeInBodyBag.sqf b/addons/medical_treatment/functions/fnc_placeInBodyBag.sqf index 3154107e01..87de5f3542 100644 --- a/addons/medical_treatment/functions/fnc_placeInBodyBag.sqf +++ b/addons/medical_treatment/functions/fnc_placeInBodyBag.sqf @@ -31,7 +31,7 @@ if (!local _patient) exitWith { if (alive _patient) then { TRACE_1("Manually killing with setDead",_patient); - [_patient, "buried_alive"] call EFUNC(medical_status,setDead); + [_patient, "buried_alive", _medic] call EFUNC(medical_status,setDead); }; private _position = (getPosASL _patient) vectorAdd [0, 0, 0.2];