Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for removing non-preset weapon if preset weapon present to removeWeaponCargo #706

Merged
merged 2 commits into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions addons/common/fnc_removeWeaponCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Function: CBA_fnc_removeWeaponCargo
Description:
Removes specific weapon(s) from cargo space.

Passing a non-preset weapon when there is a preset (classname with preset attachments/magazine)
weapon in cargo of that class will remove weapon only, leaving attachments and magazine.

Warning: All weapon attachments/magazines in container will become detached.

Parameters:
Expand Down Expand Up @@ -64,6 +67,7 @@ clearWeaponCargoGlobal _container;

{
_x params ["_weapon", "_muzzle", "_pointer", "_optic", "_magazine", "_magazineGL", "_bipod"];

// weaponsItems magazineGL does not exist if not loaded (not even as empty array)
if (count _x < 7) then {
_bipod = _magazineGL;
Expand All @@ -74,8 +78,14 @@ clearWeaponCargoGlobal _container;
// Process removal
_count = _count - 1;
} else {
_weapon = [_weapon] call CBA_fnc_getNonPresetClass;
_container addWeaponCargoGlobal [_weapon, 1];
private _weaponNonPreset = [_weapon] call CBA_fnc_getNonPresetClass;

if (_count != 0 && {_weaponNonPreset == _item}) then {
// Process removal of non-preset weapon, simply detach attachments on the weapon
_count = _count - 1;
} else {
_container addWeaponCargoGlobal [_weaponNonPreset, 1];
};

_container addItemCargoGlobal [_muzzle, 1];
_container addItemCargoGlobal [_pointer, 1];
Expand Down
5 changes: 5 additions & 0 deletions addons/common/test_inventory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,10 @@ TEST_TRUE(_result,_funcName);
TEST_TRUE(count (weaponCargo _container) == 2,_funcName);
clearWeaponCargoGlobal _container;

_container addWeaponCargoGlobal ["arifle_MX_ACO_pointer_F", 1];
_result = [_container, "arifle_MX_F"] call CBA_fnc_removeWeaponCargo;
TEST_TRUE(count (weaponCargo _container) == 0 && count (itemCargo _container) == 2,_funcName);
clearWeaponCargoGlobal _container;


deleteVehicle _container;