ACE3/addons/arsenal/functions/fnc_removeVirtualItems.sqf
Neviothr 75f7ed7532
Utilize isNotEqualTo (#7929)
* Utilize isNotEqualTo

* undo changes to some files

* redo some changes, fix based on @Vdauphin 's comment

* fix validator issues

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2021-02-27 11:05:05 -06:00

83 lines
2.4 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Alganthe
* Remove virtual items to the provided target.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Items <ARRAY of strings> <BOOL>
* 2: Add globally <BOOL>
*
* Return Value:
* None
*
* Example:
* [_box, ["item1", "item2", "itemN"]] call ace_arsenal_fnc_removeVirtualItems
* [_box, true, false] call ace_arsenal_fnc_removeVirtualItems
*
* Public: Yes
*/
params [ ["_object", objNull, [objNull]], ["_items", [], [true, [""]]], ["_global", false, [false]] ];
if (_object == objNull) exitWith {};
if (_items isEqualType [] && {count _items == 0}) exitWith {};
private _cargo = _object getVariable [QGVAR(virtualItems), [
[[], [], []], // Weapons 0, primary, handgun, secondary
[[], [], [], []], // WeaponAccessories 1, optic,side,muzzle,bipod
[ ], // Magazines 2
[ ], // Headgear 3
[ ], // Uniform 4
[ ], // Vest 5
[ ], // Backpacks 6
[ ], // Goggles 7
[ ], // NVGs 8
[ ], // Binoculars 9
[ ], // Map 10
[ ], // Compass 11
[ ], // Radio slot 12
[ ], // Watch slot 13
[ ], // Comms slot 14
[ ], // WeaponThrow 15
[ ], // WeaponPut 16
[ ] // InventoryItems 17
]];
if (_items isEqualType true) then {
if (_items) then {
[_object, _global] call FUNC(removeBox);
_object setVariable [QGVAR(virtualItems), nil, _global];
};
} else {
// Make sure all items are in string form
_items = _items select {_x isEqualType "" && {_x != ""}};
{
if (_forEachIndex isEqualTo 0) then {
_cargo set [_forEachIndex, [(_x select 0) - _items, (_x select 1) - _items, (_x select 2) - _items]];
} else {
if (_forEachIndex isEqualTo 1) then {
_cargo set [_forEachIndex, [(_x select 0) - _items, (_x select 1) - _items, (_x select 2) - _items, (_x select 3) - _items]];
} else {
_cargo set [_cargo find _x, _x - _items];
};
};
} foreach _cargo;
private _itemCount = {
if (_x isEqualTo (_cargo select 0) || {_x isEqualTo (_cargo select 1)}) then {
(_x isNotEqualTo [[],[],[]] || {_x isEqualTo [[],[],[],[]]})
} else {
(_x isNotEqualTo [])
};
} count _cargo;
if (_itemCount == 0) then {
[_object, _global] call FUNC(removeBox);
} else {
_object setVariable [QGVAR(virtualItems), _cargo, _global];
};
};