From d3561b33cc91f530af8b1291c749eeeac0de6eee Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 4 May 2024 16:14:22 +0200 Subject: [PATCH] Fix disposable magazines not being replaced --- addons/disposable/XEH_preInit.sqf | 5 -- .../disposable/fnc_replaceMagazineCargo.sqf | 50 ++++++------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index fd5954f11..9bd1af830 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -27,7 +27,6 @@ GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace; GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(magazines) = []; -GVAR(BackpackLaunchers) = createHashMap; GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace; private _cfgWeapons = configFile >> "CfgWeapons"; @@ -50,10 +49,6 @@ private _cfgMagazines = configFile >> "CfgMagazines"; GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher]; }; - if (_fitsInBackpacks) then { - GVAR(BackpackLaunchers) set [_loadedLauncher, true]; - }; - // check if mass entries add up private _massLauncher = getNumber (_cfgWeapons >> _launcher >> "WeaponSlotsInfo" >> "mass"); private _massMagazine = getNumber (_cfgMagazines >> _magazine >> "mass"); diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 89e3da9e6..47afbd7fb 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -6,61 +6,41 @@ Description: Replaces disposable launcher magazines with loaded disposable launchers. Parameters: - _box - Any object with cargo + _container - Any object with cargo Returns: Nothing. Examples: (begin example) - _box call cba_disposable_fnc_replaceMagazineCargo + _container call cba_disposable_fnc_replaceMagazineCargo (end) Author: - commy2 + commy2, johnb43 ---------------------------------------------------------------------------- */ if (!GVAR(replaceDisposableLauncher)) exitWith {}; -params ["_box"]; -if (!local _box) exitWith {}; -if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; - -private _uniformContainer = uniformContainer _box; -if (!isNull _uniformContainer) then { - _uniformContainer call FUNC(replaceMagazineCargo); -}; +params ["_container"]; -private _vestContainer = vestContainer _box; -if (!isNull _vestContainer) then { - _vestContainer call FUNC(replaceMagazineCargo); -}; +if (!local _container) exitWith {}; +if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; -private _backpackContainer = backpackContainer _box; -if (!isNull _backpackContainer) then { - _backpackContainer call FUNC(replaceMagazineCargo); -}; +private _containers = everyBackpack _container; +_containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x}); +// Replace all magazines recursively { _x call FUNC(replaceMagazineCargo); -} forEach everyBackpack _box; +} forEach _containers; -if (magazineCargo _box arrayIntersect GVAR(magazines) isEqualTo []) exitWith {}; +private _magazines = (magazineCargo _container) select {_x in GVAR(magazines)}; -private _magazines = magazinesAmmoCargo _box; -clearMagazineCargoGlobal _box; - -private _isBackpack = getNumber (configOf _box >> "isBackpack") != -1; +if (_magazines isEqualTo []) exitWith {}; +// Replace magazines with disposable launchers { - _x params ["_magazine", "_ammo"]; - - if (_magazine in GVAR(magazines)) then { - private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _magazine; - if (!_isBackpack || {_loadedLauncher in GVAR(BackpackLaunchers)}) then { - _box addWeaponCargoGlobal [_loadedLauncher, 1]; - }; - } else { - _box addMagazineAmmoCargo [_magazine, 1, _ammo]; - }; + _container addMagazineCargoGlobal [_x, -1]; + _container addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _x, 1]; } forEach _magazines;