Jump to content
Sign in to follow this  
CreativeProduct

Check if Array is in items player and remove it afterwards

Recommended Posts

Hello there.

 

Im facing a difficult thing for my circumstances. Maybe im just to sleepy to get my mind right.

 

However, im creating a script, which checks if any of the items in the array are in the players inventory. If that's the case, one of the items should be removed, but I just dont know how.

 

This is what I've got sot so far:

_unit = _this select 0;

_foods = ["ARP_sandwich","ARP_twinkies","ARP_pineapples","ARP_soup","ARP_spaghettios","ARP_tuna","ARP_skittles","ARP_snickers","ARP_pitabread","ARP_potatobag","ARP_chili","ARP_beefjerky","ARP_dip"];

If ( {_x in _foods} foreach (items _unit) ) then { hint "Item exists, should be removed." } else {Hint "false"};

It's basically getting the _x for each item again.

However, as you can propably tell, iI didnt get it to work.

 

 

Thanks in advance.

 

Best regards.

Share this post


Link to post
Share on other sites
  {
      if (_x in (items player)) then
      {
          systemChat format ["Food - %1 found",_x];
      };
  }forEach _foods;

change player to _unit

Share this post


Link to post
Share on other sites
15 minutes ago, soolie said:

  {
      if (_x in (items player)) then
      {
          systemChat format ["Food - %1 found",_x];
      };
  }forEach _foods;

 

Well, it seems like this way it checks if those items are (Maybe all of them?) are in the inventory.

 

After trying out a bit

  {
      if (_x in (items player)) then
      {
		  hint "Worked";
      } else { systemChat format ["Food - %1 found",_x];;};
  } forEach _foods;

i made this, to see if the condition was false - returning every item as found, obviously caused by the false condition - was made for debug reasons.

 

Well, the purpose of the scirpt is to check if ANY item is in the inventory and then remove that item.

 

 

Best regards

Share this post


Link to post
Share on other sites
{ 
 if (_x in (items _unit)) exitWith 
 { 
  systemChat format ["Food - %1 found",_x]; 
 }; 
}forEach _foods;

The exitWith will stop it from running again once it finds something

Share this post


Link to post
Share on other sites
3 minutes ago, soolie said:

{ 
 if (_x in (items _unit)) exitWith 
 { 
  systemChat format ["Food - %1 found",_x]; 
 }; 
}forEach _foods;

The exitWith will stop it from running again once it finds something

Works like a charm.

 

Thank you very much.

 

Best regards

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
Sign in to follow this  

×