• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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.

Switching between two overworld BGMs

226
Posts
8
Years
    • Seen Jul 19, 2023
    Hello,

    I am facing an annoying "detail" I cannot manage to fix.
    Let's say I am on Map 1 and a background music, BGM1, is playing.

    Now, when a global switch is turned on, BGM2 should be playing instead of BGM1.

    Forcing the game to play BGM2 is easy since you have a direct command for that, but you cannot actually replace the Map BGM directly. So when a battle ends, or if the player saves the game, leaves and comes back, he will heard BGM1 again.

    Using a parallel process event to force the game to play BGM2 is not great because it will play BGM2 during battles as well.
    I thought about an autorun, but I cannot figure out exactly how I should trigger it.

    Anyone already solved a similar problem in their own games? Thanks.
     
    Last edited:

    Telemetius

    Tele*
    267
    Posts
    9
    Years
  • Try using this script call to override the default BGM: $game_system.setDefaultBGM("yourBGM")

    Thenwhen you'll be getting out of the map you could use:
    $game_system.setDefaultBGM("nil")

    I haven't tested it though.
     
    226
    Posts
    8
    Years
    • Seen Jul 19, 2023
    Try using this script call to override the default BGM: $game_system.setDefaultBGM("yourBGM")

    With this method, BGM2 indeed replaces BGM1.

    If you quit and load the game, BGM2 will play instead of BGM1, which is nice.

    However, if you encounter a wild Pokemon, BGM2 will keep playing instead of the battle music.

    So it's not exactly working.
     
    226
    Posts
    8
    Years
    • Seen Jul 19, 2023
    So I found the part in the scripts playing the background music.
    I noticed there was a way to use a different BGM at night.
    So I tried to copy this method to use a different BGM when a global switch is on.
    For some reason, it doesn't work though (the music doesn't play)... Any advice?

    def autoplayAsCue
    if @map.autoplay_bgm
    if $game_switches[63]=true &&
    FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "z")
    pbCueBGM(@map.bgm.name+"z",1.0,@map.bgm.volume,@map.bgm.pitch)
    else
    pbCueBGM(@map.bgm,1.0)
    end

    if PBDayNight.isNight?(pbGetTimeNow) &&
    FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
    pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
    else
    pbCueBGM(@map.bgm,1.0)
    end
    end
    if @map.autoplay_bgs
    pbBGSPlay(@map.bgs)
    end
    end

    I did the same at "def autoplay" and i also adjusted "def autofade (mapid)" in Scene_Map.
     
    119
    Posts
    10
    Years
    • Seen Sep 1, 2023
    @HarmonyConcept:
    Your code doesn't work because when checking for the night BMG you either set it to the regular BMG or the night BMG. You should change it to an elsif (if global switch, elsif night, else)
    Code:
    def autoplayAsCue
        if @map.autoplay_bgm
            if $game_switches[63]==true &&
                  FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "z")
                pbCueBGM(@map.bgm.name+"z",1.0,@map.bgm.volume,@map.bgm.pitch)
            elsif PBDayNight.isNight?(pbGetTimeNow) &&
                  FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
                pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
            else
                pbCueBGM(@map.bgm,1.0)
            end
        end
        if @map.autoplay_bgs
            pbBGSPlay(@map.bgs)
        end
    end

    @OP: Another solution would be to not set a default BGM and use an autorun event to set the correct BGM when entering the map (and erase the event afterwards).

    EDIT: Added the code.
     
    Last edited:

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Note that your code includes the line if $game_switches[63]=true, which doesn't work how you want it to. A single = makes the first thing the same value as the second thing, while == checks whether the first thing is equal to the second thing. You want to use == here.
     
    119
    Posts
    10
    Years
    • Seen Sep 1, 2023
    Woops, missed that one XD (also fixed in the code placed above).
     
    824
    Posts
    8
    Years
  • Would I be able to use this to pull something like ALBW off, and make it so that the Pokemon League's music changes based on how many of the E4 you've defeated?
     
    Back
    Top