• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
Low HP BGM

v20.1 Low HP BGM 2021-06-05

This resource pertains to version 20.1 of Pokémon Essentials.
Pokémon Essentials Version
v20.1 ➖
A screenshot of a Pokémon battle. The player's Pikachu has HP in the red.

This causes the BGM to change mid-battle if your Pokémon is on red! It'll change if they take damage or if they're sent out while on red, and will return to the original if your Pokémon is healed to yellow/green, or if it's the only mon on red and it's switched out/fainted.

Script is designed for v20, old version was a set of instructions for v18/v19. (It was buggy, though)

Code
Paste as a new script section above main or download as a plugin for v20 here.
Ruby:
Expand Collapse Copy
module Settings
  LOW_HP_BGM = "Bicycle"
end

class Game_Temp
  attr_accessor :battle_theme
end

class Battle::Scene::PokemonDataBox < Sprite

  def visible=(value)
    super
    @sprites.each do |i|
      i[1].visible = value if !i[1].disposed?
    end
    @expBar.visible = (value && @showExp)
    if value == true && ((@battler.index%2)==0)
      if @battler.hp<=@battler.totalhp/4
        if $game_system.playing_bgm.name!=Settings::LOW_HP_BGM
          $game_temp.battle_theme = $game_system.playing_bgm.name
          pbBGMPlay(Settings::LOW_HP_BGM)
        end
      else
        low = 0
        @battler.battle.battlers.each_with_index do |b,i|
          next if !b || (b.index%2)==1
          low +=1 if b.hp<b.totalhp/4
        end
        pbBGMPlay($game_temp.battle_theme) if low == 0 && $game_system.playing_bgm.name==Settings::LOW_HP_BGM       
      end
    end
  end
 

  alias oldupdateHPAnimation updateHPAnimation
  def updateHPAnimation
    oldupdateHPAnimation
    return if !@animatingHP
    if ((@battler.index%2)==0)
      if @battler.hp<=@battler.totalhp/4 && @battler.hp>0
        if $game_system.playing_bgm.name!=Settings::LOW_HP_BGM
          $game_temp.battle_theme = $game_system.playing_bgm.name
          pbBGMPlay(Settings::LOW_HP_BGM)
        end
      elsif $game_system.playing_bgm.name==Settings::LOW_HP_BGM
        low = 0
        @battler.battle.battlers.each_with_index do |b,i|
          next if !b || (b.index%2)==1
          low +=1 if b.hp<b.totalhp/4
        end
        pbBGMPlay($game_temp.battle_theme) if low == 0 && $game_system.playing_bgm.name==Settings::LOW_HP_BGM       
      end
    end
  end
 
end

class Battle::Battler

  alias old_pbFaint pbFaint
  def pbFaint(showMessage = true)
    old_pbFaint
    low = 0
    @battle.battlers.each_with_index do |b,i|
      next if !b || (b.index%2)==1
      low +=1 if b.hp<b.totalhp/4 && b.hp > 0
    end
    pbBGMPlay($game_temp.battle_theme) if low == 0 && $game_system.playing_bgm.name==Settings::LOW_HP_BGM
  end
 
end
Change the value LOW_HP_BGM to the name of whatever BGM you want to use. (In quotes, file type shouldn't matter.)


In PokeBattle_SceneElements, find this line:
Ruby:
Expand Collapse Copy
    @expBar.visible = (value && @showExp)

Below it, add-
Ruby:
Expand Collapse Copy
    if value == true && ((@battler.index%2)==0)
      if @battler.hp<=@battler.totalhp/4
        if $game_system.playing_bgm.name!="begin"
          $game_system.bgm_memorize
          pbBGMPlay("begin")
        end
      else
        healthy = 0
        playerteam = 0
        @battler.battle.battlers.each_with_index do |b,i|
        next if !b
          if ((b.index%2)==0)
            playerteam += 1
            healthy +=1 if b.hp>b.totalhp/4
          end
        end
        if playerteam == healthy && $game_system.playing_bgm.name=="begin"
          $game_system.bgm_restore
        end
      end
    end


Below that, find:
Ruby:
Expand Collapse Copy
    @animatingHP = false if @currentHP==@endHP

Below it, add-

Ruby:
Expand Collapse Copy
    if @currentHP==@endHP && ((@battler.index%2)==0)
      if @battler.hp<=@battler.totalhp/4 && @battler.hp>0
        if $game_system.playing_bgm.name!="begin"
          $game_system.bgm_memorize
          pbBGMPlay("begin")
        end
      else
        if $game_system.playing_bgm.name=="begin"
          healthy = 0
          playerteam = 0
          @battler.battle.battlers.each_with_index do |b,i|
          next if !b
            if ((b.index%2)==0)
              playerteam += 1
              healthy +=1 if b.hp>b.totalhp/4
            end
          end
          if playerteam == healthy
            $game_system.bgm_restore
          end
        end
      end
    end

Change every instance of "begin" to the filename of the BGM you want. (You can run a replace all with Ctrl H, it won't affect anything else in this section)


Finally, in Battler_ChangeSelf, find this line-
Ruby:
Expand Collapse Copy
    # Reset form

And paste this right above it. (Or you could do it below, but it's just more organized this way)

Ruby:
Expand Collapse Copy
    healthy = 0
    playerteam = 0
    @battle.battlers.each_with_index do |b,i|
    next if !b
      if ((b.index%2)==0)
        playerteam += 1
        healthy +=1 if b.hp>b.totalhp/4 or b.hp == 0
      end
    end
    if playerteam == healthy
      $game_system.bgm_restore #if $game_system.playing_bgm.name=="begin"
    end
Like before, change "begin" to your filename.

Notes​

Please note that this only remembers the file being played, not the part of the music that it was at. Boonzeet's BGM Memory could help if you wanted to do something like that, but I believe there's currently some compatibility issues with it in v19.

In v19/v18, it's just saved as memorized_bgm, so you'll likely run into troubles if you use something else to switch music in the middle of battle, like Golisopod User's Mid Battle Dialogue/Scripted Battles or Vendily's Evolve During Battle. In v20, it's now saved to the value $game_temp.battle_theme, so this should avoid any issues, but you may want to refer back to that value for any custom scripting you add.

This doesn't check specific index numbers, just if the Pokémon is on the player's side, so it should be compatible with PartyPlus as well, but this hasn't been playtested.

To Do List​

I was having some weird troubles aliasing old methods for the databox, I might give that another go and clean the code up a bit.
Credits
Credit to TechSkylander1518, please!
Thanks to BUFF UI GOKU for requesting this!
Author
TechSkylander1518
Views
4,423
First release
Last update

Ratings

4.00 star(s) 2 ratings

More resources from TechSkylander1518

Latest updates

  1. v20 Update

    v20 update and some much-needed fixes! Script is now plug-and-play, old music is stored...

Latest reviews

From now on when I fight a trainer with more than one Pokémon, when he shows the second Pokémon the default trainer BGM changes to the wild Pokémon BGM.

Is the Low Hp BGM script related?
It was working, until it glitched and made me unable to do anything.
TechSkylander1518
TechSkylander1518
“It glitched” doesn’t really identify the problem- can you share any error messages or anything?
Back
Top