Getting actor HP as a percentage

Discussion in 'RPG Maker VX Ace' started by Kes, May 15, 2017.

Thread Status:
Not open for further replies.
  1. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,207
    Likes Received:
    9,839
    First Language:
    English
    Primarily Uses:
    RMVXA
    I need to be able to identify in battle if a particular actor's HP [actor ID = 2] is equal to or less than 35% of MHP using a troop event set to run every turn.

    I can set a variable to MHP, and another to current HP but I cannot see anywhere in a conditional branch how to determine if the second variable is equal to or less than a percentage of the first variable.

    Does anyone know if this can be done e.g. with a script call in the conditional?

    Thanks.
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    27,113
    Likes Received:
    5,947
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    mathematics

    %HP = 100*HP/MHP

    So use a series of control variable commands to calculate that number and then a conditional branch if %HP is higher than 35 or not
     
    #2
    Kes likes this.
  3. Shaz

    Shaz Veteran Veteran

    Messages:
    36,935
    Likes Received:
    10,870
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Code:
    Conditional Branch: Script: $game_actors[2].hp_rate <= 0.35
    hp_rate is an existing method that will give you the current HP / max HP. It returns a value equal to or less than 1.

    0.35 is 35%
     
    Last edited: May 15, 2017
    #3
    Heirukichi, Kes and Wavelength like this.
  4. Wavelength

    Wavelength Pre-Merge Boot Veteran

    Messages:
    3,698
    Likes Received:
    2,978
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    I always use hp_rate for this kind of thing - like @Shaz suggested.
     
    #4
    Kes likes this.
  5. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,207
    Likes Received:
    9,839
    First Language:
    English
    Primarily Uses:
    RMVXA
    @Andar Thanks, that works - though it took a while before the enemies stopped hitting everyone else except the one I wanted damaged so that I could test it.

    @Shaz and @Wavelength Thaks for that info - it will make it much quicker for other instances where I need this.

    Closing, as solved.

     
    #5
  6. HexMozart88

    HexMozart88 The Master of Random Garbage Veteran

    Messages:
    1,574
    Likes Received:
    2,804
    Location:
    A small hut in the forest
    First Language:
    English
    Primarily Uses:
    RMVXA
    @Kes Psst. It's not closed.
     
    #6
    Kes likes this.
  7. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,207
    Likes Received:
    9,839
    First Language:
    English
    Primarily Uses:
    RMVXA
    @HexMozart88 Oops! It's been one of those mornings. Thanks for letting me know.

    Really closing it this time.

     
    #7
Thread Status:
Not open for further replies.

Share This Page