• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Trainer Intro: Looping BGM instead of ME

Trainer Intro: Looping BGM instead of ME 1.0

Pokémon Essentials Version
v17.2 ➖
Pokemon Essentials is incredible, but one of the pain points for me was not being able to loop the Trainer Spotted themes. When I started using FMod for my project, the difference in functionality became noticeable.

This script memorises the current playing BGM, plays the Trainer spotted theme and uses the battle scripts to restore the theme back before launching the battle scene.

Ruby:
#===============================================================================
# Trainer Intro as BGM by Boonzeet
#===============================================================================

class Game_System
  def bgm_memorized?
    return defined?(@memorized_bgm) && @memorized_bgm != nil
  end

  def bgm_clearmemory
    @memorized_bgm = nil
  end
end

def pbPlayTrainerIntroME(trainertype)
  pbRgssOpen("Data/trainertypes.dat","rb"){|f|
     trainertypes = Marshal.load(f)
     if trainertypes[trainertype]
       bgm = trainertypes[trainertype][6]
       if bgm && bgm!=""
         bgm = pbStringToAudioFile(bgm)
         $game_system.bgm_memorize
         pbBGMPlay(bgm)
         return
       end
     end
  }
end

alias :pbTrainerBattleold :pbTrainerBattle
def pbTrainerBattle(trainerid,trainername,endspeech,
                    doublebattle=false,trainerparty=0,canlose=false,variable=nil)
  if $game_system.bgm_memorized?
    $game_system.bgm_restore
    $game_system.bgm_clearmemory
  end
  pbTrainerBattleold(trainerid,trainername,endspeech,
                    doublebattle,trainerparty,canlose,variable)
end

alias pbDoubleTrainerBattleold :pbDoubleTrainerBattle
def pbDoubleTrainerBattle
  if $game_system.bgm_memorized?
    $game_system.bgm_restore
    $game_system.bgm_clearmemory
  end
  pbDoubleTrainerBattleold(trainerid1, trainername1, trainerparty1, endspeech1,
                          trainerid2, trainername2, trainerparty2, endspeech2,
                          canlose,variable)
end

If using another script which uses bgm_memorize and using a trainer battle does not use the pbTrainerIntro command, it might restore an old bgm. To counteract this, add a script tag with $game_system.bgm_clearmemory in the event before the battle call.

I am new to RGSS and Essentials development, and this is my first script! I'm sure there is much I can improve on so please let me know :)
Credits
Please credit Boonzeet if used
Author
boonzeet
Views
1,837
First release
Last update
Rating
4.00 star(s) 1 ratings

More resources from boonzeet

Latest reviews

Awesome, only problem is that there was a glitch that played the old music for a second
Back
Top