canAddItemToBackpack: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[\[Category:[ _]?Scripting[ _]Commands[ _]Arma[ _]3(\|.*)]]" to "{{GameCategory|arma3|Scripting Commands}}")
 
(67 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3
|version1= 1.04


|1.04|Game version=
|gr1= Containers


|gr1 = Containers |GROUP1=
|descr= Checks if given object can be stored into soldier's backpack.


{{Feature|important|
Avoid passing an empty string <sqf inline>""</sqf> to this command as it will create a warning dialog:
[[File:a3 warning badvehicletype.jpg|none|alt= Warning Message: Bad vehicle type|Warning Message: Bad vehicle type]]
This message will show once per mission restart.
}}


____________________________________________________________________________________________
|s1= unit [[canAddItemToBackpack]] item


| Checks if given object can be stored into soldier's backpack. |DESCRIPTION=
|p1= unit: [[Object]]
____________________________________________________________________________________________


| unit [[canAddItemToBackpack]] item |SYNTAX=
|p2= item: [[String]]


|p1= unit: [[Object]] |PARAMETER1=
|r1= [[Boolean]]


|p2= item: [[String]] |PARAMETER2=
|s2= unit [[canAddItemToBackpack]] [item, count, ignoreSoldierMaxLoad]


| [[Boolean]] |RETURNVALUE=  
|s2since= arma3 1.56


|s2= unit [[canAddItemToBackpack]] [item, count] {{since|arma3|1.55.133607|y}} |SYNTAX2=
|p21= unit: [[Object]]


|p21= unit: [[Object]] |PARAMETER21=
|p22= item: [[String]]


|p22= [item, count]: [[Array]] |PARAMETER22=
|p23= count: [[Number]]


|p23= item: [[String]] |PARAMETER23=
|p24= ignoreSoldierMaxLoad: [[Boolean]] - (Optional, default [[false]]) [[true]] to ignore 'soldierMaxLoad' param, container [[maxLoad]] is still counted.
|p24since= arma3 2.18


|p24= count: [[Number]]   |PARAMETER24=
|r2= [[Boolean]]


|r2= [[Boolean]] |RETURNVALUE2=
|x1= <sqf>if (player canAddItemToBackpack "HandGrenade") then { player addItemToBackpack _item } else { hint "no room!" };</sqf>


|x1= <code>_item = "HandGrenade";
|seealso= [[canAdd]] [[canAddItemToUniform]] [[canAddItemToVest]] [[backpackContainer]] [[firstBackpack]] [[unitBackpack]] [[backpack]] [[backpackCargo]] [[getBackpackCargo]] [[backpackItems]] [[addBackpack]] [[addBackpackCargo]] [[addBackpackCargoGlobal]] [[removeBackpack]] [[clearBackpackCargo]] [[clearBackpackCargoGlobal]] [[clearAllItemsFromBackpack]] [[loadBackpack]] [[backpackSpaceFor]] [[addItemToBackpack]] [[removeItemFromBackpack]] [[everyBackpack]]
_fits = [[player]] [[canAddItemToBackpack]] _item;
}}
[[if]] (_fits) [[then]] {
[[player]] [[addItemToBackpack]] _item;
} [[else]] {
[[hint]] "no room!";
};</code>|EXAMPLE1=
____________________________________________________________________________________________
 
| [[canAdd]], [[canAddItemToUniform]], [[canAddItemToVest]], [[backpackContainer]], [[firstBackpack]], [[unitBackpack]], [[backpack]], [[backpackCargo]], [[getBackpackCargo]], [[backpackItems]], [[addBackpack]], [[addBackpackCargo]], [[addBackpackCargoGlobal]], [[removeBackpack]], [[clearBackpackCargo]], [[clearBackpackCargoGlobal]], [[clearAllItemsFromBackpack]], [[loadBackpack]], [[backpackSpaceFor]], [[addItemToBackpack]], [[removeItemFromBackpack]], [[everyBackpack]] |SEEALSO=


| |MPBEHAVIOUR=
{{Note
|user= AgentRev
|timestamp= 20220329045658
|text= This command is very unreliable, along with all other [[canAdd]] commands. For example, in the inventory screen, an empty {{hl|"B_Bergen_dgtl_F"}} backpack can fit a total of 30 {{hl|"5Rnd_127x108_APDS_Mag"}} mags. However, <sqf inline>player canAddItemToBackpack "5Rnd_127x108_APDS_Mag"</sqf> 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...<br>
I wrote a function almost 9 years ago to bypass this (surprisingly still existing) bug. You can check it {{Link|https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/dev/client/functions/fn_fitsInventory.sqf|here}}, with a usage example {{Link|https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/dc41623f154d6c5be683374784aba201a0628e60/client/functions/addWeaponInventory.sqf#L18-L20|here}}.
}}
}}
<h3 style='display:none'>Notes</h3>
<dl class='command_description'>
<!-- Note Section BEGIN -->
<!-- Note Section END -->
</dl>
<h3 style='display:none'>Bottom Section</h3>
{{GameCategory|arma3|Scripting Commands}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]

Latest revision as of 11:33, 3 September 2024

Hover & click on the images for description

Description

Description:
Checks if given object can be stored into soldier's backpack.
Avoid passing an empty string "" to this command as it will create a warning dialog:
Warning Message: Bad vehicle type
This message will show once per mission restart.
Groups:
Containers

Syntax

Syntax:
unit canAddItemToBackpack item
Parameters:
unit: Object
item: String
Return Value:
Boolean

Alternative Syntax

Syntax:
unit canAddItemToBackpack [item, count, ignoreSoldierMaxLoad]
Parameters:
unit: Object
item: String
count: Number
since Arma 3 logo black.png2.18
ignoreSoldierMaxLoad: Boolean - (Optional, default false) true to ignore 'soldierMaxLoad' param, container maxLoad is still counted.
Return Value:
Boolean

Examples

Example 1:
if (player canAddItemToBackpack "HandGrenade") then { player addItemToBackpack _item } else { hint "no room!" };

Additional Information

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

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
AgentRev - c
Posted on Mar 29, 2022 - 04:56 (UTC)
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...
I wrote a function almost 9 years ago to bypass this (surprisingly still existing) bug. You can check it here, with a usage example here.