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

Discussion in 'RPG Maker MV' started by ninja_tom, Nov 17, 2016.

  1. ninja_tom

    ninja_tom Veteran Veteran

    Messages:
    33
    Likes Received:
    4
    First Language:
    English
    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
     
    #1
  2. LadyBaskerville

    LadyBaskerville Hell-poodle Veteran

    Messages:
    645
    Likes Received:
    495
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    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
     
    #2
    Robin Hoot likes this.
  3. Andar

    Andar Veteran Veteran

    Messages:
    28,672
    Likes Received:
    6,594
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    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)
     
    Last edited by a moderator: Nov 17, 2016
    #3
  4. LadyBaskerville

    LadyBaskerville Hell-poodle Veteran

    Messages:
    645
    Likes Received:
    495
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV


    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?
     
    #4
  5. Andar

    Andar Veteran Veteran

    Messages:
    28,672
    Likes Received:
    6,594
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    no, that is correct because by default enemies exist only during battlescreen
     
    #5
  6. LadyBaskerville

    LadyBaskerville Hell-poodle Veteran

    Messages:
    645
    Likes Received:
    495
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    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 :)
     
    #6
  7. ninja_tom

    ninja_tom Veteran Veteran

    Messages:
    33
    Likes Received:
    4
    First Language:
    English
    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?
     
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,911
    Likes Received:
    11,586
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    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:
     
    #8
  9. ninja_tom

    ninja_tom Veteran Veteran

    Messages:
    33
    Likes Received:
    4
    First Language:
    English
    Thanks!
     
    #9

Share This Page