Skip to content

Commit

Permalink
Medical Status - Fix double execution of killed event (#7561)
Browse files Browse the repository at this point in the history
* fix double execution of killed event

* revert the execNextFrame change

* make second execution run with null

* make second execution run with null
  • Loading branch information
commy2 authored Feb 29, 2020
1 parent d87d051 commit 15b4b98
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions addons/medical_status/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PREP(getBloodVolumeChange);
PREP(getCardiacOutput);
PREP(getMedicationCount);
PREP(handleKilled);
PREP(handleKilledMission);
PREP(hasStableVitals);
PREP(initUnit);
PREP(isBeingCarried);
Expand Down
2 changes: 2 additions & 0 deletions addons/medical_status/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ PREP_RECOMPILE_END;
#endif
}, nil, [IGNORE_BASE_UAVPILOTS], true] call CBA_fnc_addClassEventHandler;

addMissionEventHandler ["EntityKilled", {_this call FUNC(handleKilledMission)}];

ADDON = true;
11 changes: 8 additions & 3 deletions addons/medical_status/functions/fnc_handleKilled.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
params ["_unit", "_killer", "_instigator", "_useEffects"];
TRACE_4("handleKilled",_unit,_killer,_instigator,_useEffects);

// ensure event is only called once
if (_unit isEqualTo (_unit getVariable [QGVAR(killed), objNull])) exitWith {
_this set [0, objNull];
_this set [1, objNull];
_this set [2, objNull];
};
_unit setVariable [QGVAR(killed), _unit];

private _causeOfDeath = _unit getVariable [QEGVAR(medical,causeOfDeath), "#scripted"];

// if undefined then it's a death not caused by ace's setDead (mission setDamage, disconnect)
Expand All @@ -36,9 +44,6 @@ if (_causeOfDeath != "#scripted") then {
};
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];

if (_unit == player) then {
// Enable user input before respawn, in case mission is using respawnTemplates
["unconscious", false] call EFUNC(common,setDisableUserInputStatus);
Expand Down
45 changes: 45 additions & 0 deletions addons/medical_status/functions/fnc_handleKilledMission.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "script_component.hpp"
/*
* Author: PabstMirror
* Vanilla EntityKilled mission EH, attempts to set correct source/killer for other killed event handlers.
*
* 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_handleKilledMission
*
* Public: No
*/

params ["_unit", "_killer", "_instigator", "_useEffects"];
TRACE_4("handleKilledMission",_unit,_killer,_instigator,_useEffects);

// ensure event is only called once
if (_unit isEqualTo (_unit getVariable [QGVAR(killedMission), objNull])) exitWith {
_this set [0, objNull];
_this set [1, objNull];
_this set [2, objNull];
};
_unit setVariable [QGVAR(killedMission), _unit];

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 mission info",_killer,_instigator,_causeOfDeath);

0 comments on commit 15b4b98

Please sign in to comment.