Skip to content

Commit 806a5f3

Browse files
committed
Handle boolean counts in setBackpackLoadout
1 parent a87923d commit 806a5f3

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

addons/main/functions/fnc_setBackpackLoadout.sqf

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,24 @@ if (isNull _backpack) exitWith {false};
2525
private _cfgMagazines = configFile >> "CfgMagazines";
2626
private _cfgVehicles = configFile >> "CfgVehicles";
2727
{
28-
if (typeName (_x select 0) == "Array") then {
28+
private _entry = _x;
29+
30+
// Some mods/functions (notably ACRE's loadout filtering) can produce cargo entries that have a boolean where
31+
// vanilla expects a numeric count (e.g. ["SomeItem", true]). Convert that to 1/0 to keep restore robust.
32+
if (_entry isEqualType [] && {count _entry > 1} && {(_entry select 1) isEqualType true}) then {
33+
_entry set [1, [0, 1] select (_entry select 1)];
34+
};
35+
36+
if (typeName (_entry select 0) == "Array") then {
2937
//weapon with attachments
30-
for "_i" from 1 to (_x select 1) do {
31-
_backpack addWeaponWithAttachmentsCargoGlobal _x;
38+
for "_i" from 1 to (_entry select 1) do {
39+
_backpack addWeaponWithAttachmentsCargoGlobal _entry;
3240
};
3341
} else {
34-
private _cargoClass = (_x select 0);
42+
private _cargoClass = (_entry select 0);
3543
//mags
3644
if (isClass (_cfgMagazines >> _cargoClass)) then {
37-
_backpack addMagazineAmmoCargo _x;
45+
_backpack addMagazineAmmoCargo _entry;
3846
// Above command sometimes fails on its own, like with PCML Missile
3947
// in NATO Ammo Bearer's backpack
4048
[{
@@ -44,7 +52,7 @@ private _cfgVehicles = configFile >> "CfgVehicles";
4452
_backpack addMagazineAmmoCargo [_mag, 1, _rounds];
4553
};
4654
_countInBackpack == _count
47-
}, {}, [_backpack] + _x, 1, {
55+
}, {}, [_backpack] + _entry, 1, {
4856
WARNING("chestpackToHolder timed out adding magazines");
4957
TRACE_1("Container: ",_this);
5058
}] call CBA_fnc_waitUntilAndExecute;
@@ -56,7 +64,7 @@ private _cfgVehicles = configFile >> "CfgVehicles";
5664
//
5765
[QGVAR(clearCargoBackpacks), [_backpack]] call CBA_fnc_globalEvent;
5866
} else {
59-
_backpack addItemCargoGlobal _x;
67+
_backpack addItemCargoGlobal _entry;
6068
}
6169
};
6270
};

0 commit comments

Comments
 (0)