MV Need help with a script

Hello fellow rpg makers.
I've recently started a project and I'm mostly using Yanfly plugins. Everything is going quite smootly until now.
I need a particular script call for the plugin "auto passive states". I need to trigger a passive effect on an actor when he equips a piece of equipment, but only if he belongs to a particular class.
So I inserted the "<Passive State: x>" note tag inside the weapon notes and then I'm trying to make a script call inside the passive state.
This is the example inside the plugin documentation:

JavaScript:
  <Custom Passive Condition>
  if (user.hp / user.mhp <= 0.25) {
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

instead of that particular hp/mp call, I need the script to generate a "true" when the character equipping the item belongs to class number 0 of the class database. I tried something like this:

JavaScript:
  <Custom Passive Condition>
  if ($gameParty.leader().isClass($dataClasses[0]) ) {
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

unfortunately, launching the game generates many errors and fails to launch.
I need your help to understand script calls better. Thank you!
launching the game generates many errors and fails to launch.
I need your help to understand script calls better. Thank you!
We can't help you based on this - the code you wrote will generate an error, which I'll explain, but it shouldn't until you equip the item that has the state and it checks the passive condition. If you're getting errors just from starting the game, you need to press F8, go to the Console tab, and post a screenshot of those errors.
instead of that particular hp/mp call, I need the script to generate a "true" when the character equipping the item belongs to class number 0 of the class database. I tried something like this:

JavaScript:
  <Custom Passive Condition>
  if ($gameParty.leader().isClass($dataClasses[0]) ) {
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>
So there's one wrong thing and a few bits of advice for you. The wrong thing is this whole class zero thing. Your classes begin at 1 in the Database - index 0 is intentionally left undefined. So how do you have a class 0, where do you see this, etc?

The first class you should have is 1.

The two bits of advice I have for you are:
1 - If conditions automatically apply to the next single code statement, so since you're just setting a variable true or false there's no need for braces.

2 - If you ever find that you're using an if statement just to set a boolean value, you can always skip it and set the variable directly to that conditional statement.

So your notetag could more efficiently be (presuming you actually mean class 1):
Code:
<Custom Passive Condition>
condition=$gameParty.leader().isClass($dataClasses[1]);
</Custom Passive Condition>
So your notetag could more efficiently be (presuming you actually mean class 1):
Code:
<Custom Passive Condition>
condition=$gameParty.leader().isClass($dataClasses[1]);
</Custom Passive Condition>

Thank you. Yesterday I just copy/pasted the script call from the sample document, so yes... the correct class would be [1].

So I put the notetag <Passive State: 25> in the class page, this way the state will be applied to any actor that belongs to the Peasant class.
Post 01.png
Now I want to spice things up a bit, and make the state trigger only when the Peasant equips a particular type of weapon: for example, every weapon belonging to the categories shown in the picture, and give an ATK malus using this code Post 04.png

Post 02.png
So now I need to instert a passive condition that triggers the state when the Peasant equips a
weapon that belongs to one of the categories shown, but since my Javascript knowledge is almost 0 I need your help.
Post 03.png
Thank you in advance :LZSproud:

EDIT: I tried with this

JavaScript:
<Custom Passive Condition>
condition=$gameActors.actor(1).isWtypeEquipped(3); 
</Custom Passive Condition>

and it's actually working! strangely though, now the game takes a very long time to launch :LZSskeptic:
Now I want to spice things up a bit, and make the state trigger only when the Peasant equips a particular type of weapon

EDIT: I tried with this

JavaScript:
<Custom Passive Condition>
condition=$gameActors.actor(1).isWtypeEquipped(3);
</Custom Passive Condition>
If you read that carefully, you're asking is Actor 1 wielding a short sword.

That's probably not what you want, unless only actor 1 can be a peasant (and even if that's true, it's less efficient).

You probably want to ask if the actor with this state is wielding a short sword. Thus:
Code:
condition=user.isWtypeEquipped(3);

And if you want to trigger it for any of multiple options, you use the OR operator ||
Code:
condition=user.isWtypeEquipped(3) || user.isWtypeEquipped(2);
etc.
If you read that carefully, you're asking is Actor 1 wielding a short sword.

That's probably not what you want, unless only actor 1 can be a peasant (and even if that's true, it's less efficient).

You probably want to ask if the actor with this state is wielding a short sword. Thus:
Code:
condition=user.isWtypeEquipped(3);

And if you want to trigger it for any of multiple options, you use the OR operator ||
Code:
condition=user.isWtypeEquipped(3) || user.isWtypeEquipped(2);
etc.
Thank you so much for your reply, I will experiment further :LZSgrin:
I ran into a similar issue just last night, including the game taking a long time to load. Bringing up console with (f8) or (f12) showed that the condition=$gameActors.actor(1).isWtypeEquipped(3); code was returning a lot of errors for some reason, leading to maximum call size error.

Switching it to the following solved my issue:

Code:
<Custom Passive Condition>
  if (
user.equips()[0] && user.equips()[0].wtypeId === 3)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-script.147048/