Enemy Dynamic Max HP

Discussion in 'RGSS Script Requests' started by Teabone, Mar 30, 2019.

    Tags:
  1. Teabone

    Teabone Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMXP
    Hey all,

    I've been trying to find a simple solution for creating a way for enemies during battle to have increased overall maximum health without effecting all instances of that enemy within the troop or in future battles. Is there a variable that people are aware of for something like this?

    I'm also quite new to scripting and its been hard finding resources online still around for RPGXP around this sort of topic.

    Using simple Event Commands dont seem to work as the max hp cap still applies even if you try to percent it over.

    EDIT: Just noticed this can indeed be altered strictly in Control Variables. Though the scripting solutions are best. Thanks @KK20
     
    Last edited: Mar 30, 2019
    #1
  2. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    89
    Likes Received:
    38
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Something as simple as this will suffice for your request. Paste below default scripts, above Main as usual.
    Code:
    class Game_Troop
      alias randomize_enemy_hp setup
      def setup(troop_id)
        randomize_enemy_hp(troop_id)
        @enemies.each do |enemy|
          # HP Variance of -10% to +20% base max HP
          enemy.maxhp += enemy.maxhp * ((rand(31) - 10) / 100.0)
          enemy.hp = enemy.maxhp
        end
      end
    end
    This changes each enemy's MaxHP to be -10% to +20% its database MaxHP value. If you want to be more creative, I'd need to know some specifics.
     
    #2
  3. Teabone

    Teabone Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMXP
    Fantastic intro here to Ruby scripting for me. Already makes sense. Its the existing database variables I need to become more familiar with.

    This has helped me a lot. Thank you very much!

    Im playing around with some very basic enemy leveling systems which have been working okay so far. I like the ability to add some randomization in there its great.
     
    Last edited: Mar 30, 2019
    #3
  4. Teabone

    Teabone Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMXP
    Another question I have, is why can't i paste code into the script event commands script field? lol seems to not allow for pasting from the clipboard there.
     
    #4
  5. Harosata

    Harosata Dramatic Lightning's BFF Veteran

    Messages:
    240
    Likes Received:
    65
    First Language:
    English
    Primarily Uses:
    RMVXA
    Considering you posted this in the RGSS request board, you were given a snippet to place inside your script database, not in the event's script command. If you had placed the snippet in the database, the would would happen when the enemy troop is formed, which will be every battle, including bosses.

    But if you do want to use the script command, if you had managed to squeeze that in there, the code wouldn't have worked what with the code designed to activate in a certain place and not as a line-per-line code. Instead, you would have done something like:
    Code:
    $game_troop.enemies.each do |enemy|
      enemy.maxhp += enemy.maxhp * ((rand(31) - 10) / 100.0)
      enemy.hp = enemy.maxhp
    end
     
    #5

Share This Page