From b9531b0644d00c4d4a87e85b6ee82b05512cfced Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:20:08 +0200 Subject: [PATCH] Added random destruction of fuel and ammo storage --- addons/cargo/XEH_postInit.sqf | 25 +++++++++++++++++++++++++ addons/cargo/script_component.hpp | 3 +++ 2 files changed, 28 insertions(+) diff --git a/addons/cargo/XEH_postInit.sqf b/addons/cargo/XEH_postInit.sqf index cc3055ae30..400f97a9db 100644 --- a/addons/cargo/XEH_postInit.sqf +++ b/addons/cargo/XEH_postInit.sqf @@ -39,6 +39,31 @@ [QGVAR(unloadedCargoOnKilled), { params ["_item", "_vehicle"]; + // Remove invulernability from this addon + [_item, "blockDamage", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); + + // Check if item can take damage + if (isDamageAllowed _item) then { + // Random chance of destroying fuel and ammo storage + if ( + random 1 < CARGO_DESTROY_FUEL_CHANCE && + {getFuelCargo _item > 0 || {missionNamespace getVariable [QEGVAR(refuel,enabled), false] && {(_item call EFUNC(refuel,getFuel)) > 0}}} + ) then { + _item setDamage 1; + }; + + // If the item has ammunition, detonate it + if (["ace_cookoff"] call EFUNC(common,isModLoaded) && {random 1 < CARGO_DESTROY_AMMO_CHANCE} && {(_item call EFUNC(cookoff,getVehicleAmmo)) select 1 > 0}) then { + [QEGVAR(cookoff,cookOffBoxServer), _item] call CBA_fnc_serverEvent; + }; + + // Readd invulnerability for while, so that items aren't destroyed when being thrown + [_item, "blockDamage", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); + + // Even though QGVAR(serverUnload) handles that on the server, make sure invulnerability from this addon is removed + [EFUNC(common,statusEffect_set), [_item, "blockDamage", QUOTE(ADDON), false], 2] call CBA_fnc_waitAndExecute; + }; + // Get direction from vehicle to item, so that item is thrown away from vehicle private _vectorDir = (getPosWorld _vehicle) vectorFromTo (getPosWorld _item); diff --git a/addons/cargo/script_component.hpp b/addons/cargo/script_component.hpp index 49cba6f556..9ca87e8ff9 100644 --- a/addons/cargo/script_component.hpp +++ b/addons/cargo/script_component.hpp @@ -20,5 +20,8 @@ #define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default}) +#define CARGO_DESTROY_FUEL_CHANCE 0.5 +#define CARGO_DESTROY_AMMO_CHANCE 0.8 + #define CARGO_TUMBLE_RANDOM_MUL 8 #define CARGO_TUMBLE_TORQUE 500