{"name":"canAddItemToBackpack","operator":null,"title":"canAddItemToBackpack","type":"command","url":"https://community.bistudio.com/wiki/canAddItemToBackpack","revid":369124,"updated":"2024-09-03T10:33:08Z","groups":["Containers"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.04"}],"since":{"game":"arma3","name":"Arma 3","version":"1.04"},"arma3_since":"1.04","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Checks if given object can be stored into soldier's backpack.\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":"unit canAddItemToBackpack item","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"item","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"item: String"}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"item","types":["String"]}},{"syntax":"unit canAddItemToBackpack [item, count, ignoreSoldierMaxLoad]","since":"arma3 1.56","effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"item","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"item: String"},{"name":"count","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"count: Number"},{"name":"ignoreSoldierMaxLoad","type":"Boolean","optional":true,"default":"false","description":"true to ignore 'soldierMaxLoad' param, container maxLoad is still counted.","types":["Boolean"],"since":"arma3 2.18","text":"ignoreSoldierMaxLoad: Boolean - (Optional, default false) true to ignore 'soldierMaxLoad' param, container maxLoad is still counted."}],"returns":{"type":"Boolean","types":["Boolean"],"description":null,"text":"Boolean"},"form":"binary","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"[item, count, ignoreSoldierMaxLoad]","types":["Array"]}}],"examples":[{"text":"```sqf\nif (player canAddItemToBackpack \"HandGrenade\") then { player addItemToBackpack _item } else { hint \"no room!\" };\n```","code":["if (player canAddItemToBackpack \"HandGrenade\") then { player addItemToBackpack _item } else { hint \"no room!\" };"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["canAdd","canAddItemToUniform","canAddItemToVest","backpackContainer","firstBackpack","unitBackpack","backpack","backpackCargo","getBackpackCargo","backpackItems","addBackpack","addBackpackCargo","addBackpackCargoGlobal","removeBackpack","clearBackpackCargo","clearBackpackCargoGlobal","clearAllItemsFromBackpack","loadBackpack","backpackSpaceFor","addItemToBackpack","removeItemFromBackpack","everyBackpack"],"notes":[{"user":"AgentRev","date":"2022-03-29T04:56:58Z","text":"This command is very unreliable, along with all other canAdd commands. For example, in the inventory screen, an empty `\"B_Bergen_dgtl_F\"` backpack can fit a total of 30 `\"5Rnd_127x108_APDS_Mag\"` mags. However, `player canAddItemToBackpack \"5Rnd_127x108_APDS_Mag\"` starts returning false once there are 17 in the backpack. Furthermore, if the player has equipped an empty PCML launcher (without any missile in his inventory), the command starts returning false once there are only 11, despite the fact that the launcher has no effect on backpack space...\n\nI wrote a function almost 9 years ago to bypass this (surprisingly still existing) bug. You can check it [here](https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/dev/client/functions/fn_fitsInventory.sqf), with a usage example [here](https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/dc41623f154d6c5be683374784aba201a0628e60/client/functions/addWeaponInventory.sqf#L18-L20)."}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Containers","Introduced with Arma 3 version 1.04","Scripting Commands"]}