Question regarding Yanfly's Libra Tips and Tricks

Hello guys,

Hope everybody is well and healthy!
Quick question, I am using Yanfly's Libra tips and tricks to scan the enemy for strength and weaknesses.
I was wondering if there is a way to show an enemy's resistance to a state and their skills as well?
Sadly my JavaScript knowledge is very limited so I thought I try and pick your brains.

Here is the link to the tips and trick btw:




cheers
You can do this using the same sort of structure as the element rates section uses.

Code:
var weakness = '';
  var resist = '';
  var immune = '';
  var absorb = '';
  var states = $dataStates;
  for (var i = 1; i < states.length; ++i) {
    var name = states[i].name;
    var rate = target.stateRate(i);
    if (rate > 1) {
      weakness += name + ' ';
    } else if (rate < 0) {
      absorb += name + ' ';
    } else if (rate === 0) {
      immune += name + ' ';
    } else if (rate < 1) {
      resist += name + ' ';
    }
  }
  if (weakness === '') weakness = 'None';
  if (resist === '') resist = 'None';
  if (immune === '') immune = 'None';
  if (absorb === '') absorb = 'None';
  weakness = '\\c[4]Weakness:\\c[0] ' + weakness + '\n';
  resist = '\\c[4]Resist:\\c[0] ' + resist + '\n';
  immune = '\\c[4]Immune:\\c[0] ' + immune + '\n';
  absorb = '\\c[4]Absorb:\\c[0] ' + absorb;
  text = weakness + resist + immune + absorb;
  $gameMessage.add(text);
You can do this using the same sort of structure as the element rates section uses.

Code:
var weakness = '';
  var resist = '';
  var immune = '';
  var absorb = '';
  var states = $dataStates;
  for (var i = 1; i < states.length; ++i) {
    var name = states[i].name;
    var rate = target.stateRate(i);
    if (rate > 1) {
      weakness += name + ' ';
    } else if (rate < 0) {
      absorb += name + ' ';
    } else if (rate === 0) {
      immune += name + ' ';
    } else if (rate < 1) {
      resist += name + ' ';
    }
  }
  if (weakness === '') weakness = 'None';
  if (resist === '') resist = 'None';
  if (immune === '') immune = 'None';
  if (absorb === '') absorb = 'None';
  weakness = '\\c[4]Weakness:\\c[0] ' + weakness + '\n';
  resist = '\\c[4]Resist:\\c[0] ' + resist + '\n';
  immune = '\\c[4]Immune:\\c[0] ' + immune + '\n';
  absorb = '\\c[4]Absorb:\\c[0] ' + absorb;
  text = weakness + resist + immune + absorb;
  $gameMessage.add(text);

Wow thanks so much for this mate! Ill give it a shot!
@Trihan
Hello mate,
Hope you are well. Thank you very much with your help regarding this. It is already working very well.
I was just wondering if there is a way to call the icon of the state as well?

With the Elements the icons are called via the text code \I[n] next to the elements in the Database...
This method doesnt work for the sates...
Bump
I was just wondering if there is a way to call the icon of the state as well?

With the Elements the icons are called via the text code \I[n] next to the elements in the Database...
This method doesnt work for the sates...
It should, all the icons come from the same file. What's the code you're using that displays it for elements but not states?
It should, all the icons come from the same file. What's the code you're using that displays it for elements but not states?
The sections of code are almost identical for the elements and states...

var weakness = '';
var resist = '';
var immune = '';
var absorb = '';
var states = $dataStates; // (instead of $dataStates; this would be: $dataSystem.elements😉
for (var i = 1; i < states.length; ++i) {
var name = states.name;
var rate = target.stateRate(i);
if (rate > 1) {
weakness += name + ' ';
} else if (rate < 0) {
absorb += name + ' ';
} else if (rate === 0) {
immune += name + ' ';
} else if (rate < 1) {
resist += name + ' ';
}
}
if (weakness === '') weakness = 'None';
if (resist === '') resist = 'None';
if (immune === '') immune = 'None';
if (absorb === '') absorb = 'None';
weakness = '\\c[4]Weakness:\\c[0] ' + weakness + '\n'; //(I assume this is the section of the code that displays the text)
resist = '\\c[4]Resist:\\c[0] ' + resist + '\n';
immune = '\\c[4]Immune:\\c[0] ' + immune + '\n';
absorb = '\\c[4]Absorb:\\c[0] ' + absorb;
text = weakness + resist + immune + absorb;
$gameMessage.add(text);



Now in case of the elements, the icons are being added due to the text code \I[n] next to the elements in the Database. Like \I[64]Fire for example
This method doesn't work for the sates though...

so the short answer is,
using the icon text code in the 'types' section, its just how the elements are named.

sry just felt a need to chime in because you gave the exact same description "\I[n] next to elements in database" both times. (always got so annoyed when the ex gave a description, i ask "what do you mean" and then she just repeats the 😠 exact same thing that i didnt understand the 1st time. its always good to restructure you descriptions when repeating yourself so people with different thought processes are more likely to understand your intent.)
so the short answer is,
using the icon text code in the 'types' section, no direct connection to the libra coding.
its just how the elements are named.
Yeah, that would be the proper way to explain it 🙂 Thank you for clarifying it!
The sections of code are almost identical for the elements and states...
Your code is unreadable because you didn't put it inside CODE tags (the upper-right icon in the text box). That caused several characters inside of brackets to instead become formatting tags. It also caused you to lose your indentation. That being said...
Now in case of the elements, the icons are being added due to the text code \I[n] next to the elements in the Database. Like \I[64]Fire for example
I didn't understand from your prior post that you had actually edited the names of the elements in the Types tab to include the escape code for the icon.
This method doesn't work for the sates though...
Technically, it does, if you renamed all of your states to include the code for their icon the way you did your elements. That's the source of my confusion, that you're saying something "doesn't work" when you're doing two completely different things.

Obviously you'll need to add the escape code into the string inside of the portion that's dedicated to your states. This will only work cleanly if you've structured your icons so that they're in order according to the state (i.e. state 3 is icon 40, state 4 is icon 41, etc.). If they're not in order, your code will be a huge mess to add this in.
But you would do something like:
Code:
var name = "\I[" + String(i+37) + "]" + states[i].name;
where the "i+37" is whatever math you'd do for the difference between the ID of the state and the index of the icon.

Original thread: https://forums.rpgmakerweb.com/threads/question-regarding-yanflys-libra-tips-and-tricks.123606/