Jump to content
Sign in to follow this  
robot

Checking if Magazine / Weapon is present.

Recommended Posts

Hello,

I have a weapon type (ItemMap), which is one of a few that can be passed to _this.

I can see _this is populated properly by using a hint _this;

I now want to run an if statement to see if this is present.

if ("ItemMap" in _item) then {
hint "yep!";
};

No matter what I try, I get:

  Error position: <in _item) then {
 Error in: Type String, expected Array,Object,Location

The same for:

_str = "ItemMap" 
if (_string in _item) then {
hint "yep!";
};

Or

if ("ItemMap" == _item) then {
hint "yep!";
};

Is this because I am using a string and it expects a different type?

Share this post


Link to post
Share on other sites

You say _this in your text and then in your code you have _item.

How are you populating _item.

_this is a protected var and you should never override it. It is used to refer to items passed to the script.

Share this post


Link to post
Share on other sites

Try this.

_weapons = weapons player;
{
 if (_x == 'ItemMap') then {hint 'player has a map'};
} forEach _weapons;

Share this post


Link to post
Share on other sites
You say _this in your text and then in your code you have _item.

How are you populating _item.

_this is a protected var and you should never override it. It is used to refer to items passed to the script.

Sorry, completely forget this:

_item = _this;

Share this post


Link to post
Share on other sites
Try this.

_weapons = weapons player;
{
 if (_x == 'ItemMap') then {hint 'player has a map'};
} forEach _weapons;

I just solved it by reversing them, but yours looks better so I will try that too:

if (_item == "ItemMap" ) then {

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  

×