• 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.
  • Apologies if you've had troubles connecting to the site, you may need a VPN to access it. Staff are also facing issues connecting, so if it's urgent please message Cat on-site or through Discord directly.
  • Hey Guest, staff applications are open! If you are interested in becoming a forum staff member and/or Discord staff member, please apply through this Google Form before April 2! You can also message Cat with any questions.
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:
Expand Collapse Copy
#===============================================================================
# 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,973
First release
Last update

Ratings

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