[SOLVED] Big Confusion with simple code snippet for MV

I'm pretty new to JS, but I usually manage to pull off small variations to the default gameplay, by using some basic, non-complex scripting. Normally I have no trouble at all, but this time it seems that I hit a dead end.

What I want to achieve : Actor X gets afflicted by a State. At the moment of his next action ( I use Yanfly's BuffsStatesCore notetags for this), if another particular actor in the party doesn't wear a specific armor, Actor X gets afflicted by an additional State.

What I tried :
Code:
<Custom Action Start Effect>
var actor = $gameActors.actor(id);
var armor = $dataArmors[id];
if (!actor.equips(4, armor)) {
  target.addState(id);
}
</Custom Action Start Effect>

Unfortunately, nothing happens!

Then I experimented a bit by removing the exclamation mark

Code:
<Custom Action Start Effect>
var actor = $gameActors.actor(id);
var armor = $dataArmors[id];
if (actor.equips(4, armor)) {
  target.addState(id);
}
</Custom Action Start Effect>

Funny conclusion with this one: the second state affects the target, no matter if the other actor equips the item or not!

I must be missing something very basic here...
Use the condition !actor.hasArmor(armor) instead. Should work.
Also maybe change target.addState to user.addState (because the target I believe would refer to the target of whatever skill the actor uses, not the actor himself).
Thanks a lot, it worked indeed! Do you have any idea what's different on your "command" that makes it successful? I mean, it's almost identical to the "equips" one, which has worked fine for me in the past, except this single occasion. I didn't even know that hasArmor existed in the first place, until you mentioned it and I took a look in the rpg_objects.js file.

Thanks again friend!
No problem, glad it worked out!

Your command isn't entirely wrong, but it's not called correctly. If you look at the rpg_objects.js file, the actor.equips() function doesn't accept any arguments. It simply returns an array containing the actor's equipped items. Therefore, you would want to check if that array includes the item you're looking for.

So, the correct way to call it would be actor.equips().contains(armor); which would return true if the actor did have the armor equipped.

And guess what, the actor.hasArmor(armor); does exactly that. Neat.
Thanks a lot for the thorough explanation! Gave me a better insight of how things work!

Original thread: https://forums.rpgmakerweb.com/threads/solved-big-confusion-with-simple-code-snippet-for-mv.90472/