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 1/9] 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; From f648421763ddda29e4b628190dc51b230a53902a Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 4 May 2024 14:03:34 -0700 Subject: [PATCH 2/9] Update addons/disposable/fnc_replaceMagazineCargo.sqf Co-authored-by: PabstMirror --- addons/disposable/fnc_replaceMagazineCargo.sqf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 47afbd7fb..af06cb55f 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -28,7 +28,9 @@ if (!local _container) exitWith {}; if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; private _containers = everyBackpack _container; -_containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x}); +if (_container isKindOf "CaManBase") then { + _containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x}); +}; // Replace all magazines recursively { From e6bf5686d25401c7dca96fe9629a886c47eee5d7 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 4 May 2024 23:04:15 +0200 Subject: [PATCH 3/9] Update fnc_replaceMagazineCargo.sqf --- addons/disposable/fnc_replaceMagazineCargo.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index af06cb55f..336651496 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -28,7 +28,8 @@ if (!local _container) exitWith {}; if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; private _containers = everyBackpack _container; -if (_container isKindOf "CaManBase") then { + +if (_container isKindOf "CAManBase") then { _containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x}); }; From b943b84388bcb14544b075568d4e1aa3a16a7771 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 5 May 2024 13:06:22 +0200 Subject: [PATCH 4/9] Remove unused variable --- addons/disposable/XEH_preInit.sqf | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index 9bd1af830..e984bed30 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -36,7 +36,6 @@ private _cfgMagazines = configFile >> "CfgMagazines"; private _launcher = configName _x; private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0)); getArray _x params ["_loadedLauncher", "_usedLauncher"]; - private _fitsInBackpacks = TYPE_BACKPACK in getArray (configFile >> "CfgWeapons" >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots"); GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher]; GVAR(UsedLaunchers) setVariable [_launcher, _usedLauncher]; From 63947a59b3b9439a418da701f77271252e4b2bf9 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 5 May 2024 13:12:50 +0200 Subject: [PATCH 5/9] Added ignoring slot restrictions comment --- addons/disposable/fnc_replaceMagazineCargo.sqf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 336651496..5f0928e46 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -45,5 +45,7 @@ if (_magazines isEqualTo []) exitWith {}; // Replace magazines with disposable launchers { _container addMagazineCargoGlobal [_x, -1]; + + // Ignores slot restrictions, but that's wanted, as magazines shouldn't just vanish _container addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _x, 1]; } forEach _magazines; From 3dcda1b51ab1cd700029e2ce8a70046ff9db109b Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 8 May 2024 10:11:23 +0200 Subject: [PATCH 6/9] Check for launchers that can fit in vests and uniforms --- addons/disposable/XEH_preInit.sqf | 9 ++++- .../disposable/fnc_replaceMagazineCargo.sqf | 37 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index e984bed30..83f8ca74c 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -27,6 +27,7 @@ GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace; GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace; GVAR(magazines) = []; +GVAR(allowedSlotsLaunchers) = createHashMap; GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace; private _cfgWeapons = configFile >> "CfgWeapons"; @@ -48,6 +49,8 @@ private _cfgMagazines = configFile >> "CfgMagazines"; GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher]; }; + GVAR(allowedSlotsLaunchers) set [_loadedLauncher, getArray (_cfgWeapons >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots")]; + // check if mass entries add up private _massLauncher = getNumber (_cfgWeapons >> _launcher >> "WeaponSlotsInfo" >> "mass"); private _massMagazine = getNumber (_cfgMagazines >> _magazine >> "mass"); @@ -64,7 +67,11 @@ private _cfgMagazines = configFile >> "CfgMagazines"; } forEach configProperties [configFile >> "CBA_DisposableLaunchers", "isArray _x"]; ["CBA_settingsInitialized", { - ["All", "InitPost", {call FUNC(replaceMagazineCargo)}, nil, nil, true] call CBA_fnc_addClassEventHandler; + ["All", "InitPost", { + params ["_object"]; + + [typeOf _object, _object] call FUNC(replaceMagazineCargo); + }, nil, nil, true] call CBA_fnc_addClassEventHandler; }] call CBA_fnc_addEventHandler; ADDON = true; diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 5f0928e46..93f1b3405 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -6,6 +6,7 @@ Description: Replaces disposable launcher magazines with loaded disposable launchers. Parameters: + _containerType - typeOf _container _container - Any object with cargo Returns: @@ -13,7 +14,7 @@ Returns: Examples: (begin example) - _container call cba_disposable_fnc_replaceMagazineCargo + [typeOf _container, _container] call cba_disposable_fnc_replaceMagazineCargo (end) Author: @@ -21,16 +22,20 @@ Author: ---------------------------------------------------------------------------- */ if (!GVAR(replaceDisposableLauncher)) exitWith {}; +if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; -params ["_container"]; +params ["_containerType", "_container"]; if (!local _container) exitWith {}; -if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; -private _containers = everyBackpack _container; +private _containers = everyContainer _container; if (_container isKindOf "CAManBase") then { - _containers append ([uniformContainer _container, vestContainer _container, backpackContainer _container] select {!isNull _x}); + _containers append ([ + [uniform _container, uniformContainer _container], + [vest _container, vestContainer _container], + [backpack _container, backpackContainer _container] + ] select {!isNull (_x select 1)}); }; // Replace all magazines recursively @@ -42,10 +47,28 @@ private _magazines = (magazineCargo _container) select {_x in GVAR(magazines)}; if (_magazines isEqualTo []) exitWith {}; +// Check if a uniform, vest, backpack or something else entirely +_containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { + TYPE_BACKPACK +} else { + private _itemType = configFile >> "CfgWeapons" >> _containerType >> "ItemInfo" >> "type"; + + if (isClass _itemType) then { + getNumber _itemType + } else { + 0 + }; +}; + // Replace magazines with disposable launchers { _container addMagazineCargoGlobal [_x, -1]; - // Ignores slot restrictions, but that's wanted, as magazines shouldn't just vanish - _container addWeaponCargoGlobal [GVAR(MagazineLaunchers) getVariable _x, 1]; + private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _x; + + // Ignore slot restrictions if not a uniform, vest or backpack + // If slot restrictions apply, don't add weapon but remove magazine + if (_containerType == 0 || {_containerType in (GVAR(allowedSlotsLaunchers) getOrDefault [_loadedLauncher, []])}) then { + _container addWeaponCargoGlobal [_loadedLauncher, 1]; + }; } forEach _magazines; From 1db80c385cfaf752b155407e474c2bbaea063d96 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 8 May 2024 10:24:26 +0200 Subject: [PATCH 7/9] Update fnc_replaceMagazineCargo.sqf --- addons/disposable/fnc_replaceMagazineCargo.sqf | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 93f1b3405..e5f6fb074 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -51,13 +51,8 @@ if (_magazines isEqualTo []) exitWith {}; _containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { TYPE_BACKPACK } else { - private _itemType = configFile >> "CfgWeapons" >> _containerType >> "ItemInfo" >> "type"; - - if (isClass _itemType) then { - getNumber _itemType - } else { - 0 - }; + // If uniform or vest, this config will be defined, otherwise it will default to 0 + getNumber (configFile >> "CfgWeapons" >> _containerType >> "ItemInfo" >> "type") }; // Replace magazines with disposable launchers @@ -66,8 +61,8 @@ _containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _x; - // Ignore slot restrictions if not a uniform, vest or backpack - // If slot restrictions apply, don't add weapon but remove magazine + // Slot restrictions only apply if uniform, vest or backpack + // If slot restrictions apply, remove magazine but don't add weapon if (_containerType == 0 || {_containerType in (GVAR(allowedSlotsLaunchers) getOrDefault [_loadedLauncher, []])}) then { _container addWeaponCargoGlobal [_loadedLauncher, 1]; }; From a089ba7797806e1451f425bcc7efbc17f39db1e2 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 8 Aug 2024 14:53:50 -0500 Subject: [PATCH 8/9] Keep original args for `cba_disposable_fnc_replaceMagazineCargo` --- addons/disposable/XEH_preInit.sqf | 6 +----- addons/disposable/fnc_replaceMagazineCargo.sqf | 9 ++++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index 8a6a0ce61..9b4c7e2ba 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -91,11 +91,7 @@ private _cfgMagazines = configFile >> "CfgMagazines"; } forEach configProperties [configFile >> "CBA_DisposableLaunchers", "isArray _x"]; ["CBA_settingsInitialized", { - ["All", "InitPost", { - params ["_object"]; - - [typeOf _object, _object] call FUNC(replaceMagazineCargo); - }, nil, nil, true] call CBA_fnc_addClassEventHandler; + ["All", "InitPost", {call FUNC(replaceMagazineCargo)}, nil, nil, true] call CBA_fnc_addClassEventHandler; }] call CBA_fnc_addEventHandler; ADDON = true; diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index e5f6fb074..2168b0499 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -6,7 +6,6 @@ Description: Replaces disposable launcher magazines with loaded disposable launchers. Parameters: - _containerType - typeOf _container _container - Any object with cargo Returns: @@ -14,7 +13,7 @@ Returns: Examples: (begin example) - [typeOf _container, _container] call cba_disposable_fnc_replaceMagazineCargo + [_container] call cba_disposable_fnc_replaceMagazineCargo (end) Author: @@ -24,7 +23,7 @@ Author: if (!GVAR(replaceDisposableLauncher)) exitWith {}; if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; -params ["_containerType", "_container"]; +params ["_container"]; if (!local _container) exitWith {}; @@ -48,11 +47,11 @@ private _magazines = (magazineCargo _container) select {_x in GVAR(magazines)}; if (_magazines isEqualTo []) exitWith {}; // Check if a uniform, vest, backpack or something else entirely -_containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { +private _containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { TYPE_BACKPACK } else { // If uniform or vest, this config will be defined, otherwise it will default to 0 - getNumber (configFile >> "CfgWeapons" >> _containerType >> "ItemInfo" >> "type") + getNumber (configFile >> "CfgWeapons" >> (typeOf _container) >> "ItemInfo" >> "type") }; // Replace magazines with disposable launchers From 69dac45415e6a7a679f44c8fe3762d35fd847f54 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 8 Aug 2024 15:40:52 -0500 Subject: [PATCH 9/9] Revert "Keep original args for `cba_disposable_fnc_replaceMagazineCargo`" This reverts commit a089ba7797806e1451f425bcc7efbc17f39db1e2. --- addons/disposable/XEH_preInit.sqf | 6 +++++- addons/disposable/fnc_replaceMagazineCargo.sqf | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/disposable/XEH_preInit.sqf b/addons/disposable/XEH_preInit.sqf index 9b4c7e2ba..8a6a0ce61 100644 --- a/addons/disposable/XEH_preInit.sqf +++ b/addons/disposable/XEH_preInit.sqf @@ -91,7 +91,11 @@ private _cfgMagazines = configFile >> "CfgMagazines"; } forEach configProperties [configFile >> "CBA_DisposableLaunchers", "isArray _x"]; ["CBA_settingsInitialized", { - ["All", "InitPost", {call FUNC(replaceMagazineCargo)}, nil, nil, true] call CBA_fnc_addClassEventHandler; + ["All", "InitPost", { + params ["_object"]; + + [typeOf _object, _object] call FUNC(replaceMagazineCargo); + }, nil, nil, true] call CBA_fnc_addClassEventHandler; }] call CBA_fnc_addEventHandler; ADDON = true; diff --git a/addons/disposable/fnc_replaceMagazineCargo.sqf b/addons/disposable/fnc_replaceMagazineCargo.sqf index 2168b0499..e5f6fb074 100644 --- a/addons/disposable/fnc_replaceMagazineCargo.sqf +++ b/addons/disposable/fnc_replaceMagazineCargo.sqf @@ -6,6 +6,7 @@ Description: Replaces disposable launcher magazines with loaded disposable launchers. Parameters: + _containerType - typeOf _container _container - Any object with cargo Returns: @@ -13,7 +14,7 @@ Returns: Examples: (begin example) - [_container] call cba_disposable_fnc_replaceMagazineCargo + [typeOf _container, _container] call cba_disposable_fnc_replaceMagazineCargo (end) Author: @@ -23,7 +24,7 @@ Author: if (!GVAR(replaceDisposableLauncher)) exitWith {}; if (missionNamespace getVariable [QGVAR(disableMagazineReplacement), false]) exitWith {}; -params ["_container"]; +params ["_containerType", "_container"]; if (!local _container) exitWith {}; @@ -47,11 +48,11 @@ private _magazines = (magazineCargo _container) select {_x in GVAR(magazines)}; if (_magazines isEqualTo []) exitWith {}; // Check if a uniform, vest, backpack or something else entirely -private _containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { +_containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then { TYPE_BACKPACK } else { // If uniform or vest, this config will be defined, otherwise it will default to 0 - getNumber (configFile >> "CfgWeapons" >> (typeOf _container) >> "ItemInfo" >> "type") + getNumber (configFile >> "CfgWeapons" >> _containerType >> "ItemInfo" >> "type") }; // Replace magazines with disposable launchers