Javascript code for checking if an armor/weapon is not currently equipped

Hello all!

I am using various Yanfly plugins with lunatic modes, and so far without Javascript knowledge, I can usually google my way around to figure out what I need, and use common sense for the rest. Unfortunately I am stuck on this and would love some help from the community who know more than me.

Basically, I want to write a conditional that checks if the party currently has a particular armor/weapon, AND if the armor/weapon is NOT equipped - by anyone in the party, just not one specific actor.

Here is my current code in the middle of the lunatic brackets:
Code:
if ($gameParty.hasItem($dataArmors[X], true))
{ visible = true; }
else { visible = false; } 


if ($gameParty.hasItem($dataWeapons[X], true))
{ visible = true; }
else { visible = false; } 

x = armor or weapon database ID

Now I'd like to add "AND ITEM NOT EQUIPPED" somehow next to the conditional, so that it is checking if they have the item AND it is not equipped. But I can't figure out the right syntax for it.

Thanks for your help!
When you use $gameParty, it will check all your actors in your party. I think you can use this:
Code:
if (user.equips().contains($dataWeapons[x])){
visible = true;}
else{
visible = false;}
Same with $dataArmors[x] maybe.
@JamesRyan Thanks for the quick response!
This is what I tried with the info you gave me:

Code:
if ($gameParty.hasItem($dataWeapons[2], true) && (user.equips().contains($dataWeapons[2], false)

Because I'd like to check if it is not equipped, I put 'false' in there. I'm guessing that's not correct lol. I'm getting an unexpected token { error, but I suspect the entire thing might not be correct.
You can use ! to invert a check so

if (!user.equips().contains($dataWeapons[x]))

would check if something is not equipped. However this code won't work as you are currently using it. I think @JamesRyan is saying you can replace user with $gameParty to have it check all actors in your party. I haven't tried it.
Fair enough! I tried
Code:
if ($gameParty.hasItem($dataWeapons[2], true) && (user.equips().contains($dataWeapons[2])
just to see if I wouldn't get an error, because my main actor does have weapon 2 equipped. Still got the unexpected token { error.

So then I tried
Code:
if ($gameParty.hasItem($dataWeapons[2], true) && (!$gameParty.equips().contains($dataWeapons[2])
Same error 🙁

I did more googlin' and found this thread with a solution that I thought would do exactly what I needed, so I tried:
Code:
if ($gameParty.hasItem($dataWeapons[2], true) && ($gameParty.isAnyMemberEquipped($dataWeapons[2]))
But no dice 🙁 Same error.

Edit:
Good news
Code:
if (!$gameParty.isAnyMemberEquipped($dataWeapons[2]))
{ visible = true; }
else { visible = false; }
works. The weapon is hidden because I have it equipped. Tried with other weapons, and it does what it needs to.

But when I try adding ($gameParty.hasItem($dataWeapons[2], true) to the conditional, it gets all messed up with errors.

Code:
if (($gameParty.hasItem($dataWeapons[2]) && (!$gameParty.isAnyMemberEquipped($dataWeapons[2])))

{ visible = true; }

else { visible = false; }

Any ideas?
The errors are due to your brackets. 😛 JS if statements must have their condition enclosed with (brackets). Also for some of your examples you have more opening brackets than closing ones. Try one of the following, I think they should be equivalent:
Code:
if ($gameParty.hasItem($dataWeapons[2], false) && !$gameParty.isAnyMemberEquipped($dataWeapons[2])) {
  visible = true;
} else {
  visible = false;
}
Code:
visible = $gameParty.hasItem($dataWeapons[2], false) && !$gameParty.isAnyMemberEquipped($dataWeapons[2]);
Also, just for info: the second argument of hasItem determines whether or not equipped items are included in the count; I've set it to false in the above examples because counting the equipped items is redundant in this case. 😅
If you want it to affect a specific user, or the user of your skill, just use "user".
Or if you wanna check through the whole party, maybe caethyril's solution can help.
@caethyril Thank you! I assumed it had something to do with a parenthesis or two.

This is what I tried:
Code:
if ($gameParty.hasItem($dataWeapons[2], false) && !$gameParty.isAnyMemberEquipped($dataWeapons[2]))

{ visible = true;

} else {

visible = false;

}

Still got an error though, oof.

Also confused about the redundancy with "$dataWeapons[2], false" - I'd like the code to check if the user has the item, but then make sure it's not equipped. It's basically going to show up in the menu if the item is in their inventory, but I don't want it to show up if they have the item equipped, or else the user might lose their equipment when they activate the event.
That code alone seems to run as expected for me, no errors; maybe there's an error elsewhere in your notetag? 😅

What I meant by "redundant" is that there's simply no point checking the equipped stuff when the purpose of the second check is to ensure there are none of them equipped. Put another way: hasItem checks the inventory, then if includeEquip is true, it calls isAnyMemberEquipped...but we're checking the inverse of isAnyMemberEquipped in the second condition, and A && !A will always be false for any true/false value A. (Hope that makes sense! Feel free to keep the true in there if you like, shouldn't do any harm. 😴)
Thanks for the explanation, @caethyril !

No luck getting the code to work for me, but I've found a workaround:
Conditionals01.JPG
Just have two evals in there! It seems to work so I guess I shouldn't touch it, haha.
Is it possible to have two of the particular item? One equipped and one not? If so your check is not correct. It sounds like what you want is hasItem with the second argument false and don't bother with the isAnyMemberEquipped.
Is it possible to have two of the particular item? One equipped and one not? If so your check is not correct. It sounds like what you want is hasItem with the second argument false and don't bother with the isAnyMemberEquipped.
Oh no! You're right. This is a huge underlying problem. It's a selling system, so if they have the item equipped, they won't be able to sell any duplicates they might have. Super lame. In that case, I'll just have to include a note about the possibility for selling equipped items.

Oof. All that work trying to figure this out, lol!

Edit: So just saying "false" and removing the equip check, like you said, is working. I'm not understanding how or why! But you can't argue with results. I checked by unequipping weapon 2, then adding more weapon 2s to equipping one to make sure, and all seems fine. Thanks so much, dulsi!
If you look here, you will what that second parameter means. The parameter is called includeEquip. If it is true, it will search equipped items in addition to unequipped items. If it is false it only searches items that are not equipped.

(I don't know if that link is to an official documentation of not. It just happened to be what I found quickly.)

Original thread: https://forums.rpgmakerweb.com/threads/javascript-code-for-checking-if-an-armor-weapon-is-not-currently-equipped.105368/