mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Medical StateMachine - Tweak dead state handling (#7061)
* Medical StateMachine - Tweak dead state handling - Don't call setDammage inside HandleDamage EH - Add death reason on entering death state * add a getVar disable in case this causes problems * Cleanup * cleanup * Update addons/medical_statemachine/functions/fnc_enteredStateDeath.sqf Co-Authored-By: Ferran Obon <magnetar5891@gmail.com>
This commit is contained in:
parent
9d0e474cf5
commit
d6c39e661f
@ -16,10 +16,12 @@
|
||||
*/
|
||||
|
||||
params ["_unit"];
|
||||
if (isNull _unit) exitWith {};
|
||||
|
||||
// TODO: Probably also needs additional logic to deal with edge cases
|
||||
//IGNORE_PRIVATE_WARNING ["_thisOrigin", "_thisTransition"]; // vars provided by CBA_statemachine
|
||||
TRACE_3("enteredStateDeath",_this,_thisOrigin,_thisTransition);
|
||||
|
||||
// Send a local event before death
|
||||
[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent;
|
||||
private _causeOfDeath = format ["%1:%2", _thisOrigin, _thisTransition];
|
||||
|
||||
[_unit] call EFUNC(medical_status,setDead);
|
||||
// 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);
|
||||
|
@ -4,6 +4,7 @@ PREP(getBloodLoss);
|
||||
PREP(getBloodPressure);
|
||||
PREP(getBloodVolumeChange);
|
||||
PREP(getCardiacOutput);
|
||||
PREP(handleKilled);
|
||||
PREP(hasStableVitals);
|
||||
PREP(initUnit);
|
||||
PREP(isBeingCarried);
|
||||
|
@ -8,4 +8,19 @@ PREP_RECOMPILE_END;
|
||||
|
||||
#include "initSettings.sqf"
|
||||
|
||||
// Add vanilla killed EH to unit to set correct killer
|
||||
["CAManBase", "init", {
|
||||
params ["_unit"];
|
||||
|
||||
private _config = [_unit] call CBA_fnc_getObjectConfig;
|
||||
if (getText (_config >> "simulation") == "UAVPilot") exitWith {TRACE_1("ignore UAV AI",typeOf _unit);};
|
||||
if (getNumber (_config >> "isPlayableLogic") == 1) exitWith {TRACE_1("ignore logic unit",typeOf _unit)};
|
||||
|
||||
// Hopefully this EH gets added first as it can only effect other EH called after it
|
||||
private _ehIndex = _unit addEventHandler ["Killed", {_this call FUNC(handleKilled)}];
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
if (_ehIndex != 0) then { WARNING_1("killed EH not first [%1]",_ehIndex); };
|
||||
#endif
|
||||
}, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler;
|
||||
|
||||
ADDON = true;
|
||||
|
41
addons/medical_status/functions/fnc_handleKilled.sqf
Normal file
41
addons/medical_status/functions/fnc_handleKilled.sqf
Normal file
@ -0,0 +1,41 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Vanilla Killed EH, attempts to set correct source/killer for other killed event handlers (vanilla and XEH)
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Killer <OBJECT>
|
||||
* 2: Instigator <OBJECT>
|
||||
* 3: Use Effects <BOOL>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [cursorObject, player, player, true] call ace_medical_status_fnc_handleKilled
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_unit", "_killer", "_instigator", "_useEffects"];
|
||||
TRACE_4("handleKilled",_unit,_killer,_instigator,_useEffects);
|
||||
|
||||
private _causeOfDeath = _unit getVariable [QEGVAR(medical,causeOfDeath), "#scripted"];
|
||||
|
||||
// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect)
|
||||
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];
|
||||
};
|
||||
};
|
||||
TRACE_3("killer info",_killer,_instigator,_causeOfDeath);
|
||||
|
||||
if (_unit isEqualTo (_unit getVariable [QGVAR(killed), objNull])) exitWith {}; // ensure event is only called once
|
||||
_unit setVariable [QGVAR(killed), _unit];
|
||||
["ace_killed", [_unit, _causeOfDeath, _killer, _instigator]] call CBA_fnc_globalEvent;
|
@ -13,16 +13,17 @@
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
params ["_unit", ["_reason", "unknown"]];
|
||||
params ["_unit", ["_reason", "#setDead"]];
|
||||
TRACE_2("setDead",_unit,_reason);
|
||||
|
||||
// No heart rate or blood pressure to measure when dead
|
||||
_unit setVariable [VAR_HEART_RATE, 0, true];
|
||||
_unit setVariable [VAR_BLOOD_PRESS, [0, 0], true];
|
||||
|
||||
_unit setVariable [QEGVAR(medical,causeOfDeath), _reason, true];
|
||||
|
||||
// Send a local event before death
|
||||
[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent;
|
||||
|
||||
// Kill the unit without changing visual apperance
|
||||
[_unit, 1] call EFUNC(medical_engine,setStructuralDamage);
|
||||
|
||||
private _lastShooter = _unit getVariable [QEGVAR(medical,lastDamageSource), objNull];
|
||||
private _lastInstigator = _unit getVariable [QEGVAR(medical,lastInstigator), objNull];
|
||||
|
||||
["ace_killed", [_unit, _reason, _lastShooter, _lastInstigator]] call CBA_fnc_globalEvent;
|
||||
|
Loading…
Reference in New Issue
Block a user