From 154a24340cc52ab494df9e620914ad4ed7b4b059 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:20:56 +0200 Subject: [PATCH] Common - Optimize and expand `CBA_fnc_addWeaponWithoutItems` (#1557) --- addons/common/fnc_addWeaponWithoutItems.sqf | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/addons/common/fnc_addWeaponWithoutItems.sqf b/addons/common/fnc_addWeaponWithoutItems.sqf index 9caf7edf2f..5e94446f04 100644 --- a/addons/common/fnc_addWeaponWithoutItems.sqf +++ b/addons/common/fnc_addWeaponWithoutItems.sqf @@ -3,28 +3,30 @@ Function: CBA_fnc_addWeaponWithoutItems Description: - Adds weapon to unit without attachments and without taking a magazine. + Adds weapon to unit without taking a magazine. Attachments will be removed by default, but can be kept by setting a parameter. Does not work on vehicles. Attempts to keep magazine ids for unrelated magazines. Parameters: - _unit - Unit to add the weapon to - _weapon - Weapon to add + _unit - Unit to add the weapon to + _weapon - Weapon to add + _removeLinkedItems - If linked items should be removed or not (Default: true) Returns: Nothing. Examples: (begin example) - [player, "arifle_mx_F"] CBA_fnc_addWeaponWithoutItems; + [player, "arifle_mx_F"] call CBA_fnc_addWeaponWithoutItems; + [player, "arifle_AK12_lush_arco_snds_pointer_bipod_F", false] call CBA_fnc_addWeaponWithoutItems; (end) Author: - commy2 + commy2, johnb43 ---------------------------------------------------------------------------- */ -params ["_unit", "_weapon"]; +params ["_unit", "_weapon", ["_removeLinkedItems", true, [true]]]; // config case private _compatibleMagazines = [_weapon, true] call CBA_fnc_compatibleMagazines; @@ -50,19 +52,16 @@ private _backpackMagazines = magazinesAmmoCargo _backpack select { _unit addWeapon _weapon; -if (primaryWeapon _unit == _weapon) then { - removeAllPrimaryWeaponItems _unit; -}; - -if (secondaryWeapon _unit == _weapon) then { - // 'removeAllSecondaryWeaponItems' does not exist - { - _unit removeSecondaryWeaponItem _x; - } forEach secondaryWeaponItems _unit; -}; - -if (handgunWeapon _unit == _weapon) then { - removeAllHandgunItems _unit; +if (_removeLinkedItems) then { + if (primaryWeapon _unit == _weapon) then { + removeAllPrimaryWeaponItems _unit; + }; + if (secondaryWeapon _unit == _weapon) then { + removeAllSecondaryWeaponItems _unit; + }; + if (handgunWeapon _unit == _weapon) then { + removeAllHandgunItems _unit; + }; }; {