diff --git a/addons/cookoff/XEH_postInit.sqf b/addons/cookoff/XEH_postInit.sqf index 52073d39b1..36cebc1d17 100644 --- a/addons/cookoff/XEH_postInit.sqf +++ b/addons/cookoff/XEH_postInit.sqf @@ -11,6 +11,22 @@ [QGVAR(smoke), FUNC(smoke)] call CBA_fnc_addEventHandler; [QGVAR(cookOffBox), FUNC(cookOffBox)] call CBA_fnc_addEventHandler; +// handle cleaning up effects when vehicle is deleted mid-cookoff +[QGVAR(addCleanupHandlers), { + params ["_vehicle"]; + + // Don't add a new EH if cookoff is run multiple times + if ((_vehicle getVariable [QGVAR(deletedEH), -1]) == -1) then { + private _deletedEH = _vehicle addEventHandler ["Deleted", { + params ["_vehicle"]; + + [QGVAR(cleanupEffects), [_vehicle]] call CBA_fnc_globalEvent; + }]; + + _vehicle setVariable [QGVAR(deletedEH), _deletedEH]; + }; +}] call CBA_fnc_addEventHandler; + [QGVAR(cleanupEffects), { params ["_vehicle", ["_effects", []]]; diff --git a/addons/cookoff/functions/fnc_cookOff.sqf b/addons/cookoff/functions/fnc_cookOff.sqf index 37e0164eae..8176b8d085 100644 --- a/addons/cookoff/functions/fnc_cookOff.sqf +++ b/addons/cookoff/functions/fnc_cookOff.sqf @@ -30,6 +30,8 @@ TRACE_9("cooking off",_vehicle,_intensity,_instigator,_smokeDelayEnabled,_ammoDe if (_vehicle getVariable [QGVAR(isCookingOff), false]) exitWith {}; _vehicle setVariable [QGVAR(isCookingOff), true, true]; +[QGVAR(addCleanupHandlers), [_vehicle]] call CBA_fnc_serverEvent; + // limit maximum value of intensity to prevent very long cook-off times _intensity = _intensity min _maxIntensity;