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

Filtered getUnitLoadout #1238

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 4 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class CfgFunctions {
PATHTO_FNC(addBinocularMagazine);
PATHTO_FNC(removeBinocularMagazine);
PATHTO_FNC(randomizeFacewear);
PATHTO_FNC(getUnitLoadout);
PATHTO_FNC(filterLoadout);
PATHTO_FNC(addLoadoutFilter);
PATHTO_FNC(removeLoadoutFilter);
};

class Cargo {
Expand Down
1 change: 1 addition & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GVAR(featureCamerasNames) = [
call COMPILE_FILE(init_gauss);
call COMPILE_FILE(init_perFrameHandler);
call COMPILE_FILE(init_delayLess);
call COMPILE_FILE(init_filteredLoadout);

// Due to activateAddons being overwritten by eachother (only the last executed command will be active), we apply this bandaid
GVAR(addons) = call (uiNamespace getVariable [QGVAR(addons), {[]}]);
Expand Down
43 changes: 43 additions & 0 deletions addons/common/fnc_addLoadoutFilter.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_addLoadoutFilter

Description:
Add a filter for CBA_fnc_getUnitLoadout.

Parameters:
_function - The function you wish to execute. <CODE>

Passed Arguments:
_this <ARRAY>
0: _loadout - A getUnitLoadout array
1: _handle - A number representing the handle of the function. Same as '_handle' returned by this function. <NUMBER>

Returns:
_handle - A number representing the handle of the function. Use this to remove the handler. <NUMBER>

Examples:
Remove the radio from loadouts
(begin example)
_handle = [{
params ["_loadout", "_handle"];
if ((_loadout select 9) select 2 == "ItemRadio") then {
(_loadout select 9) set [2, ""];
};
_loadout
}] call CBA_fnc_addLoadoutFilter;
(end)

Author:
SynixeBrett
---------------------------------------------------------------------------- */

params [["_function", {}, [{}]]];

if (_function isEqualTo {}) exitWith {-1};

private _handle = GVAR(filterLoadoutHandles) pushBack count GVAR(filterLoadoutArray);

GVAR(filterLoadoutArray) pushBack [_function, _handle];

_handle
30 changes: 30 additions & 0 deletions addons/common/fnc_filterLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_filterLoadout

Description:
Used to filter a getUnitLoadout array.

Parameters:
_loadout - getUnitLoadout array <ARRAY>

Example:
(begin example)
_loadout = [getUnitLoadout player] call CBA_fnc_filterLoadout;
(end)

Returns:
filtered getUnitLoadout array <ARRAY>

Author:
SynixeBrett
---------------------------------------------------------------------------- */
SCRIPT(filterLoadout);

params [["_loadout", [], [[]]]];

{
_loadout = [_loadout] call (_x select 0);
} forEach GVAR(filterLoadoutArray);

_loadout
28 changes: 28 additions & 0 deletions addons/common/fnc_getUnitLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getUnitLoadout

Description:
Return the loadout of a unit with CBA_fnc_filterLoadout applied.

Parameters:
_unit - Unit to get loadout of <OBJECT>

Returns:
_loadout - `getUnitLoadout` array <ARRAY>

Examples:
(begin example)
private _loadout = [player] call CBA_fnc_getUnitLoadout;
(end)

Author:
SynixeBrett
---------------------------------------------------------------------------- */
SCRIPT(getUnitLoadout);

params [["_unit", objNull, [objNull]]];

if (_unit isEqualTo objNull) exitWith {[]};

[getUnitLoadout _unit] call CBA_fnc_filterLoadout
54 changes: 54 additions & 0 deletions addons/common/fnc_removeLoadoutFilter.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_removeLoadoutFilter

Description:
Remove a handler that you have added using CBA_fnc_addLoadoutFilter.

Parameters:
_handle - The function handle you wish to remove. <NUMBER>

Returns:
true if removed successful, false otherwise <BOOLEAN>

Examples:
(begin example)
_handle = [myLoadoutFilter] call CBA_fnc_addLoadoutFilter;
sleep 10;
[_handle] call CBA_fnc_removeLoadoutFilter;
(end)

Author:
Nou & Jaynus, SynixeBrett
---------------------------------------------------------------------------- */

params [["_handle", -1, [0]]];

[{
params ["_handle"];

private _index = GVAR(filterLoadoutHandles) param [_handle];
if (isNil "_index") exitWith {false};

GVAR(filterLoadoutHandles) set [_handle, nil];
(GVAR(filterLoadoutArray) select _index) set [0, {}];

if (GVAR(filterLoadoutToRemove) isEqualTo []) then {
{
{
GVAR(filterLoadoutArray) set [_x, objNull];
} forEach GVAR(filterLoadoutToRemove);

GVAR(filterLoadoutArray) = GVAR(filterLoadoutArray) - [objNull];
GVAR(filterLoadoutToRemove) = [];

{
_x params ["", "_index"];
GVAR(filterLoadoutHandles) set [_index, _forEachIndex];
} forEach GVAR(filterLoadoutArray);
} call CBA_fnc_execNextFrame;
};

GVAR(filterLoadoutToRemove) pushBackUnique _index;
true
}, _handle] call CBA_fnc_directCall;
5 changes: 5 additions & 0 deletions addons/common/init_filteredLoadout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "script_component.hpp"

GVAR(filterLoadoutArray) = [];
GVAR(filterLoadoutHandles) = [];
GVAR(filterLoadoutToRemove) = [];