MV Is there any way to obtain the name of the enemy?

Hi, I'm trying to create a stats menu for my game Eternal Levels, and one of the data I want to show is the strongest enemy defeated, is there any way to show the name of the strongest enemy that was defeated last time taking into account its HP?

Here is an example, sorry if it's in spanish, but I can't change it at the moment, even so I think it's understandable

segunda propuesta.png


The important data is the last one, leave the rest to me
Do you have some way of tracking, determining, and storing "the strongest enemy"?

If you have an ID, it's just $dataEnemies[ID].name
Do you have some way of tracking, determining, and storing "the strongest enemy"?

If you have an ID, it's just $dataEnemies[ID].name
To determine which is the strongest, I will use a variable that is equal to the VP parameter of enemy #1. I'll try that command, I'll let you know if it works, thanks 😉
Could try:
Code:
$dataEnemies.reduce((strongestEnemy, enemy) => (strongestEnemy && strongestEnemy.params[0] >= enemy.params[0]) ? strongestEnemy : enemy).name

Translated:
  • Iterate through every enemy
  • If a strongest enemy, based on maximum HP, has not been determined yet, use the current enemy
  • If the next enemy has more maxmium HP than the currently-determined strongest enemy, that enemy is now the strongest enemy
  • After iterating through every enemy, you should have the highest maximum HP enemy, where enemies with the same maximum HP are ignored
  • Get its name
EDIT: If you want to do it on different stats, replace the 0 in "params[0]" with the corresponding number for the stat you want to compare:
  • 1: maximum MP (mmp)
  • 2: atk
  • 3: def
  • 4: mat
  • 5: mdf
  • 6: agi
  • 7: luk
Could try:
Code:
$dataEnemies.reduce((strongestEnemy, enemy) => (strongestEnemy && strongestEnemy.params[0] >= enemy.params[0]) ? strongestEnemy : enemy).name

Translated:
  • Iterate through every enemy
  • If a strongest enemy, based on maximum HP, has not been determined yet, use the current enemy
  • If the next enemy has more maxmium HP than the currently-determined strongest enemy, that enemy is now the strongest enemy
  • After iterating through every enemy, you should have the highest maximum HP enemy, where enemies with the same maximum HP are ignored
  • Get its name
EDIT: If you want to do it on different stats, replace the 0 in "params[0]" with the corresponding number for the stat you want to compare:
  • 1: maximum MP (mmp)
  • 2: atk
  • 3: def
  • 4: mat
  • 5: mdf
  • 6: agi
  • 7: luk
Hello so long, today I had the opportunity to try your code, I think it is not working very well, I'm using it with the plug in HudMaker, this would be the code that I enter:

${$dataEnemies.reduce((strongestEnemy, enemy) => (strongestEnemy && strongestEnemy.params[0] >= enemy.params[0]) ? strongestEnemy : enemy).name}

1723937550265.png


The problem is that the Ligther always comes out as the most powerful defeated entity, even if I have started a new game without having defeated any entity previously, try defeating a Clump at level 8 but this does not change:

1723937680635.png


These are the statistics of both entities
Spoiler: Ligther
1723937795589.png
Spoiler: Clump
1723937861978.png

Pd: don't try to edit the "params[0]" I'll try to play with that and see if I can correct it
The problem is that the Ligther always comes out as the most powerful defeated entity, even if I have started a new game without having defeated any entity previously
That's exactly what the code @Zevia provided will do - it retrieves the strongest enemy from the entire database.

I asked you in my first response whether you have some way to track this - the game by itself has absolutely no idea which enemies you've seen or defeated. You need to add that, and you haven't shown us anything about how you're trying to do that.

I think Zevia making that suggestion did not understand your first post where you said you wanted it to be limited to the enemies you've beaten. It will always return the highest parameter in the entire list of enemies.
Or you keep a list elsewhere that sort the enemies? It is your game, you decide which enemy is strongest.
That's exactly what the code @Zevia provided will do - it retrieves the strongest enemy from the entire database.

I asked you in my first response whether you have some way to track this - the game by itself has absolutely no idea which enemies you've seen or defeated. You need to add that, and you haven't shown us anything about how you're trying to do that.

I think Zevia making that suggestion did not understand your first post where you said you wanted it to be limited to the enemies you've beaten. It will always return the highest parameter in the entire list of enemies.
I don't have anything implemented yet, I'm also having other problems to show other data with the stats, and I'm also working with the other, can you think of any idea how to solve the enemies name problem?
Or you keep a list elsewhere that sort the enemies? It is your game, you decide which enemy is strongest.
That would be tedious, the idea is to automate the process.
I don't have anything implemented yet, I'm also having other problems to show other data with the stats, and I'm also working with the other, can you think of any idea how to solve the enemies name problem?
I don't know if it's a language problem or something else - this has nothing to do with names. I don't know why you keep bringing it back to that.

Showing the name of any enemy is trivial, I told you that in my first reply. What you need to come up with is how you're tracking the information - how does your game know which enemies the player has seen/killed/whatever?

Here's one method.

