Jump to content
HeisenS

Help, checking for item in inventory?

Recommended Posts

Hello guys,

 

Well i'm the progress of making a repair system menu for arma 3 and i have came across something which i am unsure about. Well i want to check if the player has a ToolKit in their inventory however i do not know the line of code of which is used to check for inventory items. I'm fairly new to dialog and scripting so i am unsure about this. Any help of what i could try out would be amazing. Thanks! 

 

It's a work in progress...

 

Hesien

Share this post


Link to post
Share on other sites
_items = items player;

if ("ToolKit" in _items) then {

// script

};

I'll try that out, thanks.

Share this post


Link to post
Share on other sites

If you are finding mags, then the syntax would be:

"ItemClassName" in magazines player;

Share this post


Link to post
Share on other sites

If you are finding mags, then the syntax would be:

 

"ItemClassName" in magazines player;

Yer, thanks.

Share this post


Link to post
Share on other sites
_items = items player;

if ("ToolKit" in _items) then {

// script

};

Worked!

Share this post


Link to post
Share on other sites
_items = items player;
_wanted = [ "item1", "item2", "item3", "item4", "item5", "item6", "item7" ];

if ( _wanted findIf { _x in _items } > -1 ) then {

// script

};

script is executed if one of the items in _wanted is carried by player

Share this post


Link to post
Share on other sites
1 hour ago, sarogahtyp said:

_items = items player;
_wanted = [ "item1", "item2", "item3", "item4", "item5", "item6", "item7" ];

if ( _wanted findIf { _x in _items } > -1 ) then {

// script

};

script is executed if one of the items in _wanted is carried by player

Hi, thanks for the quick response, though this is not what I am looking for. I am trying to make a crafting system and I want to make it so it uses multiple items. Lets say it uses "Scrap" twice, and uses a "Rifle_Body" once. So that would be 3 items that are all needed to execute the script.

Share this post


Link to post
Share on other sites
_items = items player;
_recipe = [ ["item1", 5], ["item2", 3], ["item3", 98]];
_crafting_allowed = true;

{
 _item = _x#0;
 _wanted_num = _x#1;

 _num = {_x isEqualTo _item} count _items;

 if (_num < _wanted_num) then { _crafting_allowed = false };

} count recipe;

if ( _crafting_allowed ) then {

// script

};

not tested, but shows the way at least...

Edited by sarogahtyp
simplified
  • Like 1

Share this post


Link to post
Share on other sites
22 minutes ago, sarogahtyp said:

_items = items player;
_recipe = [ ["item1", 5], ["item2", 3], ["item3", 98]];
_crafting_allowed = true;

{
 _item = _x#0;
 _wanted_num = _x#1;

 _num = {_x isEqualTo _item} count _items;

 if (_num < _wanted_num) then { _crafting_allowed = false };

} count recipe;

if ( _crafting_allowed ) then {

// script

};

not tested, but shows the way at least...

It works, thankyou. Also, is there a way to make it so it not only checks items of the player, but also magazines? Example would be: _items = items player, magazines player; But this doesnt work ofcourse.

 

Edit: nevermind, found the solution. Thanks alot!

Share this post


Link to post
Share on other sites
1 minute ago, steam-76561198069261992 said:

It works, thankyou. Also, is there a way to make it so it not only checks items of the player, but also magazines? Example would be: _items = items player, magazines player; But this doesnt work ofcourse.

 

just append it to the item array:

_stuff = items player;
_stuff append magazines player;

 

Share this post


Link to post
Share on other sites
On 6/9/2021 at 7:52 AM, sarogahtyp said:

_items = items player;
_wanted = [ "item1", "item2", "item3", "item4", "item5", "item6", "item7" ];

if ( _wanted findIf { _x in _items } > -1 ) then {

// script

};

script is executed if one of the items in _wanted is carried by player

Hello @sarogahtyp how do I achieve this in MP dedicated?

Share this post


Link to post
Share on other sites
On 8/31/2021 at 4:42 AM, sarogahtyp said:

@Soapbox0331 depends on your purpose and how you are trying to achieve it ...

@sarogahtyp ok, sure:

MP Dedi using SOG Prairie Fire. Goal is to conduct wire tap mission. 

 

Task 1 is to ensure at least one of the players has wire tap kit ("vn_b_item_wiretap") in inventory. I was thinking a trigger condition that detects this completes the task.

FYSA: There is a function, VN_ms_fnc_hasItems (https://wiki.sogpf.com/index.php/VN_ms_fnc_hasItems). Again, I do not know how to do a MP dedi of: [[player], ["vn_b_item_wiretap"]] call VN_ms_fnc_hasItems;   

 

Task 2 is to conduct the wire tap. Currently I have an object near a cable with this holdaction, which displays a wire tap kit for 10 seconds, deletes it, and task is completed via WireTapCollected in trigger condition:
[
    this,                                            
    "CONDUCT WIRE TAP",                                        
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    
    "_this distance _target < 3",                        
    "_caller distance _target < 3",                        
    { Recorder1 setpos [(getpos Cable select 0), (getpos Cable select 1), 0]; },                                                    
    {},                                                    
    { deleteMarker "WireTap"; deleteVehicle Recorder1; WireTapCollected = true; publicVariable "WireTapCollected"; },                
    {},                                                    
    [],                                                    
    10,                                                    
    0,                                                    
    true,                                                
    false                                                
] remoteExec ["BIS_fnc_holdActionAdd", 0, this];

 

Ideally, this holdaction would only be available or functional for a player with "vn_b_item_wiretap" in inventory.
 
Thanks for sharing your expertise!

Share this post


Link to post
Share on other sites

You don't need to remote exec a code already known by all players, as any each player runs all the init fields of all the objects/units in editor (this variable works only here)

Add a simple condition for your item:
 

[
    this,                                            
    "CONDUCT WIRE TAP",                                        
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    
    "_this distance _target < 3 && 'vn_b_item_wiretap' in items _this",                        
    "_caller distance _target < 3 && 'vn_b_item_wiretap' in items _caller",                        
    { Recorder1 setpos [(getpos Cable select 0), (getpos Cable select 1), 0]; },                                                    
    {},                                                    
    {
      deleteMarker "WireTap"; deleteVehicle Recorder1; WireTapCollected = true; publicVariable "WireTapCollected";
    },                
    {},                                                    
    [],                                                    
    10,                                                    
    0,                                                    
    true,                                                
    false                                                
] call BIS_fnc_holdActionAdd;

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×