canAdd
Jump to navigation
Jump to search
Description
- Description:
- Checks if given object can be stored in inventory of given object or any inventory container (uniform, vest, backpack) of given unit.
Before Arma 3 v2.10 this comment verified only the biggest container when multiple items were queried; now it checks all containers. - Groups:
- Unit Inventory
Syntax 1
- Syntax:
- object canAdd item
- Parameters:
- object: Object - unit or container
- item: String - config class
- Return Value:
- Boolean
Syntax 2
- Syntax:
- object canAdd [item, count, ignoreSoldierMaxLoad]
- Parameters:
- object: Object - unit or container
- item: String - config class
- count: Number - desired quantity
- since 2.18
- ignoreSoldierMaxLoad: Boolean - (Optional, default false) true to ignore 'soldierMaxLoad' param, container's maxLoad is still counted
- Return Value:
- Boolean
Syntax 3
- Syntax:
- weapon canAdd item
- Parameters:
- weapon: String - weapon class name
- item: String - config class of magazine or attachment
- Return Value:
- Boolean
Syntax 4
- Syntax:
- weapon canAdd [attachment, slot]
- Parameters:
- weapon: String - weapon class name
- attachment: String - attachment class name
- slot: String - slot class name (defined under WeaponSlotsInfo class in weapon config)
- Return Value:
- Boolean
Syntax 5
- Syntax:
- weapon canAdd [magazine, muzzle]
- Parameters:
- weapon: String - weapon class name
- magazine: String - magazine class name
- muzzle: String - muzzle class name
- Return Value:
- Boolean
Examples
- Example 1:
- Example 2:
- if (_box canAdd "FirstAidKit") then { _box addWeaponCargo ["FirstAidKit", 1]; } else { hint "Not enough space"; };
- Example 3:
- Example 4:
- // check if attachment can be loaded "arifle_Katiba_GL_F" canAdd "acc_pointer_IR"; "arifle_Katiba_GL_F" canAdd ["acc_pointer_IR", "PointerSlot"];
- Example 5:
- // check if magazine can be loaded "arifle_Katiba_GL_F" canAdd "30Rnd_65x39_caseless_green"; "arifle_Katiba_GL_F" canAdd ["30Rnd_65x39_caseless_green", "this"]; "arifle_Katiba_GL_F" canAdd ["1Rnd_SmokeRed_Grenade_shell", "EGLM"];
Additional Information
- See also:
- canAddItemToBackpack canAddItemToUniform canAddItemToVest compatibleMagazines compatibleItems
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Nov 29, 2015 - 00:02 (UTC)
-
Can also be used on any object that has inventory, not only player inventory containers.
Where _box is B_supplyCrate_F:// empty _box canAdd "FirstAidKit"; // returns true // full _box canAdd "FirstAidKit"; // returns false
- Posted on Feb 11, 2017 - 18:40 (UTC)
-
This can also be used as alternative to canAddItemToBackpack, canAddItemToUniform, canAddItemToVest where container might not be strictly defined. In some cases it might be a good optimisation for your code, where you also don't need to perform checks on which type of player container this is. Example:
private _container = selectRandom [uniformContainer player, vestContainer player, backpackContainer player]; if (_container canAdd "Rangefinder") then { _container addItemCargoGlobal ["Rangefinder", 1]; };