canAdd: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|= Game version" to "|Game version=")
m (Text replacement - "since= Arma3" to "since= arma3")
 
(79 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3
|version1= 0.70


|0.70|Game version=
|gr1= Unit Inventory
____________________________________________________________________________________________


| Checks if given object can be stored in inventory of given object or any inventory container ([[uniform]], [[vest]], [[backpack]]) of given unit. |DESCRIPTION=
|descr= Checks if given object can be stored in inventory of given object or any inventory container ([[uniform]], [[vest]], [[backpack]]) of given unit.<br>
____________________________________________________________________________________________
Before {{arma3}} v2.10 this comment verified only the biggest container when multiple items were queried; now it checks all containers.


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


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


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


| [[Boolean]] |RETURNVALUE=
|r1= [[Boolean]]


| s2 =object '''canAdd''' [item, count]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(''Since Arma 3 v1.55.133607'') |SYNTAX=
|s2= object [[canAdd]] [item, count, ignoreSoldierMaxLoad]


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


| r2= [[Boolean]] |RETURNVALUE=
|p21= object: [[Object]] - unit or container


|x1= <code>[[if]] ([[player]] [[canAdd]] "FirstAidKit") [[then]] {
|p22= item: [[String]] - config class
  [[player]] [[addItem]] "FirstAidKit";
 
} [[else]] {
|p23= count: [[Number]] - desired quantity
  [[hint]] "Not enough space";
 
};
|p24= ignoreSoldierMaxLoad: [[Boolean]] - (Optional, default [[false]]) [[true]] to ignore 'soldierMaxLoad' param, container's [[maxLoad]] is still counted
</code>|EXAMPLE1=  
|p24since= arma3 2.18
 
|r2= [[Boolean]]
 
|s3= weapon [[canAdd]] item
 
|s3since= arma3 2.10
 
|p41= weapon: [[String]] - weapon class name
 
|p42= item: [[String]] - config class of magazine or attachment
 
|r3= [[Boolean]]
 
|s4= weapon [[canAdd]] [attachment, slot]
 
|s4since= arma3 2.10
 
|p61= weapon: [[String]] - weapon class name


|x2= <code>[[if]] (_box [[canAdd]] "FirstAidKit") [[then]] {
|p62= attachment: [[String]] - attachment class name
  _box [[addWeaponCargo]] ["FirstAidKit", 1];
} [[else]] {
  [[hint]] "Not enough space";
};
</code>|EXAMPLE2=


|x3= <code>car [[canAdd]] <nowiki>[</nowiki>[[currentWeapon]] [[player]], 50];</code>|EXAMPLE3=
|p63= slot: [[String]] - slot class name (defined under '''WeaponSlotsInfo''' class in weapon config)


____________________________________________________________________________________________
|r4= [[Boolean]]


| [[canAddItemToBackpack]], [[canAddItemToUniform]], [[canAddItemToVest]] |SEEALSO=
|s5= weapon [[canAdd]] [magazine, muzzle]


| |MPBEHAVIOUR=  
|s5since= arma3 2.10
____________________________________________________________________________________________
}}


<h3 style='display:none'>Notes</h3>
|p81= weapon: [[String]] - weapon class name
<dl class='command_description'>
<!-- Note Section BEGIN -->


<!-- Note Section END -->
|p82= magazine: [[String]] - magazine class name
</dl>


<h3 style='display:none'>Bottom Section</h3>
|p83= muzzle: [[String]] - muzzle class name
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
|r5= [[Boolean]]
<dl class="command_description">
<dd class="notedate">Posted on November 29, 2015 - 00:02 (UTC)</dd>
<dt class="note">[[User:Jonpas|Jonpas]]</dt>
<dd class="note">
Can also be used on any object that has inventory, not only player inventory containers.<br>
<br>
Where <b>_box</b> is <b>B_supplyCrate_F</b>:
<code>// Empty
_box canAdd "FirstAidKit";
-> true


// Full
|x1= <sqf
_box canAdd "FirstAidKit";
>if (player canAdd "FirstAidKit") then
-> false
{
</code>
player addItem "FirstAidKit";
</dd>
}
</dl>
else
{
hint "Not enough space";
};
</sqf>


<dl class="command_description">
|x2= <sqf>
<dd class="notedate">Posted on February 11, 2017 - 18:40 (UTC)</dd>
if (_box canAdd "FirstAidKit") then
<dt class="note">[[User:Demellion|Demellion]]</dt>
{
<dd class="note">
_box addWeaponCargo ["FirstAidKit", 1];
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:<br>
}
<code>_i = [(uniformContainer player),(vestContainer player),(backpackContainer player)] call BIS_fnc_selectRandom;
else
if (_i canAdd "Rangefinder") then {
{
    _i addItemCargoGlobal ["Rangefinder",1];
hint "Not enough space";
};
};
</code>
</sqf>


</dd>
|x3= <sqf>car canAdd [currentWeapon player, 50];</sqf>
</dl>


|x4= <sqf>
// check if attachment can be loaded
"arifle_Katiba_GL_F" canAdd "acc_pointer_IR";
"arifle_Katiba_GL_F" canAdd ["acc_pointer_IR", "PointerSlot"];
</sqf>


<!-- DISCONTINUE Notes -->
|x5= <sqf>
// 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"];
</sqf>
 
|seealso= [[canAddItemToBackpack]] [[canAddItemToUniform]] [[canAddItemToVest]] [[compatibleMagazines]] [[compatibleItems]]
}}
 
 
{{Note
|user= Jonpas
|timestamp= 20151129000200
|text= Can also be used on any object that has inventory, not only player inventory containers.<br>
<br>
Where '''_box''' is '''B_supplyCrate_F''':
<sqf>// empty
_box canAdd "FirstAidKit"; // returns true
 
// full
_box canAdd "FirstAidKit"; // returns false</sqf>
}}
 
{{Note
|user= Demellion
|timestamp= 20170211184000
|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:<br>
<sqf>private _container = selectRandom [uniformContainer player, vestContainer player, backpackContainer player];
if (_container canAdd "Rangefinder") then
{
_container addItemCargoGlobal ["Rangefinder", 1];
};
</sqf>
}}

Latest revision as of 17:26, 9 February 2024

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.
Before Arma 3 v2.10 this comment verified only the biggest container when multiple items were queried; now it checks all containers.
Groups:
Unit Inventory

Syntax 1

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

Syntax 2

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

Syntax 3

Syntax:
weapon canAdd item
Parameters:
weapon: String - weapon class name
item: String - config class of magazine or attachment
Return Value:
Boolean

Syntax 4

Syntax:
weapon canAdd [attachment, slot]
Parameters:
weapon: String - weapon class name
attachment: String - attachment class name
slot: String - slot class name (defined under WeaponSlotsInfo class in weapon config)
Return Value:
Boolean

Syntax 5

Syntax:
weapon canAdd [magazine, muzzle]
Parameters:
weapon: String - weapon class name
magazine: String - magazine class name
muzzle: String - muzzle class name
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];
Example 4:
// check if attachment can be loaded "arifle_Katiba_GL_F" canAdd "acc_pointer_IR"; "arifle_Katiba_GL_F" canAdd ["acc_pointer_IR", "PointerSlot"];
Example 5:
// 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"];

Additional Information

See also:
canAddItemToBackpack canAddItemToUniform canAddItemToVest compatibleMagazines compatibleItems

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


Jonpas - c
Posted on Nov 29, 2015 - 00:02 (UTC)
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
Demellion - c
Posted on Feb 11, 2017 - 18:40 (UTC)
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]; };