{"name":"canAdd","operator":null,"title":"canAdd","type":"command","url":"https://community.bistudio.com/wiki/canAdd","revid":376862,"updated":"2025-12-08T21:18:49Z","groups":["Unit Inventory"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"0.70"}],"since":{"game":"arma3","name":"Arma 3","version":"0.70"},"arma3_since":"0.70","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Checks if given object can be stored in inventory of given object or any inventory container (uniform, vest, backpack) of given unit.\n\nBefore Arma 3 v2.10 this comment verified only the biggest container when multiple items were queried; now it checks all containers.\n\n> [!IMPORTANT]\n> Avoid passing an empty string `\"\"` to this command as it will create a warning dialog:\n>\n> This message will show once per mission restart.","syntaxes":[{"syntax":"object canAdd item","since":null,"effect":null,"exec":null,"params":[{"name":"object","type":"Object","optional":false,"default":null,"description":"unit or container","types":["Object"],"since":null,"text":"object: Object - unit or container"},{"name":"item","type":"String","optional":false,"default":null,"description":"config class","types":["String"],"since":null,"text":"item: String - config class"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"object","types":["Object"]},"right":{"text":"item","types":["String"]}},{"syntax":"object canAdd [item, count, ignoreSoldierMaxLoad]","since":"arma3 1.56","effect":null,"exec":null,"params":[{"name":"object","type":"Object","optional":false,"default":null,"description":"unit or container","types":["Object"],"since":null,"text":"object: Object - unit or container"},{"name":"item","type":"String","optional":false,"default":null,"description":"config class","types":["String"],"since":null,"text":"item: String - config class"},{"name":"count","type":"Number","optional":false,"default":null,"description":"desired quantity","types":["Number"],"since":null,"text":"count: Number - desired quantity"},{"name":"ignoreSoldierMaxLoad","type":"Boolean","optional":true,"default":"false","description":"true to ignore 'soldierMaxLoad' param, container's maxLoad is still counted","types":["Boolean"],"since":"arma3 2.18","text":"ignoreSoldierMaxLoad: Boolean - (Optional, default false) true to ignore 'soldierMaxLoad' param, container's maxLoad is still counted"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"object","types":["Object"]},"right":{"text":"[item, count, ignoreSoldierMaxLoad]","types":["Array"]}},{"syntax":"weapon canAdd item","since":"arma3 2.10","effect":null,"exec":null,"params":[{"name":"weapon","type":"String","optional":false,"default":null,"description":"weapon class name","types":["String"],"since":null,"text":"weapon: String - weapon class name"},{"name":"item","type":"String","optional":false,"default":null,"description":"config class of magazine or attachment","types":["String"],"since":null,"text":"item: String - config class of magazine or attachment"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"weapon","types":["String"]},"right":{"text":"item","types":["String"]}},{"syntax":"weapon canAdd [attachment, slot]","since":"arma3 2.10","effect":null,"exec":null,"params":[{"name":"weapon","type":"String","optional":false,"default":null,"description":"weapon class name","types":["String"],"since":null,"text":"weapon: String - weapon class name"},{"name":"attachment","type":"String","optional":false,"default":null,"description":"attachment class name","types":["String"],"since":null,"text":"attachment: String - attachment class name"},{"name":"slot","type":"String","optional":false,"default":null,"description":"slot class name (defined under **WeaponSlotsInfo** class in weapon config), for example:\n- \"CowsSlot\" for optics\n- \"MuzzleSlot\" for silencers\n- \"PointerSlot\" for laser pointers and flashlights\n- \"UnderBarrelSlot\" for bipods","types":["String"],"since":null,"text":"slot: String - slot class name (defined under **WeaponSlotsInfo** class in weapon config), for example:\n- \"CowsSlot\" for optics\n- \"MuzzleSlot\" for silencers\n- \"PointerSlot\" for laser pointers and flashlights\n- \"UnderBarrelSlot\" for bipods"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"weapon","types":["String"]},"right":{"text":"[attachment, slot]","types":["Array"]}},{"syntax":"weapon canAdd [magazine, muzzle]","since":"arma3 2.10","effect":null,"exec":null,"params":[{"name":"weapon","type":"String","optional":false,"default":null,"description":"weapon class name","types":["String"],"since":null,"text":"weapon: String - weapon class name"},{"name":"magazine","type":"String","optional":false,"default":null,"description":"magazine class name","types":["String"],"since":null,"text":"magazine: String - magazine class name"},{"name":"muzzle","type":"String","optional":false,"default":null,"description":"muzzle class name","types":["String"],"since":null,"text":"muzzle: String - muzzle class name"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"weapon","types":["String"]},"right":{"text":"[magazine, muzzle]","types":["Array"]}}],"examples":[{"text":"<sqf\n>if (player canAdd \"FirstAidKit\") then\n{\n\tplayer addItem \"FirstAidKit\";\n}\nelse\n{\n\thint \"Not enough space\";\n};\n</sqf>","code":[]},{"text":"```sqf\nif (_box canAdd \"FirstAidKit\") then\n{\n    _box addWeaponCargo [\"FirstAidKit\", 1];\n}\nelse\n{\n    hint \"Not enough space\";\n};\n```","code":["if (_box canAdd \"FirstAidKit\") then\n{\n\t_box addWeaponCargo [\"FirstAidKit\", 1];\n}\nelse\n{\n\thint \"Not enough space\";\n};"]},{"text":"```sqf\ncar canAdd [currentWeapon player, 50];\n```","code":["car canAdd [currentWeapon player, 50];"]},{"text":"```sqf\n// check if attachment can be loaded\n\"arifle_Katiba_GL_F\" canAdd \"acc_pointer_IR\";\n\"arifle_Katiba_GL_F\" canAdd [\"acc_pointer_IR\", \"PointerSlot\"];\n```","code":["// check if attachment can be loaded\n\"arifle_Katiba_GL_F\" canAdd \"acc_pointer_IR\";\n\"arifle_Katiba_GL_F\" canAdd [\"acc_pointer_IR\", \"PointerSlot\"];"]},{"text":"```sqf\n// check if magazine can be loaded\n\"arifle_Katiba_GL_F\" canAdd \"30Rnd_65x39_caseless_green\";\n\"arifle_Katiba_GL_F\" canAdd [\"30Rnd_65x39_caseless_green\", \"this\"];\n\"arifle_Katiba_GL_F\" canAdd [\"1Rnd_SmokeRed_Grenade_shell\", \"EGLM\"];\n```","code":["// check if magazine can be loaded\n\"arifle_Katiba_GL_F\" canAdd \"30Rnd_65x39_caseless_green\";\n\"arifle_Katiba_GL_F\" canAdd [\"30Rnd_65x39_caseless_green\", \"this\"];\n\"arifle_Katiba_GL_F\" canAdd [\"1Rnd_SmokeRed_Grenade_shell\", \"EGLM\"];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["canAddItemToBackpack","canAddItemToUniform","canAddItemToVest","compatibleMagazines","compatibleItems","compatibleWeapons"],"notes":[{"user":"Jonpas","date":"2015-11-29T00:02:00Z","text":"Can also be used on any object that has inventory, not only player inventory containers.\n\nWhere **_box** is **B_supplyCrate_F**:\n\n```sqf\n// empty\n_box canAdd \"FirstAidKit\"; // returns true\n\n// full\n_box canAdd \"FirstAidKit\"; // returns false\n```"},{"user":"Demellion","date":"2017-02-11T18:40:00Z","text":"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:\n\n```sqf\nprivate _container = selectRandom [uniformContainer player, vestContainer player, backpackContainer player];\nif (_container canAdd \"Rangefinder\") then\n{\n    _container addItemCargoGlobal [\"Rangefinder\", 1];\n};\n```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Unit Inventory","Introduced with Arma 3 version 0.70","Scripting Commands"]}