[Solved]Yanfly passive state plugin - if inside an if statement?

Hi everyone,
I just started out with java(script) and I have some difficulty to get the result I want to archive.

I'm using yanfly passive states to create custom equipement sets that gives a passive state for example atk +10 for the user that has equiped the whole set. (thats working though).

But now I want to check if one of the two certain weapons are
equiped and then two types of certain armor and after that the rest of the set must be equiped to the user.

So straight forward the (check if the rest is equipped is working. But it seems like I don't get the part where
if (weapon1 OR weapon2) is equiped
and if (armor 1 OR armor 2) is equiped
and (armor 3 AND armor 4 AND armor5 AND armor6) is equiped
to turn the condition on.
else condition off

I think I'm doing the if inside an if inside an if part wrong haha ^^

Thanks in advanced for pointing me into the right direction.



JavaScript:
<Custom Passive Condition>

\\first check if there is one of the two weapons equiped
 
if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {

\\second check if there are one of these armors are equiped
                                          if (user.hasArmor($dataArmors[1]) || user.hasArmor($dataArmors[2])) {

                       
\\ check if the rest is equipped.
                                    if (user.hasArmor($dataArmors[4]) && user.hasArmor($dataArmors[5]) && user.hasArmor($dataArmors[6]) && user.hasArmor($dataArmors[7]) && user.hasArmor($dataArmors[8]) && user.hasArmor($dataArmors[9])){

                                    condition = true;

                                    } else {

                                    condition = false;

                       

                       

                        } else {

                        condition = false;

                        }

       

    } else {

    Condition = false;

    }


</Custom Passive Condition>
Hello, I don't see anything wrong at first glance.
What happen when you run the code?
How the passive state is applied?
Hi @TSR
Thank you for your reply, I don't get any errors from the code, but it seems the state isn't applied either after equiping the armors and swords.

The plugin gives automatically a state to the actor.
So If the actor is not having say armor1 equiped the state is removed.

if actor has armor1 equiped the state is not removed and is there for the actor.

if I use this code to if everyting is equiped it works as intented.
JavaScript:
<Custom Passive Condition>
  if (user.hasArmor($dataArmors[99]) && user.hasArmor($dataArmors[98]) && user.hasArmor($dataArmors[97]) && user.hasArmor($dataArmors[96]) && user.hasArmor($dataArmors[95]) && user.hasArmor($dataArmors[94]) && user.hasArmor($dataArmors[93]) && user.hasWeapon($dataWeapons[42]) ) {
  condition = true;
  } else {
  condition = false;
  }

</Custom Passive Condition>

But how do I implement it so that the condition is true when havin different swords to choose from and still requires armor1 to set the condition to true.
This would be a little bit more complicated, but everything is feasible. I give you some cue on how I would probably do this. I haven't tested anything, so i'll let you do the trials and errors 🙂
You can try some locals arrays containing the index of weapon and armor that can induce the state.
Code:
<Custom Passive Condition>
  let WeaponList = [1, 2, 3];
  let ArmorList = [4, 5, 6];
  let cond = 0;
  for (i in WeaponList) {
    if (user.equips()[0] && user.equips()[0].id === WeaponList[i]) {
      cond += 1; break;
    }
  }
  for (i in ArmorList) {
    if (user.equips()[1] && user.equips()[1].id === WeaponList[i]) {
      cond += 1;    }
  }
  for (i in ArmorList) {
    if (user.equips()[2] && user.equips()[2].id === WeaponList[i]) {
      cond += 1;    }
  }
  if (cond === 8) {
    condition = true
  } else {
    condition = false
  }
</Custom Passive Condition>
I used a local cond to check each equip slots (only the first 3 equip slots are assessed in the exemple above).
So if cond is equal the total equip slot the condition will be true.
Feel free if you have some questions.
Ah, I give up for now. Thanks for trying to help me but I'm not skilled enough yet to figure it out I guess,

I can't seem to get the 'let' function to work;
Block-scoped declarations (let, const, function, class) not yet supported outside strict mode-

I also tried to put a variable that counts + 1 if a condition is met and when all the conditions are met the variable = 3 and the condition is set to true.
didn't work for me either (no errors but it didn't change the state of the actor, maybe it's plugin specific?


I just want to combine:
(user.hasWeapon($dataWeapons[1] || user.hasWeapon($dataWeapons[2]))
with
(user.hasArmor($dataArmors[1]) && user.hasArmor($dataArmors[2])

so weapon1 OR weapon2 is equiped with armor1 AND armor2 to set the condition to true.

I let it rest for now, maybe I can think of another way for this to work.

Thanks again for your help.
It's a bit strange that this isn't showing a syntax error in the console as you're using 2 else's with a single if and leaving one if block unclosed. What you've actually written is:

Code:
if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
    if (user.hasArmor($dataArmors[1]) || user.hasArmor($dataArmors[2])) {
        if (user.hasArmor($dataArmors[4]) && user.hasArmor($dataArmors[5]) && user.hasArmor($dataArmors[6]) && user.hasArmor($dataArmors[7]) && user.hasArmor($dataArmors[8]) && user.hasArmor($dataArmors[9])){
            condition = true;
        } else {
            condition = false;
        } else {                             // notice else is used right after else
            condition = false;
        }
    } else {
        Condition = false;
    }
// the first if condition is never closed.

I'm assuming Yanfly is handling the error within his plugin in some way or another which is preventing it from showing in the console. Either way, to make your code work you need to add another curly brace:

Code:
if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
    if (user.hasArmor($dataArmors[1]) || user.hasArmor($dataArmors[2])) {
        if (user.hasArmor($dataArmors[4]) && user.hasArmor($dataArmors[5]) && user.hasArmor($dataArmors[6]) && user.hasArmor($dataArmors[7]) && user.hasArmor($dataArmors[8]) && user.hasArmor($dataArmors[9])){
            condition = true;
        } else {
            condition = false;
        }  // added curly brace here to prevent double else
    } else {
        condition = false;
    }
} else {
    condition = false;
}

As a neatness measure, rather than have 3 else blocks and 3 "condition = false" lines it might be easier to just say the condition is false at the start of the script and then if the conditions are met change it to true. Like so:

Code:
condition = false;
if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
    if (user.hasArmor($dataArmors[1]) || user.hasArmor($dataArmors[2])) {
        if (user.hasArmor($dataArmors[4]) && user.hasArmor($dataArmors[5]) && user.hasArmor($dataArmors[6]) && user.hasArmor($dataArmors[7]) && user.hasArmor($dataArmors[8]) && user.hasArmor($dataArmors[9])){
            condition = true;
        }
    }
}
Well... it seems I didn't published my last reply... I'll change it then cause it's irrelevant after @Silva post. 😉
As a neatness measure, rather than have 3 else blocks and 3 "condition = false" lines it might be easier to just say the condition is false at the start of the script and then if the conditions are met change it to true. Like so:
I like neatness, thanks!

Anyway, I've tested it this way with a test passive state.
Code:
<Custom Passive Condition>
   if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
    if (user.hasArmor($dataArmors[1]) && user.hasArmor($dataArmors[49])) {
       condition = true
    } else {
       condition = false
    }
  } else {
    condition = false
  }
</Custom Passive Condition>
Works perfectly... Hint: I put an icon for the passive state to see when it's on and off.
When the actor has either weapon1 or 2 and have both armors1 and 49(in my case), the state is on.

But use @Silva neater syntax instead:
Code:
<Custom Passive Condition>
   condition = false;
   if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
      if (user.hasArmor($dataArmors[1]) && user.hasArmor($dataArmors[49])) {
         condition = true;
      } 
    }
</Custom Passive Condition>

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode-
*Concerning Block-scoped declaration, I don't know but I use let, cons and declare functions extensively in Yanfly lunatic notetags like the one above and it works perfectly. 😉
Ah thnx guys, I got it working with the neatness solution from @Silva.
I didn't know that this was possible, I only figured out if and elses the way I used it in my first attempt.
This works
JavaScript:
condition = false;
if (user.hasWeapon($dataWeapons[1]) || user.hasWeapon($dataWeapons[2])) {
    if (user.hasArmor($dataArmors[1]) || user.hasArmor($dataArmors[2])) {
        if (user.hasArmor($dataArmors[4]) && user.hasArmor($dataArmors[5]) && user.hasArmor($dataArmors[6]) && user.hasArmor($dataArmors[7]) && user.hasArmor($dataArmors[8]) && user.hasArmor($dataArmors[9])){
            condition = true;
        }
   }

}


Thanks for the help you opened a new world for me ^^

Original thread: https://forums.rpgmakerweb.com/threads/solved-yanfly-passive-state-plugin-if-inside-an-if-statement.116484/