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

Common - Optimize and expand CBA_fnc_addWeaponWithoutItems #1557

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 19 additions & 20 deletions addons/common/fnc_addWeaponWithoutItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
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 <OBEJCT>
_weapon - Weapon to add <STRING>
_unit - Unit to add the weapon to <OBEJCT>
_weapon - Weapon to add <STRING>
_removeLinkedItems - If linked items should be removed or not <BOOLEAN> (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;
private _compatibleMagazines = compatibleMagazines _weapon;
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

private _uniform = uniformContainer _unit;
private _uniformMagazines = magazinesAmmoCargo _uniform select {
Expand All @@ -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;
};
};

{
Expand Down
2 changes: 1 addition & 1 deletion addons/main/script_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD

// MINIMAL required version for the Mod. Components can specify others..
#define REQUIRED_VERSION 2.06
#define REQUIRED_VERSION 2.10

/*
// Defined DEBUG_MODE_NORMAL in a few CBA_fncs to prevent looped logging :)
Expand Down