HP/MP heal on max HP/MP gain

I am looking for a script that automatically heals the same HP and MP upon HP and MP gain.

Basically if an actor levels up and now his max HP is 35 HP higher, I want the actors current HP to go up 35 as well.

For example, if say Justin's current HP is 500/1200 and he levels up and now his max HP is 1235, I want him to automatically recover 35 HP so his current HP is now 535/1235. I want the same for MP. so like 400/500 would become 410/510 respectively. (This is how Pokémon games do it).


I also want this to work on status effects that raise max HP/MP like Moltres's dynamax skill that doubles her max everything. Currently I have a healing effect that does this but I would prefer it to do it without adding the "recover HP" and "recover MP" effect.


Keep in mind there are ways in my game that a player can level up outside of battle so something that works in all cases in and out of battle is preferred.

Is there a script for this or one can be made?

You folks have been extremely helpful with scripts and I appreciate it.
changed, I missed the MP request part
Spoiler: HP Up
Ruby:
# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: HP increase on MHP Gain                ║  Version: 1.02     ║
# ║ Author: Roninator2                            ║                    ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function:                                     ║   Date Created     ║
# ║                                               ╠════════════════════╣
# ║  HP goes up when level goes up                ║    18 Sep 2023     ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil                                                      ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description:                                                 ║
# ║       Keep Hp in line with MHP growth                              ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions:                                                      ║
# ║                                                                    ║
# ║   Plug and play                                                    ║
# ║   When MHP goes up 50 points, so will HP                           ║
# ║   Same for MP                                                      ║
# ║                                                                    ║
# ║   Also includes states                                             ║
# ║   State should be set to expire                                    ║
# ║                                                                    ║
# ║   Now supports buffs causing HP & MP increase                      ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates:                                                           ║
# ║ 1.00 - 22 Nov 2024 - Script finished                               ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks:                                                ║
# ║   Roninator2                                                       ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use:                                                      ║
# ║  Follow the original Authors terms of use where applicable         ║
# ║    - When not made by me (Roninator2)                              ║
# ║  Free for all uses in RPG Maker except nudity                      ║
# ║  Anyone using this script in their project before these terms      ║
# ║  were changed are allowed to use this script even if it conflicts  ║
# ║  with these new terms. New terms effective 03 Apr 2024             ║
# ║  No part of this code can be used with AI programs or tools        ║
# ║  Credit must be given                                              ║
# ╚════════════════════════════════════════════════════════════════════╝

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Level Up
  #--------------------------------------------------------------------------
  alias r2_hp_up_on_level level_up
  def level_up
    old_hp = self.mhp
    old_mp = self.mmp
    r2_hp_up_on_level
    new_hp = self.mhp
    new_mp = self.mmp
    hp_up = new_hp - old_hp
    mp_up = new_mp - old_mp
    self.hp += hp_up
    self.mp += mp_up
  end
end

class Game_Battler < Game_BattlerBase
  alias r2_add_new_state_hp_up  add_new_state
  #--------------------------------------------------------------------------
  # * Add New State
  #--------------------------------------------------------------------------
  def add_new_state(state_id)
    old_hp = self.mhp
    old_mp = self.mmp
    r2_add_new_state_hp_up(state_id)
    if self.is_a?(Game_Actor)
      st = $data_states[state_id]
      st.features.each do |ft|
        if ft.code == 21
          if ft.data_id == 0 && ft.value > 1
            new_hp = self.mhp
            chg_hp = new_hp - old_hp
            self.hp += chg_hp
          end
          if ft.data_id == 1 && ft.value > 1
            new_mp = self.mmp
            chg_mp = new_mp - old_mp
            self.mp += chg_mp
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Add Buff
  #--------------------------------------------------------------------------
  alias r2_add_buff_hp_gain   add_buff
  def add_buff(param_id, turns)
    return unless alive?
    old_hp = self.mhp if self.is_a?(Game_Actor)
    old_mp = self.mmp if self.is_a?(Game_Actor)
    hp_buff = @buffs[0] if self.is_a?(Game_Actor)
    mp_buff = @buffs[1] if self.is_a?(Game_Actor)
    r2_add_buff_hp_gain(param_id, turns)
    if self.is_a?(Game_Actor)
      hp_buff2 = @buffs[0]
      mp_buff2 = @buffs[1]
      if hp_buff2 > hp_buff
        new_hp = self.mhp
        chg_hp = new_hp - old_hp
        self.hp += chg_hp
      end
      if mp_buff2 > mp_buff
        new_mp = self.mmp
        chg_mp = new_mp - old_mp
        self.mp += chg_mp
      end
    end
  end
end
I cannot tell by the script and the script comments suggest otherwise.

but I want it to work when states increase MHP and MMP too. I have skills that do that and there are items too like "HP Drink" that applies a temporary MHP buff.

I did specify status effects in my OP.
but I want it to work when states increase MHP and MMP too. I have skills that do that and there are items too like "HP Drink" that applies a temporary MHP buff.
States added, if the drink adds a state to the actor then this is all good, but if not then more will have to be thought out to include not state items.
I could not remember for the item so I just checked. Yes more would need to be done for buffs.

Please and thank you.
Yes more would need to be done for buffs.
Add Buff added.
@Roninator2 , there is a bug in this script. If a status effect lowers MHP, the actor takes double damage.

Say a state takes away 500 MPH, the actor loses 1000 HP when the state is applied and that can result in a death.

This status effect here is a major issue with this script:

IMG_0502.jpeg


as this significantly reduces MHP. Any time this status is applied with the HP increase on MHP gain script, the actor dies even if he was full health 1500/1500.

Removing the HP increase on MHP gain script makes this status effect work as intended, reducing the MHP to 150 instead of killing the actor.
@Roninator2 , there is a bug in this script. If a status effect lowers MHP, the actor takes double damage.

Say a state takes away 500 MPH, the actor loses 1000 HP when the state is applied and that can result in a death.

This status effect here is a major issue with this script:

View attachment 278770

as this significantly reduces MHP. Any time this status is applied with the HP increase on MHP gain script, the actor dies even if he was full health 1500/1500.

Removing the HP increase on MHP gain script makes this status effect work as intended, reducing the MHP to 150 instead of killing the actor.
This is because the script isn't checking that the value is greater than 1.

Change line 58 to

Ruby:
if ft.data_id == 0 && ft.value > 1

and line 63 to

Ruby:
if ft.data_id == 1 && ft.value > 1
Thank You. That fixed the situation beautifully. Even works on Atk State.

Original thread: https://forums.rpgmakerweb.com/threads/hp-mp-heal-on-max-hp-mp-gain.161278/