canAdd: Difference between revisions
Lou Montana (talk | contribs) m (Text replacement - "</dd> <dt></dt>" to "</dd> <dt></dt>") |
Lou Montana (talk | contribs) m (Text replacement - "\{\{Note([^}]*)<code>([^<]*)<\/code>" to "{{Note$1<sqf>$2</sqf>") |
||
(39 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|gr1= Unit Inventory | |gr1= Unit Inventory | ||
|descr= Checks if given object can be stored in inventory of given object or any inventory container ([[uniform]], [[vest]], [[backpack]]) of given unit. | |descr= Checks if given object can be stored in inventory of given object or any inventory container ([[uniform]], [[vest]], [[backpack]]) of given unit. Since Arma 3 v2.09 this command will count unit storage space as whole, instead of as biggest container, when multiple items are queried. | ||
|s1= | |s1= object [[canAdd]] item | ||
|p1= object: [[Object]] - unit or container | |p1= object: [[Object]] - unit or container | ||
Line 16: | Line 16: | ||
|r1= [[Boolean]] | |r1= [[Boolean]] | ||
|s2= object [[canAdd]] [item, count] | |s2= object [[canAdd]] [item, count] | ||
|s2since= arma3 1.56 | |||
|p21= object: [[Object]] - unit or container | |p21= object: [[Object]] - unit or container | ||
|p22= [item, | |p22= item: [[String]] - Config class | ||
|p23= count: [[Number]] - desired quantity | |||
|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 | |||
|p62= attachment: [[String]] - Attachment class name | |||
|p63= slot: [[String]] - Slot class name (defined under '''WeaponSlotsInfo''' class in weapon config) | |||
|r4= [[Boolean]] | |||
|s5= weapon [[canAdd]] [magazine, muzzle] | |||
|s5since= arma3 2.10 | |||
| | |p81= weapon: [[String]] - Weapon class name | ||
| | |p82= magazine: [[String]] - Magazine class name | ||
| | |p83= muzzle: [[String]] - Muzzle class name | ||
|r5= [[Boolean]] | |||
|x1= <sqf>if (player canAdd "FirstAidKit") then | |||
{ | |||
player addItem "FirstAidKit"; | |||
} | |||
else | |||
{ | |||
hint "Not enough space"; | |||
};</sqf> | |||
|x2= <sqf>if (_box canAdd "FirstAidKit") then | |||
{ | |||
_box addWeaponCargo ["FirstAidKit", 1]; | |||
} | |||
else | |||
{ | |||
hint "Not enough space"; | |||
};</sqf> | |||
| | |x3= <sqf>car canAdd [currentWeapon player, 50];</sqf> | ||
</ | |||
| | |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> | |||
</ | |||
| | |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]] | |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> | |||
Can also be used on any object that has inventory, not only player inventory containers.<br> | |||
<br> | <br> | ||
Where | Where '''_box''' is '''B_supplyCrate_F''': | ||
< | <sqf>// empty | ||
_box canAdd "FirstAidKit"; | _box canAdd "FirstAidKit"; // returns true | ||
// | // full | ||
_box canAdd "FirstAidKit"; | _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> | |||
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 | ||
if ( | { | ||
_container addItemCargoGlobal ["Rangefinder", 1]; | |||
}; | }; | ||
</ | </sqf> | ||
}} | |||
Revision as of 11:42, 13 May 2022
Description
- Description:
- Checks if given object can be stored in inventory of given object or any inventory container (uniform, vest, backpack) of given unit. Since Arma 3 v2.09 this command will count unit storage space as whole, instead of as biggest container, when multiple items are queried.
- 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]
- Parameters:
- object: Object - unit or container
- item: String - Config class
- count: Number - desired quantity
- 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:
- Example 2:
- if (_box canAdd "FirstAidKit") then { _box addWeaponCargo ["FirstAidKit", 1]; } else { hint "Not enough space"; };
- Example 3:
- 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
- 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
- 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]; };