• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Trainer Spotted Theme: Use Looping BGM instead of ME

Boonzeet

Pokémon Secrets of the Ages Developer
  • 188
    Posts
    16
    Years
    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.

    Code:
    #===============================================================================
    # 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 :)
     
    Back
    Top