- Pokémon Essentials Version
- v20.1 ➖
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
Ruby:
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
In PokeBattle_SceneElements, find this line:
Below it, add-
Below that, find:
Below it, add-
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-
And paste this right above it. (Or you could do it below, but it's just more organized this way)
Like before, change "begin" to your filename.
Ruby:
@expBar.visible = (value && @showExp)
Below it, add-
Ruby:
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:
@animatingHP = false if @currentHP==@endHP
Below it, add-
Ruby:
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:
# Reset form
And paste this right above it. (Or you could do it below, but it's just more organized this way)
Ruby:
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
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!