canAdd: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\| *((\[\[.*\]\],? ?)+) * \}\}" to "|seealso= $1 }}")
m (Text replacement - "<dl class="command_description"> <dd class="notedate">" to "<dl class="command_description"> <dt></dt> <dd class="notedate">")
Line 54: Line 54:
<!-- CONTINUE Notes -->
<!-- CONTINUE Notes -->
<dl class="command_description">
<dl class="command_description">
<dt></dt>
<dd class="notedate">Posted on November 29, 2015 - 00:02 (UTC)</dd>
<dd class="notedate">Posted on November 29, 2015 - 00:02 (UTC)</dd>
<dt class="note">[[User:Jonpas|Jonpas]]</dt>
<dt class="note">[[User:Jonpas|Jonpas]]</dt>
Line 72: Line 73:


<dl class="command_description">
<dl class="command_description">
<dt></dt>
<dd class="notedate">Posted on February 11, 2017 - 18:40 (UTC)</dd>
<dd class="notedate">Posted on February 11, 2017 - 18:40 (UTC)</dd>
<dt class="note">[[User:Demellion|Demellion]]</dt>
<dt class="note">[[User:Demellion|Demellion]]</dt>

Revision as of 14:29, 5 April 2021

Hover & click on the images for description

Description

Description:
Description needed
Groups:
Unit Inventory

Syntax

Syntax:
Syntax needed
Parameters:
object: Object - unit or container
item: String - Config class
Return Value:
Return value needed

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
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]; };