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 CBA_fnc_uniqueUnitItems #902

Merged
merged 6 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CfgFunctions {
PATHTO_FNC(removeWeapon);
PATHTO_FNC(removeMagazine);
PATHTO_FNC(removeItem);
PATHTO_FNC(uniqueUnitItems);
PATHTO_FNC(weaponComponents);
PATHTO_FNC(dropWeapon);
PATHTO_FNC(dropMagazine);
Expand Down
46 changes: 46 additions & 0 deletions addons/common/fnc_uniqueUnitItems.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_uniqueUnitItems

Description:
Retrievs a unique list of items in the units inventory.

Parameters:
_unit - Unit to retrieve the items from
_weaponItems - Include weapons, attachments, loaded magazines (Default: false)
_backpack - Include items in backpack (Default: true)
_vest - Include items in vest (Default: true)
_uniform - Include items in uniform (Default: true)

Example:
(begin example)
_allItems = [player, true, false] call CBA_fnc_uniqueUnitItems
(end)

Returns:
Array of item classnames <ARRAY>

Author:
Dedmen
---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(uniqueUnitItems);

params [["_unit", objNull, [objNull]], ["_weaponItems", true, [true]], ["_backpack", true, [true]], ["_vest", true, [true]], ["_uniform", true, [true]]];
Copy link
Contributor Author

@dedmen dedmen May 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah!
["_weaponItems", true, [true]] default false? duh..


private _allItems = (assignedItems _unit);
if (_uniform) then {_allItems append ((getItemCargo (uniformContainer _unit)) select 0);};
if (_vest) then {_allItems append ((getItemCargo (vestContainer _unit)) select 0);};
if (_backpack) then {_allItems append ((getItemCargo (backpackContainer _unit)) select 0);};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parenthesis aaaaa

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfectly fine here to quickly see the order they are executed in.

Copy link
Contributor

@commy2 commy2 Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaaaa

if (_uniform) then {
    _allItems append (getItemCargo uniformContainer _unit select 0);
};

if (_vest) then {
    _allItems append (getItemCargo vestContainer _unit select 0);
};

if (_backpack) then {
    _allItems append (getItemCargo backpackContainer _unit select 0);
};

T_T

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getItemCargo uniformContainer _unit select 0

this is just unreadable IMO.


if (_weaponItems) then {
_allItems append (primaryWeaponItems _unit);
_allItems append (secondaryWeaponItems _unit);
_allItems append (handgunItems _unit);
_allItems append [
primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit,
primaryWeaponMagazine _unit, secondaryWeaponMagazine _unit, handgunMagazine _unit
];
_allItems pushBack (_unit call CBA_fnc_binocularMagazine);
};
Copy link
Contributor

@commy2 commy2 Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (_weaponItems) then {
    _allItems append [
        primaryWeapon _unit,
        secondaryWeapon _unit,
        handgunWeapon _unit
    ];
    _allItems append primaryWeaponItems _unit;
    _allItems append secondaryWeaponItems _unit;
    _allItems append handgunItems _unit;
    _allItems append primaryWeaponMagazine _unit;
    _allItems append secondaryWeaponMagazine _unit;
    _allItems append handgunMagazine _unit;
    _allItems pushBack (_unit call CBA_fnc_binocularMagazine);
};

Copy link
Contributor

@commy2 commy2 Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that primaryWeaponMagazine-no S etc. report ARRAY, exactly like the XItems versions.


_allItems arrayIntersect _allItems //Remove duplicates