canAdd: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|PARAMETER1= |p22=" to "|PARAMETER21= |p22=")
Line 10: Line 10:
____________________________________________________________________________________________
____________________________________________________________________________________________


| object '''canAdd''' item |SYNTAX=
| object [[canAdd]] item |SYNTAX=


|p1= object: [[Object]] - unit or container   |PARAMETER1=  
|p1= object: [[Object]] - unit or container |PARAMETER1=  


|p2= item: [[String]] - Config class |PARAMETER2=  
|p2= item: [[String]] - Config class |PARAMETER2=  


| [[Boolean]] |RETURNVALUE=  
| [[Boolean]] |RETURNVALUE=
____________________________________________________________________________________________
 
|s2= object [[canAdd]] [item, count] {{since|arma3|1.55.133607|y}} |SYNTAX2=
 
|p21= object: [[Object]] - unit or container  |PARAMETER21=
 
|p22= [item, count]: [[Array]] |PARAMETER22=


| s2 =object '''canAdd''' [item, count]       (''Since Arma 3 v1.55.133607'') |SYNTAX2=
|p23= item: [[String]] - Config class |PARAMETER23=


|p21= object: [[Object]] - unit or container  |PARAMETER21= 
|p24= count: [[Number]] - desired quantity  |PARAMETER24=
|p22= [item, count]: [[Array]] |PARAMETER1=
|p23= item: [[String]] - Config class |PARAMETER2=
|p24= count: [[Number]] - desired quantity  |PARAMETER1=  


| r2= [[Boolean]] |RETURNVALUE=  
| r2= [[Boolean]] |RETURNVALUE2=
____________________________________________________________________________________________


|x1= <code>[[if]] ([[player]] [[canAdd]] "FirstAidKit") [[then]] {
|x1= <code>[[if]] ([[player]] [[canAdd]] "FirstAidKit") [[then]] {
Line 32: Line 37:
   [[hint]] "Not enough space";
   [[hint]] "Not enough space";
};
};
</code>|EXAMPLE1=  
</code>|EXAMPLE1=


|x2= <code>[[if]] (_box [[canAdd]] "FirstAidKit") [[then]] {
|x2= <code>[[if]] (_box [[canAdd]] "FirstAidKit") [[then]] {
Line 39: Line 44:
   [[hint]] "Not enough space";
   [[hint]] "Not enough space";
};
};
</code>|EXAMPLE2=
</code>|EXAMPLE2=
 
|x3= <code>car [[canAdd]] <nowiki>[</nowiki>[[currentWeapon]] [[player]], 50];</code>|EXAMPLE3=


|x3= <code>car [[canAdd]] [<nowiki/>[[currentWeapon]] [[player]], 50];</code> |EXAMPLE3=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[canAddItemToBackpack]], [[canAddItemToUniform]], [[canAddItemToVest]] |SEEALSO=  
| [[canAddItemToBackpack]], [[canAddItemToUniform]], [[canAddItemToVest]] |SEEALSO=


| |MPBEHAVIOUR=  
| |MPBEHAVIOUR=
____________________________________________________________________________________________
}}
}}


Line 59: Line 62:


<h3 style='display:none'>Bottom Section</h3>
<h3 style='display:none'>Bottom Section</h3>
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
Line 95: Line 97:
</dd>
</dd>
</dl>
</dl>


<!-- DISCONTINUE Notes -->
<!-- DISCONTINUE Notes -->

Revision as of 00:33, 22 December 2019

Hover & click on the images for description

Description

Description:
Checks if given object can be stored in inventory of given object or any inventory container (uniform, vest, backpack) of given unit.
Groups:
Uncategorised

Syntax

Syntax:
object canAdd item
Parameters:
object: Object - unit or container
item: String - Config class
Return Value:
Boolean

Alternative Syntax

Syntax:
object canAdd [item, count] Template:since
Parameters:
object: Object - unit or container
[item, count]: Array
item: String - Config class
count: Number - desired quantity
Return Value:
Boolean

Examples

Example 1:
if (player canAdd "FirstAidKit") then { player addItem "FirstAidKit"; } else { hint "Not enough space"; };
Example 2:
if (_box canAdd "FirstAidKit") then { _box addWeaponCargo ["FirstAidKit", 1]; } else { hint "Not enough space"; };
Example 3:
car canAdd [currentWeapon player, 50];

Additional Information

See also:
canAddItemToBackpackcanAddItemToUniformcanAddItemToVest

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

Notes

Bottom Section

Posted on November 29, 2015 - 00:02 (UTC)
Jonpas
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"; -> true // Full _box canAdd "FirstAidKit"; -> false
Posted on February 11, 2017 - 18:40 (UTC)
Demellion
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:
_i = [(uniformContainer player),(vestContainer player),(backpackContainer player)] call BIS_fnc_selectRandom; if (_i canAdd "Rangefinder") then { _i addItemCargoGlobal ["Rangefinder",1]; };