Jump to content
kibaBG

[SOLVED] check if player has specific item

Recommended Posts

Hi, I simply don't know how to check if player has specific item in inventory. 🤔
I searched biki and found only this -> https://community.bistudio.com/wiki/BIS_fnc_hasItem

I try to use it in a loop to  check regularly for an item but it gives an error 
 

if ([player, "acex_intelitems_notepad"] call BIS_fnc_hasItem) do {
hint "You have found important intel!";
};

Any leads? 

Share this post


Link to post
Share on other sites

replace the do with then

 

that should do it 🙂

  • Like 1

Share this post


Link to post
Share on other sites

OMG, thank you, no errors but still not working 😪 ... 

Share this post


Link to post
Share on other sites
21 minutes ago, kibaBG said:

OMG, thank you, no errors but still not working 😪 ... 

 

are you sure "acex_intelitems_notepad" is correct item name? Ace loaded up?

 

  • Like 1

Share this post


Link to post
Share on other sites

Yes, it's the correct classsname. At least what it gives in eden, ACE is loaded. 


The code taken from this theme https://forums.bohemia.net/forums/topic/152168-trigger-activated-when-item-added-to-players-inventory-from-dead-body/ is working in debug console. Gives "true" if intel item is in player Uniform. 

"acex_intelitems_notepad" in UniformItems player;

uniformItems, vestItems and backpackItems commands should be used, because intel item can go to vest if uniform is full ...


This is simply not working, don't know why? execVM from initPlayerLocal.sqf 

 

if ("acex_intelitems_notepad" in uniformItems player) then {
hint "You have found important intel!";
};


Edit
I tested with other items like "Intel_File1_F" but still no avail 😥

 

Share this post


Link to post
Share on other sites

Because it executes once at mission start/player join. 

 

Also, the object in question is actually a magazine.

if ("acex_intelitems_notepad" in magazines player) then {
	hint "You have found important intel!";
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Still shows nothing ... 😕😔

Share this post


Link to post
Share on other sites

Make sure the code is running, put hint there somewhere before rest of the code

  • Like 1

Share this post


Link to post
Share on other sites

Works fine for me. How are you executing it? As I mentioned in my first reply, running it from an init script will only have it execute once at mission start. The code as presented above is meant more for testing in debug or for periodic execution by other means.

  • Like 1

Share this post


Link to post
Share on other sites
player addEventHandler[ "Take", {
	params[ "_unit", "_container", "_item" ];
	
	if ( _item == "acex_intelitems_notepad" ) then {
		hint "You have found important intel!";
	};
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Unfortunately, it doesn't fire when picking up an object via ACE interaction. 

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, Harzach said:

Unfortunately, it doesn't fire when picking up an object via ACE interaction. 

Ah ok, was just going off that you said it was a magazine. Didn't realise it was action based.

  • Like 1

Share this post


Link to post
Share on other sites

It's kind of the ideal solution (the Take EH) I think, but I'm not sure if there's a way to pickup ACE interactions that way. I'll have to dive into the ACE wiki/git...

  • Like 1

Share this post


Link to post
Share on other sites

Need to see if there is some kind of SEH for ACE intel when picked up.

Or be able to change the actions code.

?

  • Like 1

Share this post


Link to post
Share on other sites
On 11/5/2022 at 4:39 PM, Larrow said:

player addEventHandler[ "Take", {
	params[ "_unit", "_container", "_item" ];
	
	if ( _item == "acex_intelitems_notepad" ) then {
		hint "You have found important intel!";
	};
}];

 

 

Error missing ] ...
No error if written and not pasted. 🙂 
But still no hint, just nothing upon taking the intel item. 
I am trying with other intel, not ACE item ...
Edit: Not working with CBA intel items too. 😪

Share this post


Link to post
Share on other sites

Works fine here. Again, how/where are you executing it?

 

Also again, it does not work with ACE interaction.

 

As for CBA intel items, they are "consumed" when picked up, and so do not go into inventory.

  • Like 1

Share this post


Link to post
Share on other sites
if ('acex_intelitems_notepad' in (items player)) then	{ 
	hint "You have found important intel!"; 
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Magazines do not appear in the array created by assignedItems.

  • Like 1

Share this post


Link to post
Share on other sites
On 11/8/2022 at 12:03 PM, Vadym Mazur said:

if ('acex_intelitems_notepad' in (items player)) then	{ 
	hint "You have found important intel!"; 
};

 

 

Not working! 
@Harzach I make intel.sqf, put the code inside and then I write execVM "intel.sqf"; in initPLayerLocal.sqf (my scenario is SP).   

Share this post


Link to post
Share on other sites

See the first sentence of my first reply.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, kibaBG said:

 

Not working! 
@Harzach I make intel.sqf, put the code inside and then I write execVM "intel.sqf"; in initPLayerLocal.sqf (my scenario is SP).   

The init part in initPlayerLocal.sqf means the initialization phase of your scenario (or when player connects to the mission in MP environment), so your script is executed right at the start of your mission and it won't wait nor execute again. If you want to have it happen during your mission, place a trigger with 

"acex_intelitems_notepad" in magazines player

in its Condition field and

hint "You have found important intel!";

in its On Activation field.  This is as simple as it gets, can't be any simpler probably.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

That will work once, which is fine if there is only one piece of intel to be picked up. Setting the trigger to repeatable might seem to be the obvious solution, but then you'll receive that message every 0.5 seconds (default) while the item is in your inventory.

 

As above, if ACE interaction is not necessary, then you can just use the Take EH. It is the best option.

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

×