MV Attempting to add possible item drops to Yanfly Libra skill

I just implemented the setup to create the Libra skill, as outlined on Yanfly's tips and tricks page, but I am wondering if there is an way to add to the list of displayed information the possible items the party can receive from defeating the target.

I have a very limited understanding of javascript and I have attempted to reference the drops by adding to the code supplied from Yanfly, but I have not been able to figure it out.

Spoiler: Supplied Code
JavaScript:
<Before Eval>
if (target.isEnemy()) {
  var id = target._enemyId;
  $gameSystem.addHpGaugeEnemy(id);

  var text = target.name() + '\n';
  text += '\\px[100]\\c[4]HP:\\c[0] ' + target.hp;
  text += '/' + target.mhp;
  text += '\\px[400]\\c[4]MP:\\c[0] ' + target.mp;
  text += '/' + target.mmp;
  text += '\\px[700]\\c[4]TP:\\c[0] ' + target.tp;
  text += '\n';
  text += '\\px[100]\\c[4]ATK:\\c[0] ' + target.atk;
  text += '\\px[400]\\c[4]MAT:\\c[0] ' + target.mat;
  text += '\\px[700]\\c[4]AGI:\\c[0] ' + target.agi;
  text += '\n';
  text += '\\px[100]\\c[4]DEF:\\c[0] ' + target.def;
  text += '\\px[400]\\c[4]MDF:\\c[0] ' + target.mdf;
  text += '\\px[700]\\c[4]LUK:\\c[0] ' + target.luk;
  $gameMessage.add(text);
 
  var weakness = '';
  var resist = '';
  var immune = '';
  var absorb = '';
  var elements = $dataSystem.elements;
  for (var i = 1; i < elements.length; ++i) {
    var name = elements[i];
    var rate = target.elementRate(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);
}
</Before Eval>

I have tried looking through the plugin and source code files in Visual Code Studio but I have not been able to figure out how to reference the possible drops. I am using many yanfly plugins but the one I am hoping to work with here is YEP_ExtraEnemyDrops, as it allows me to set the possible drops within each enemy's notetag box.

I tried simply adding:

JavaScript:
var drops = enemy.drops();
$gameMessage.add('Loot: ' + drops);

to the end of the supplied code and that didn't do it.

I tried swapping enemy.drops out for pretty much anything I could find in the plugin and source code files, but I couldn't figure out. I thought I was headed in the right direction when my search brought me to Yanfly's Steal & Snatch plugin, since it provides an option to include the drops into the pool of steal-able items. The plugin also provides an option to remove a stolen item from the targets drop pool.

I found the code that handles that and I'm hoping the answer lies here somewhere:

Spoiler: Yanfly.Steal.Game_Enemy_makeDropItems
JavaScript:
if (Yanfly.Param.StealDropRemove) {

Yanfly.Steal.Game_Enemy_makeDropItems = Game_Enemy.prototype.makeDropItems;
Game_Enemy.prototype.makeDropItems = function() {
    var drops = Yanfly.Steal.Game_Enemy_makeDropItems.call(this);
    var max = this.stealableItems().length;
    for (var i = 0; i < max; ++i) {
      var stealable = this.stealableItems()[i];
      if (stealable.type === 'gold') continue;
      if (!stealable.isStolen) continue;
      if (!stealable.isDrop) continue;
      stealable.isDrop = false;
      var id = stealable.id;
      if (stealable.type === 'item') {
        var item = $dataItems[id];
      } else if (stealable.type === 'weapons') {
        var item = $dataWeapons[id];
      } else {
        var item = $dataArmors[id];
      }
      var index = drops.indexOf(item);
      drops.splice(index, 1);
    }
    return drops;
};

I also looked into some of the core files and found this:
JavaScript:
BattleManager.makeRewards = function() {
    this._rewards = {};
    this._rewards.gold = $gameTroop.goldTotal();
    this._rewards.exp = $gameTroop.expTotal();
    this._rewards.items = $gameTroop.makeDropItems();
};

As well as this:
JavaScript:
Game_Enemy.prototype.makeDropItems = function() {
    return this.enemy().dropItems.reduce(function(r, di) {
        if (di.kind > 0 && Math.random() * di.denominator < this.dropItemRate()) {
            return r.concat(this.itemObject(di.kind, di.dataId));
        } else {
            return r;
        }
    }.bind(this), []);
};

I just don't know how to put it all together to do what I want to do, which is simply add the items in an enemy's drop pool to the Libra skill text window.

Any help with this would be greatly appreciated as enemy drops are pretty important to my current project and if the player could see them during battle it would probably make a great deal of difference in the long run.

I just checked CGMV Encyclopedia and it does in fact show the drops added through the notetags, if I can figure out how this plugin is referencing the notetag drops, I might be able to figure it out...I am too tired at this point to keep working on it but at least I have a starting point for tomorrow.


Well...just before calling it quits I looked into CGMV Encyclopedia plugin a bit and found out how to reference the items drops...
$dataEnemies[enemyId].dropItems

Now I just need to figure out how to actually draw the correct information into the text window as putting:
$gameMessage.add('Loot: ' + $dataEnemies[1].dropItems)

Just shows: Loot: [Object][Object][Object][Object][Object] all the way across the text window.

I am definitely stopping there for the night, I'm glad I was able to make some progress.
This is pretty tricky because of the way the game stores item drops....

If each enemy only drops a singular item you can do something like the below:
Code:
  var dropId = $dataEnemies[target._enemyId].dropItems[x].dataId;
  var itemName = $dataItems[dropId].name;
  text = ('Loot ' + itemName);
  $gameMessage.add(text);

Where X is the array of the item.

It becomes more complex when you have different types of drops, such as weapons and multiple drops. You would need to check the kind of each, store all data as variables, and make conditional calls to assign it to item names.

This is how it would work with the DEFAULT system. If you're using a plugin to modify drops, I would have to look into that more, but it's possible that drop names are more easily managed. I'll check some more later.



Edit:

This would work for the default system. A friend of mine helped me put it together.
Code:
var droppedItems = [];
//extract dropped items from given enemy into array 
for(let x=0; x<$dataEnemies[target._enemyId].dropItems.length; x++){
  if($dataEnemies[target._enemyId].dropItems[x].kind !== 0){
    droppedItems.push($dataEnemies[target._enemyId].dropItems[x]);
  }
}

//extract names of items based on kind value
var itemNames = [];
for(let x = 0; x<droppedItems.length; x++){
  switch(droppedItems[x].kind){
    case 1: 
      itemNames.push($dataItems[droppedItems[x].dataId].name);
      break;
    case 2:
      itemNames.push($dataWeapons[droppedItems[x].dataId].name);      
      break;
    case 3:
      itemNames.push($dataArmors[droppedItems[x].dataId].name);
      break;
    default:
      itemNames.push("invalid item");
  }
}

//print names
for(let x=0; x<itemNames.length; x++){
  console.log(itemNames[x]);
  $gameMessage.add(itemNames[x]);
 }
Awesome! I will definitely give this a shot! Thank you for your help.

-EDIT-

It works perfectly! Thank you so much for this! Looking at the code and seeing it in action definitely helps me see what I was doing wrong, I am still relatively new with javascript and still don't have a complete understanding of even some of the basics, clearly.
This is pretty tricky because of the way the game stores item drops....

If each enemy only drops a singular item you can do something like the below:
Code:
  var dropId = $dataEnemies[target._enemyId].dropItems[x].dataId;
  var itemName = $dataItems[dropId].name;
  text = ('Loot ' + itemName);
  $gameMessage.add(text);

Where X is the array of the item.

It becomes more complex when you have different types of drops, such as weapons and multiple drops. You would need to check the kind of each, store all data as variables, and make conditional calls to assign it to item names.

This is how it would work with the DEFAULT system. If you're using a plugin to modify drops, I would have to look into that more, but it's possible that drop names are more easily managed. I'll check some more later.



Edit:

This would work for the default system. A friend of mine helped me put it together.
Code:
var droppedItems = [];
//extract dropped items from given enemy into array
for(let x=0; x<$dataEnemies[target._enemyId].dropItems.length; x++){
  if($dataEnemies[target._enemyId].dropItems[x].kind !== 0){
    droppedItems.push($dataEnemies[target._enemyId].dropItems[x]);
  }
}

//extract names of items based on kind value
var itemNames = [];
for(let x = 0; x<droppedItems.length; x++){
  switch(droppedItems[x].kind){
    case 1:
      itemNames.push($dataItems[droppedItems[x].dataId].name);
      break;
    case 2:
      itemNames.push($dataWeapons[droppedItems[x].dataId].name);    
      break;
    case 3:
      itemNames.push($dataArmors[droppedItems[x].dataId].name);
      break;
    default:
      itemNames.push("invalid item");
  }
}

//print names
for(let x=0; x<itemNames.length; x++){
  console.log(itemNames[x]);
  $gameMessage.add(itemNames[x]);
 }
Would it be possible to modify this so that it states "LOOT" and shows it all on one line, such as:

LOOT: Drop 1 Drop 2 Drop 3
Would it be possible to modify this so that it states "LOOT" and shows it all on one line, such as:

LOOT: Drop 1 Drop 2 Drop 3

This should work:

JavaScript:
var itemId = [];
for(let x = 0; x<droppedItems.length; x++){
  switch(droppedItems[x].kind){
    case 1:
      itemId.push($dataItems[droppedItems[x].dataId].id);
      break;
    case 2:
      itemId.push($dataWeapons[droppedItems[x].dataId].id);     
      break;
    case 3:
      itemId.push($dataArmors[droppedItems[x].dataId].id);
      break;
    default:
      itemId.push("invalid item");
  }
}

var drops = 'Drops: ';
for(let x=0; x<itemId.length; x++){
   console.log(itemId[x]);
   drops += ' \\ii[' + itemId[x] + ']';
 }
  $gameMessage.add(drops);
 }
}

Original thread: https://forums.rpgmakerweb.com/threads/attempting-to-add-possible-item-drops-to-yanfly-libra-skill.126734/