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
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.
Important
Avoid passing an empty string
""to this command as it will create a warning dialog:This message will show once per mission restart.
object canAdd item
Parameters:
Returns: Boolean
since arma3 1.56
object canAdd [item, count, ignoreSoldierMaxLoad]
Parameters:
object: Object - unit or containeritem: String - config classcount: Number - desired quantityignoreSoldierMaxLoad: Boolean - (Optional, default false) true to ignore 'soldierMaxLoad' param, container's maxLoad is still counted (since arma3 2.18)Returns: Boolean
since arma3 2.10
weapon canAdd item
Parameters:
Returns: Boolean
since arma3 2.10
weapon canAdd [attachment, slot]
Parameters:
weapon: String - weapon class nameattachment: String - attachment class nameslot: String - slot class name (defined under WeaponSlotsInfo class in weapon config), for example:
Returns: Boolean
since arma3 2.10
weapon canAdd [magazine, muzzle]
Parameters:
weapon: String - weapon class namemagazine: String - magazine class namemuzzle: String - muzzle class nameReturns: Boolean
<sqf
if (player canAdd "FirstAidKit") then { player addItem "FirstAidKit"; } else { hint "Not enough space"; }; </sqf>
if (_box canAdd "FirstAidKit") then
{
_box addWeaponCargo ["FirstAidKit", 1];
}
else
{
hint "Not enough space";
};
car canAdd [currentWeapon player, 50];
// check if attachment can be loaded
"arifle_Katiba_GL_F" canAdd "acc_pointer_IR";
"arifle_Katiba_GL_F" canAdd ["acc_pointer_IR", "PointerSlot"];
// 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"];
canAddItemToBackpack · canAddItemToUniform · canAddItemToVest · compatibleMagazines · compatibleItems · compatibleWeapons
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
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];
};