Script to get the max HP of an enemy from the database

In the attached picture the value I would want to get is 200.


I want to initialize a variable with this in my event (I am making a very-lite ABS).


I googled around but can't seem to find a reference of how to programatically get that value. I could initialize my events by hand but I would rather reference this variable.


Thanks!

01_08_06_img01.png
In Control Variables -> Script enter this:


$dataEnemies[ID].params[0]


where ID is the id of the enemy of which you want to get the max HP.


E.g. if your bat has the id 0002 in the database,


$dataEnemies[2].params[0]


will give you the max HP of the bat.


If you want to access the other parameters,


param[1] is MMP


param[2] is ATK


param[3] is DEF


param[4] is MAT


param[5] is MDF
no need for a script - you didn't find a script because that value is one of those that can be directly accessed by the control variable command in the game data section.


Simply use a control variable command and select game data, then change from the default map ID to whatever enemy parameter you want to access.


EDIT (and that way you don't even have to remember the numbers for each param as you would have to do in @LadyBaskerville s solution)
Simply use a control variable command and select game data, then change from the default map ID to whatever enemy parameter you want to access.



That only seems to work for enemies in battles, though - the drop down menu offers the numbers from 1 to 8 for the enemies' positions in the troop, not the enemy IDs from the database. Or am I overlooking something there?
no, that is correct because by default enemies exist only during battlescreen
Looking through the .js files again, I think I understand the difference between the two methods now. The enemies referenced by Game Data -> Enemy are Game_Enemy objects which are only created when a Game_Troop is loaded - that's why they only exist during battle. And I completely agree that in this case it's much easier to just use the Game Data option for the variable 😉


But since the OP is talking about an ABS, I assumed that the event which sets the variable to the enemy's MHP would be on a map, not in a battle. $dataEnemies works there because it is not referring to Game_Enemy objects, but to the data saved in the Enemies.json file (loaded by the DataManager at the start of the game), which is accessible at any time.


Hope that makes sense 🙂
Thanks both. For me the solution was as identified by LadyBaskerville to use $dataEnemies[ID].params[0] as I am overworld in ABS.


How on earth do you discover things like the existence of dataEnemies. I cannot find it in the Help that ships with the game at all. Is it from looking in the .js and .json files directly?
You won't find it in the help file.  It's in the scripts.  rpg_objects.js is a good one, particularly a lot of the Game_Interpreter functions.  


This might help you get started:
Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/script-to-get-the-max-hp-of-an-enemy-from-the-database.71078/