MV Modifying Yanfly "Libra" tips and tricks to show passive states




I'm trying to modify the lunatic code for the Libra tips and tricks to show Passive states and their descriptions.
Something like this.

1697217585219.png




Since checking battler.isStateaffected() doesn't seem to work for passives, I found a workaround for that issue on the state Category plugin page and found some script calls that can be used to check for passive states marked with the category <Category: 'passive'>, but I don't know how to go through each of them and add text for each one detected.

battler.isStateCategoryAffected('text')
- This will return a 'true' or 'false' after checking if battler is affected
by a state with category 'text'. Replace 'text' with the category name but
keep the quotes. This will check even passive states.

battler.getStateCategoryAffectedCount('text');
- This will return a number value to see how many states (passives included)
the battler is affected by with the category 'text'. Replace 'text' with the
category name but keep the quotes.



This is about as far as I got with my terrible js skills and digging through other tips and tricks pages, probably wrong but it was worth a try:

JavaScript:
</Before Eval>
    var states = target.getStateCategoryAffectedCount('Passive');
    // Loop through each state.
    for (var i = 0; i < states.length; ++i) {
      // Get currently looped checked state
      var checkState = states[i];
      var name = states[i].name;



      }
  text = '\\c[4](Passive) \\c[0] ' + name ;
  $gameMessage.add(text);
}
</Before Eval>
Since checking battler.isStateaffected() doesn't seem to work for passives
It absolutely does - passive states are no different than regular ones in terms of how they're stored on actors and enemies.

If you use the correct syntax (Affected is capitalized) and the correct reference (e.g. target rather than battler), it should do exactly what you want.

Also, the code you provided at the bottom wouldn't work, you're mixing different kinds of data object - trying to treat an integer value like an array.
It absolutely does - passive states are no different than regular ones in terms of how they're stored on actors and enemies.

If you use the correct syntax (Affected is capitalized) and the correct reference (e.g. target rather than battler), it should do exactly what you want.

Also, the code you provided at the bottom wouldn't work, you're mixing different kinds of data object - trying to treat an integer value like an array.
This page I found said it doesn't check for passive states though: http://www.yanfly.moe/wiki/Template:Skills_and_States_Core_Passive_States_Clarification

For those using the code "a.isStateAffected(10)" to check if a target is affected by a state or not, this does NOT check passive states. This only checks for states that were directly applied to the target.

This is NOT a bug.

Instead, use "a.states().includes($dataStates[10])" to check for them. This code will search for both directly applied states and passive states alike.


I don't know if this page is outdated or if it's since been patched though
I don't know how you got to that tiny portion of a page, but that is from the instructions for the VisuStella Skills and States Core (as it says in the URL and the page title 😉). It has nothing to do with Yanfly's Auto Passive States.
I stumbled onto that specific page while googling everywhere for solutions :hswt: whoops.


Since it works then, is there a way other than using state categories to check if the states on the enemy are passive states with .isStateAffected()? I have a lot of passives and need a quick way to get them

For the bottom part of the code I'm struggling on, how do I get the text for each state name and state description to show in a message? I'm a bit confused how the Libra text works.
Since it works then, is there a way other than using state categories to check if the states on the enemy are passive states with .isStateAffected()?
Well, you know which states are granted passively because you made them in the database.

But if you're just iterating through every state on an enemy, no, there's no way from looking at a state whether it was granted by a passive notetag unless you mark it (such as with the state category).

For the bottom part of the code I'm struggling on, how do I get the text for each state name and state description to show in a message? I'm a bit confused how the Libra text works.
You'd just copy the exact same format.

Paste this above the last line of the Libra code ($gameMessage.add):
Code:
target.states().forEach(state =>
{
    if (state.category.contains("PASSIVE"))
        text += "\\c[4]Passive:\\c[0] " + state.name;
});
Well, you know which states are granted passively because you made them in the database.

But if you're just iterating through every state on an enemy, no, there's no way from looking at a state whether it was granted by a passive notetag unless you mark it (such as with the state category).


You'd just copy the exact same format.

Paste this above the last line of the Libra code ($gameMessage.add):
Code:
target.states().forEach(state =>
{
    if (state.category.contains("PASSIVE"))
        text += "\\c[4]Passive:\\c[0] " + state.name;
});
Sweet! Thanks so much for the help!

Edit: Hmm it did successfully pull up the state name but it pulled it up with 'undefined' next to it.
1697313677460.png


Edit 2: Alright I got it to work! Leaving this here for anyone who needs the fix:

1697314556409.png



JavaScript:
<Before Eval>

SceneManager._scene._logWindow.clear();

target.states().forEach(state =>{

    if (state.category.contains("PASSIVE")){

    var text ='\\c[23](Passive)\\c[0] ' +  state.name;

    $gameMessage.add(text);

    }

});

</Before Eval>
It wasn't clear that you weren't using any of the existing Libra functionality.

If you wanted just the states and weren't using the rest of that code, it would've made more sense not to reference it in your first post at all - as my directions in my prior post were based on the text variable already being declared by the existing code 😛

Personally, I would take the variable declaration and the $gameMessage.add() out of the loop, the way Yanfly had it in Libra - that way you're getting one message with all the information, rather than the player having to click through each state individually.

But whichever you prefer for your game 🙂

Original thread: https://forums.rpgmakerweb.com/threads/modifying-yanfly-libra-tips-and-tricks-to-show-passive-states.161989/