Skip to content

Commit

Permalink
Fix disposable magazines not being replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 committed May 4, 2024
1 parent 441d937 commit d3561b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
5 changes: 0 additions & 5 deletions addons/disposable/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");
Expand Down
50 changes: 15 additions & 35 deletions addons/disposable/fnc_replaceMagazineCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,41 @@ Description:
Replaces disposable launcher magazines with loaded disposable launchers.
Parameters:
_box - Any object with cargo <OBJECT>
_container - Any object with cargo <OBJECT>
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;

0 comments on commit d3561b3

Please sign in to comment.