diff --git a/addons/cookoff/XEH_postInit.sqf b/addons/cookoff/XEH_postInit.sqf index 673fbac963..190232e34f 100644 --- a/addons/cookoff/XEH_postInit.sqf +++ b/addons/cookoff/XEH_postInit.sqf @@ -16,33 +16,24 @@ if (isServer) then { ["AllVehicles", "Deleted", { { deleteVehicle _x; - } forEach ((_this select 0) getVariable [QGVAR(vehicleEffects), []]); + } forEach ((_this select 0) getVariable [QGVAR(effects), []]); }, true, ["CAManBase", "StaticWeapon"], true] call CBA_fnc_addClassEventHandler; ["ReammoBox_F", "Deleted", { { deleteVehicle _x; - } forEach ((_this select 0) getVariable [QGVAR(boxEffects), []]); + } forEach ((_this select 0) getVariable [QGVAR(effects), []]); }, true, [], true] call CBA_fnc_addClassEventHandler; -[QGVAR(cleanupVehicleEffects), { +// Raised when the flames have subsided or after the ammo of a box has finished cooking off +[QGVAR(cleanupEffects), { params ["_object"]; { deleteVehicle _x; - } forEach (_object getVariable [QGVAR(vehicleEffects), []]); + } forEach (_object getVariable [QGVAR(effects), []]); - _object setVariable [QGVAR(vehicleEffects), nil]; -}] call CBA_fnc_addEventHandler; - -[QGVAR(cleanupBoxEffects), { - params ["_object"]; - - { - deleteVehicle _x; - } forEach (_object getVariable [QGVAR(boxEffects), []]); - - _object setVariable [QGVAR(boxEffects), nil]; + _object setVariable [QGVAR(effects), nil]; }] call CBA_fnc_addEventHandler; // Ammo box damage handling diff --git a/addons/cookoff/functions/fnc_cookOff.sqf b/addons/cookoff/functions/fnc_cookOff.sqf index cf6e5db616..215cfd1c92 100644 --- a/addons/cookoff/functions/fnc_cookOff.sqf +++ b/addons/cookoff/functions/fnc_cookOff.sqf @@ -112,7 +112,10 @@ if (_delayBetweenSmokeAndFire) then { if (isNull _vehicle) exitWith {}; // Remove effects - [QGVAR(cleanupVehicleEffects), _vehicle] call CBA_fnc_globalEvent; + [QGVAR(cleanupEffects), _vehicle] call CBA_fnc_globalEvent; + + // Reset variable, so it can cook-off again + _vehicle setVariable [QGVAR(isCookingOff), nil, true]; if (GVAR(destroyVehicleAfterCookoff) || _detonateAfterCookoff) then { _vehicle setDamage [1, true, _source, _instigator]; // because it's running on the server, killer and instigator can be set diff --git a/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf b/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf index 9b8435c007..804efa5f8a 100644 --- a/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf +++ b/addons/cookoff/functions/fnc_cookOffBoxLocal.sqf @@ -49,5 +49,5 @@ params ["", "", "", "_startTime", "_smokeDelay"]; [QGVAR(detonateAmmunition), [_box, true, _source, _instigator, random [DETONATION_DELAY / 2, DETONATION_DELAY, DETONATION_DELAY / 2 * 3]]] call CBA_fnc_localEvent; }; - _box setVariable [QGVAR(boxEffects), _effects]; + _box setVariable [QGVAR(effects), _effects]; }, _this, (_startTime - CBA_missionTime + _smokeDelay) max 0] call CBA_fnc_waitAndExecute; // this delay allows for synchronisation for JIP players diff --git a/addons/cookoff/functions/fnc_detonateAmmunition.sqf b/addons/cookoff/functions/fnc_detonateAmmunition.sqf index 6bc3744f66..e6186ccedc 100644 --- a/addons/cookoff/functions/fnc_detonateAmmunition.sqf +++ b/addons/cookoff/functions/fnc_detonateAmmunition.sqf @@ -26,7 +26,9 @@ params ["_object", ["_destroyWhenFinished", false], ["_source", objNull], ["_ins if (isNull _object) exitWith {}; // Don't have an object detonate its ammo twice -if (!isNil {_object getVariable QGVAR(cookoffMagazines)}) exitWith {}; +if (_object getVariable [QGVAR(isAmmoDetonating), false]) exitWith {}; + +_object setVariable [QGVAR(isAmmoDetonating), true, true]; _object setVariable [QGVAR(cookoffMagazines), _object call FUNC(getVehicleAmmo)]; diff --git a/addons/cookoff/functions/fnc_detonateAmmunitionServer.sqf b/addons/cookoff/functions/fnc_detonateAmmunitionServer.sqf index 25bb4e43a5..2e3d56bb7e 100644 --- a/addons/cookoff/functions/fnc_detonateAmmunitionServer.sqf +++ b/addons/cookoff/functions/fnc_detonateAmmunitionServer.sqf @@ -10,7 +10,7 @@ * 3: Instigator * * Return Value: - * Nothing Useful + * None * * Example: * [cursorObject, true, player, player] call ace_cookoff_fnc_detonateAmmunitionServer @@ -26,19 +26,11 @@ if (isNull _object) exitWith {}; (_object getVariable QGVAR(cookoffMagazines)) params ["_magazines", "_totalAmmo"]; -// If the cook-off has finished, clean up the effects and destroy the object -if (_magazines isEqualTo [] || {_totalAmmo <= 0}) exitWith { - [QGVAR(cleanupBoxEffects), _object] call CBA_fnc_globalEvent; +private _hasFinished = _totalAmmo <= 0 || {_magazines isEqualTo []}; - _object setVariable [QGVAR(cookoffMagazines), nil]; - - if (_destroyWhenFinished) then { - _object setDamage [1, true, _source, _instigator]; - }; -}; - -// If the cook-off is interrupted or disabled, clean up the effects -if (underwater _object || { +// If the cook-off has finished or been interrupted, clean up the effects for boxes (no vehicle effects) +if (_hasFinished || + {underwater _object} || { if (GVAR(ammoCookoffDuration) == 0) exitWith {true}; if (_object isKindOf "ReammoBox_F") exitWith { @@ -47,9 +39,21 @@ if (underwater _object || { !(GVAR(enableAmmoCookoff) && {_object getVariable [QGVAR(enableAmmoCookoff), true]}) }) exitWith { - [QGVAR(cleanupBoxEffects), _object] call CBA_fnc_globalEvent; + if (_object isKindOf "ReammoBox_F") then { + [QGVAR(cleanupEffects), _object] call CBA_fnc_globalEvent; + // Reset variable, so the box can cook-off again + _object setVariable [QGVAR(isCookingOff), nil, true]; + }; + + // Reset variables, so the object can detonate its ammo again _object setVariable [QGVAR(cookoffMagazines), nil]; + _object setVariable [QGVAR(isAmmoDetonating), nil, true]; + + // If done, destroy the object if necessary + if (_hasFinished && _destroyWhenFinished) then { + _object setDamage [1, true, _source, _instigator]; + }; }; private _magazineIndex = floor random (count _magazines); @@ -76,9 +80,6 @@ _totalAmmo = _totalAmmo - _removed; _object setVariable [QGVAR(cookoffMagazines), [_magazines, _totalAmmo]]; -// Detonate the remaining ammo after a delay -[FUNC(detonateAmmunitionServer), [_object, _destroyWhenFinished, _source, _instigator], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute; - // Get magazine info, which is used to spawn projectiles private _configMagazine = configFile >> "CfgMagazines" >> _magazineClassname; private _ammo = getText (_configMagazine >> "ammo"); @@ -169,3 +170,6 @@ switch (_simType) do { }; }; }; + +// Detonate the remaining ammo after a delay +[FUNC(detonateAmmunitionServer), [_object, _destroyWhenFinished, _source, _instigator], _timeBetweenAmmoDetonation] call CBA_fnc_waitAndExecute; diff --git a/addons/cookoff/functions/fnc_smoke.sqf b/addons/cookoff/functions/fnc_smoke.sqf index f060a98f61..8d95719dc6 100644 --- a/addons/cookoff/functions/fnc_smoke.sqf +++ b/addons/cookoff/functions/fnc_smoke.sqf @@ -41,4 +41,4 @@ private _effects = [_smokeBarrel]; _effects pushBack _smoke; } forEach _positions; -_vehicle setVariable [QGVAR(vehicleEffects), _effects]; +_vehicle setVariable [QGVAR(effects), _effects]; diff --git a/addons/vehicle_damage/functions/fnc_handleDetonation.sqf b/addons/vehicle_damage/functions/fnc_handleDetonation.sqf index 9556cea424..8f317323fa 100644 --- a/addons/vehicle_damage/functions/fnc_handleDetonation.sqf +++ b/addons/vehicle_damage/functions/fnc_handleDetonation.sqf @@ -21,18 +21,17 @@ */ params ["_vehicle", "_chanceOfDetonate", "_vehicleAmmo", "_explosiveAmmoCount", "_nonExplosiveAmmoCount", ["_injurer", objNull]]; -private _alreadyDetonating = _vehicle getVariable [QGVAR(detonating), false]; + private _isKnockedOut = _explosiveAmmoCount > 0; -if (!_alreadyDetonating && { _chanceOfDetonate >= random 1 }) exitWith { +// Ignore if the vehicle is already detonating ammo +if (_vehicle getVariable [QEGVAR(cookoff,isAmmoDetonating), false]) exitWith {_isKnockedOut}; + +if (_chanceOfDetonate >= random 1) exitWith { [_vehicle, _injurer, _vehicleAmmo] call FUNC(detonate); LOG_2("Detonating [%1] with a chance-to-detonate [%2]",_vehicle,_chanceOfDetonate); - _vehicle setVariable [QGVAR(detonating), true]; _isKnockedOut }; -// Avoid RPT spam -if (_alreadyDetonating) exitWith { _isKnockedOut }; - LOG_2("[%1] No Detonation - Chance of detonation [%2]",_vehicle,_chanceOfDetonate); false