Choose a variable (we'll say 42). At the beginning of the game, set it to 0.

Download and install Yanfly's Buffs and States Core, and Auto Passive States.

Make a state, and give it to each actor in your game as a passive.

Give it the notetag:
Code:
<Custom Establish Effect>
if (target.isEnemy() && target.hp <= 0)
{
    if ($gameVariables.value(42) > 0 && target.mhp > $dataEnemies[$gameVariables.value(42)].mhp)
        $gameVariables.setValue(42, target.enemyId());
}
</Custom Establish Effect>

Every time one of your actors kills an enemy, it will check whether that enemy had the most Max HP of anything you've killed; and if yes, store the enemy ID in variable 42.

Then you can use the code I gave you in my first reply to produce the name wherever you want.
Writing a plugin for this would be fairly simple but
That would be tedious, the idea is to automate the process.
makes me not want to.
Try downloading this file and adding it to your plugins directory, or copy/paste the following into a file in your plugins directory that is named exactly DetermineEnemyFromHighestStat.js (it must be named exactly that or else the parameter for a variable won't be read correctly).
Spoiler
JavaScript:
/*:
* @plugindesc Provides Script call to get an enemy based on the highest stat provided.
* @author Zevia
*
* @help Set aside a variable to store the Ids of every enemy that's been defeated.
* The default is 19, but can be changed in the Plugin configuration.
* Whenever an enemy dies, its Id will be added to the collection of enemy Ids
* stored in that variable.
* Use a script command with the following code to get the property of an
* enemy with the highest value based on its parameters:
* Zevia.getEnemyPropertyByHighestValue()
* OR
* Zevia.getEnemyPropertyByHighestValue(x, y)
* where x is the parameter Id you want to compare for defeated enemies and
* y is the property of the enemy you want, as a String. For example:
* Zevia.getEnemyPropertyByHighestValue(0, 'name')
* would return the name of the defeated enemy with the highest MHP.
* If x and y are not provided, the default values are 0 (MHP) and 'name'.
* Parameter Ids map to enemy properties as values:
* 0: mhp
* 1: mmp
* 2: atk
* 3: def
* 4: mat
* 5: mdf
* 6: agi
* 7: luk
*
* Additional examples:
* Get the experience value of the defeated enemy with the highest MMP:
* Zevia.getEnemyPropertyByHighestValue(1, 'exp')
* Get the gold of the defeated enemy with the highest luk:
* Zevia.getEnemyPropertyByHighestValue(7, 'gold')

* @param defeatedEnemiesVariable
* @text Defeated Enemy Ids Variable
* @type variable
* @desc The variable used to store the Ids of every defeated enemy
* @default 19
*/

(function(module) {
    'use strict';

    var Zevia = module.Zevia || {};
    module.Zevia = Zevia;

    var parameters = PluginManager.parameters('DetermineEnemyFromHighestStat');
    var defeatedEnemiesVariable = parseInt(parameters.defeatedEnemiesVariable);

    Zevia.getEnemyPropertyByHighestValue = function(paramId, enemyProperty) {
        const parameterId = paramId || 0;
        const property = enemyProperty || 'name';
        const defeatedEnemyIds = $gameVariables.value(defeatedEnemiesVariable) || [];
        if (defeatedEnemyIds.length === 0) {
            return '';
        }
        if (defeatedEnemyIds.length === 1) {
            return $dataEnemies[defeatedEnemyIds[0]][property];
        }
        return defeatedEnemyIds.reduce((highestEnemyId, enemyId) => {
            const highestEnemy = $dataEnemies[highestEnemyId];
            const enemy = $dataEnemies[enemyId];
            return (highestEnemy && highestEnemy.params[parameterId] >= enemy.params[parameterId]) ? highestEnemy : enemy;
        })[property] || '';
    };

    Zevia.enemyDie = Game_Enemy.prototype.die;
    Game_Enemy.prototype.die = function() {
        Zevia.enemyDie.call(this);
        const defeatedEnemyIds = $gameVariables.value(defeatedEnemiesVariable) || [];
        if (defeatedEnemyIds.indexOf(this._enemyId) === -1) {
            $gameVariables.setValue(defeatedEnemiesVariable, defeatedEnemyIds.concat(this._enemyId));
        }
    };
})(window);

It should provide a script command you can call by doing Script: Zevia.getEnemyPropertyByHighestValue()

You'll need to configure the plugin to reserve a variable for storing the Ids of every defeated enemy. By default, it's variable 19, so if you're already using variable 19 for something else, you'll want to change the configuration to a different variable Id.

Then you could do something like creating a common event of:
Code:
Control Variables: #0001: strongestEnemyDefeatedName = Zevia.getEnemyPropertyByHighestValue()
Text: The name of the strongest enemy defeated, based on MHP,
          is \V[1]

If no enemies have been defeated, the value will be an empty String.

If you want a different property that's available on a $dataEnemies instance, or if you want to determine an enemy from the highest value of a different parameter, you can pass those to the method for the script call:
Code:
Control Variables: #0001 strongestEnemyGoldByLuk = Zevia.getEnemyPropertyByHighestValue(7, 'gold')
Text: The gold dropped by the strongest enemy defeated, based
          on LUK, is \V[1]
The default values are 0 (meaning MHP) and 'name'. Note that properties always have to be passed as a String, so you should use quotes around the property, e.g. "name" / 'name', "gold" / 'gold', "exp" / 'exp', etc.
Try downloading this file and adding it to your plugins directory, or copy/paste the following into a file in your plugins directory that is named exactly DetermineEnemyFromHighestStat.js (it must be named exactly that or else the parameter for a variable won't be read correctly).
Spoiler
JavaScript:
/*:
* @plugindesc Provides Script call to get an enemy based on the highest stat provided.
* @author Zevia
*
* @help Set aside a variable to store the Ids of every enemy that's been defeated.
* The default is 19, but can be changed in the Plugin configuration.
* Whenever an enemy dies, its Id will be added to the collection of enemy Ids
* stored in that variable.
* Use a script command with the following code to get the property of an
* enemy with the highest value based on its parameters:
* Zevia.getEnemyPropertyByHighestValue()
* OR
* Zevia.getEnemyPropertyByHighestValue(x, y)
* where x is the parameter Id you want to compare for defeated enemies and
* y is the property of the enemy you want, as a String. For example:
* Zevia.getEnemyPropertyByHighestValue(0, 'name')
* would return the name of the defeated enemy with the highest MHP.
* If x and y are not provided, the default values are 0 (MHP) and 'name'.
* Parameter Ids map to enemy properties as values:
* 0: mhp
* 1: mmp
* 2: atk
* 3: def
* 4: mat
* 5: mdf
* 6: agi
* 7: luk
*
* Additional examples:
* Get the experience value of the defeated enemy with the highest MMP:
* Zevia.getEnemyPropertyByHighestValue(1, 'exp')
* Get the gold of the defeated enemy with the highest luk:
* Zevia.getEnemyPropertyByHighestValue(7, 'gold')

* @param defeatedEnemiesVariable
* @text Defeated Enemy Ids Variable
* @type variable
* @desc The variable used to store the Ids of every defeated enemy
* @default 19
*/

(function(module) {
    'use strict';

    var Zevia = module.Zevia || {};
    module.Zevia = Zevia;

    var parameters = PluginManager.parameters('DetermineEnemyFromHighestStat');
    var defeatedEnemiesVariable = parseInt(parameters.defeatedEnemiesVariable);

    Zevia.getEnemyPropertyByHighestValue = function(paramId, enemyProperty) {
        const parameterId = paramId || 0;
        const property = enemyProperty || 'name';
        const defeatedEnemyIds = $gameVariables.value(defeatedEnemiesVariable) || [];
        if (defeatedEnemyIds.length === 0) {
            return '';
        }
        if (defeatedEnemyIds.length === 1) {
            return $dataEnemies[defeatedEnemyIds[0]][property];
        }
        return defeatedEnemyIds.reduce((highestEnemyId, enemyId) => {
            const highestEnemy = $dataEnemies[highestEnemyId];
            const enemy = $dataEnemies[enemyId];
            return (highestEnemy && highestEnemy.params[parameterId] >= enemy.params[parameterId]) ? highestEnemy : enemy;
        })[property] || '';
    };

    Zevia.enemyDie = Game_Enemy.prototype.die;
    Game_Enemy.prototype.die = function() {
        Zevia.enemyDie.call(this);
        const defeatedEnemyIds = $gameVariables.value(defeatedEnemiesVariable) || [];
        if (defeatedEnemyIds.indexOf(this._enemyId) === -1) {
            $gameVariables.setValue(defeatedEnemiesVariable, defeatedEnemyIds.concat(this._enemyId));
        }
    };
})(window);

It should provide a script command you can call by doing Script: Zevia.getEnemyPropertyByHighestValue()

You'll need to configure the plugin to reserve a variable for storing the Ids of every defeated enemy. By default, it's variable 19, so if you're already using variable 19 for something else, you'll want to change the configuration to a different variable Id.

Then you could do something like creating a common event of:
Code:
Control Variables: #0001: strongestEnemyDefeatedName = Zevia.getEnemyPropertyByHighestValue()
Text: The name of the strongest enemy defeated, based on MHP,
          is \V[1]

If no enemies have been defeated, the value will be an empty String.

If you want a different property that's available on a $dataEnemies instance, or if you want to determine an enemy from the highest value of a different parameter, you can pass those to the method for the script call:
Code:
Control Variables: #0001 strongestEnemyGoldByLuk = Zevia.getEnemyPropertyByHighestValue(7, 'gold')
Text: The gold dropped by the strongest enemy defeated, based
          on LUK, is \V[1]
The default values are 0 (meaning MHP) and 'name'. Note that properties always have to be passed as a String, so you should use quotes around the property, e.g. "name" / 'name', "gold" / 'gold', "exp" / 'exp', etc.
Thank you very much, I really appreciate it, and to the others, sorry for the inconvenience, especially to you ATT_Turan that at the beginning I think we didn't understand each other very well

Original thread: https://forums.rpgmakerweb.com/threads/is-there-any-way-to-obtain-the-name-of-the-enemy.171015/