• 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.
Resource icon

Change Map BGMs (v19) 1.0

Pokémon Essentials Version
v19 ➖
This script allows you to change the bgm that is played naturaly on maps.

Please comment any bugs I can fix or improvements I could make.

If you are using Essentials Version 18.1 please use this script: Change Map BGMs (v18.1)

  • Download and unzip the plugin into your Plugins folder.
  • Open Plugins/Change BGMs/Settings.rb
  • Alter the REPLACE_BGMS Array to what you need. The structure is the following:
    • Each Entry represents one BGM that can replace the usual bgm on maps under certain conditions
    • Each Entry is made up out of 5 elements. The last 3 being optional. [identifier, bgm_name, map_selector, volume, pitch] Leaving out optiona elements will treat those as nil.
      If multiple Entries are activated and meet the playing conditions the higher one in the list will be prioritised
      • identifier: The key that you are going to use to turn that bgm on or off.
      • bgm_name: The name of the BGM file in Audio/BGM.
      • map_selector: Used to tell the script on what maps the bgm is supposed to play. The following filters are possible:
        • An Array of Integers. The BGM will be played on the maps with those IDs. It still needs to in an array even if it is only a single map id. For Example: [1,2,3] or [61]
        • "indoor" or "outdoor" will play the bgms either on all indoor or outdoor maps.
        • nil will make the bgm play on all maps.
      • volume: sets the volume to the given number. Sets it to the maps native volume if nil.
      • pitch: sets the pitch to the given number. Sets it to the maps native pitch if nil.
  • Call playSpecialBGM(identifier) to activate the BGM being played under the conditions set in REPLACE_BGMS. If the bgm on the map the player is on meets the conditions set in REPLACE_BGMS the bgm will change to the new one.
  • Call deactivateSpecialBGM(identifier) to deactivate the BGM being played under the conditions set in REPLACE_BGMS. If the bgm on the map the player is on meets the conditions set in REPLACE_BGMS the bgm will change to the new one.

REPLACE_BGMS = [
["Pitched", "Battle Elite", [3, 8, 5], 95, 200],
["Quiet", "Battle Elite", "outdoor" , 50],
["Loud", "Battle Elite", nil , 80],
["Best Song", "Poke Mart"]
]

To activate the Poke Mart music playing on all maps you'd need to call playSpecialBGM("Best Song") in an event or script.
To turn it off again you call deactivateSpecialBGM("Best Song")

If you call playSpecialBGM("Loud") the Battle Elite bgm will start playing on all maps. Calling playSpecialBGM("Quiet") will overwrite the "Loud" bgm because it is higher up on the REPLACE_BGMS array. Therefore the Battle Elite theme will play with 50 volume outdoors and with 80 volume indoors.

If you don't feel like using the plugin feature you can also copy the following code and paste it into a new script section above compiler.
Change BGMs:
Expand Collapse Copy
#------------------------------------------------------------------------------
#Change BGMs script by aiyinsi
#Version: 1.0
#For Essentials V19
#------------------------------------------------------------------------------
####################################SETTINGS###################################
#------------------------------------------------------------------------------
#
#This script allows you to change the bgm that is played naturaly on maps.
#
#------------------------------------------------------------------------------
#SETUP INSTRUCTIONS:
#
# 1. Paste this script into a new script section somewhere above Compiler.
# 2. Alter the REPLACE_BGMS Array to what you need. The structure is the following:
#    -Each Entry represents one BGM that can replace the usual bgm on maps under
#     certain conditions
#    -Each Entry is made up out of 5 elements. The last 3 being optional.
#     [identifier, bgm_name, map_selector, volume, pitch] Leaving out optional
#     elements will treat those as nil.
#       -identifier: The key that you are going to use to turn that bgm on or off.
#       -bgm_name: The name of the BGM file in Audio/BGM.
#       -map_selector: Used to tell the script on what maps the bgm is supposed
#        to play. The following filters are possible:
#         -An Array of Integers. The BGM will be played on the maps with those
#          IDs. It still needs to in an array even if it is only a single map id.
#          For Example: [1,2,3] or [69]
#         -"indoor" or "outdoor" will play the bgms either on all indoor or
#          outdoor maps.
#         -nil will make the bgm play on all maps.
#       -volume: sets the volume to the given number. Sets it to the maps native
#        volume if nil.
#       -pitch: sets the pitch to the given number. Sets it to the maps native
#        pitch if nil.
#     If multiple Entries are activated the higher one in the list will be
#     prioritised.
# 3. Call playSpecialBGM(identifier) to activate the BGM being played under the
#    conditions set in REPLACE_BGMS. If the bgm on the map the player is on
#    meets the conditions set in REPLACE_BGMS the bgm will change to the new one.
# 4. Call deactivateSpecialBGM(identifier) to deactivate the BGM being played
#    under the conditions set in REPLACE_BGMS. If the bgm on the map the player
#    is on meets the conditions set in REPLACE_BGMS the bgm will change to the
#    new one.
#
#
#------------------------------------------------------------------------------
#EXAMPLE:
#REPLACE_BGMS = [
#                 ["Pitched", "Battle Elite", [3, 8, 5], 95, 200],
#                 ["Quiet", "Battle Elite", "outdoor" , 50],
#                 ["Loud", "Battle Elite", nil , 80],
#                 ["Best Song", "Poke Mart"]
#               ]
#
#To activate the Poke Mart music playing on all maps you'd need to call
#playSpecialBGM("Best Song") in an event or script.
#To turn it off again you call deactivateSpecialBGM("Best Song")
#
#If you call playSpecialBGM("Loud") the Battle Elite bgm will start playing on
#all maps. Calling playSpecialBGM("Quiet") will overwrite the "Loud" bgm
#because it is higher up on the REPLACE_BGMS array. Therefore the Battle Elite
#theme will play with 50 volume outdoors and with 80 volume indoors.
#
#------------------------------------------------------------------------------
#EDIT THIS ARRAY:
REPLACE_BGMS = [
                ["Quiet", "Battle Elite", "outdoor" , 50]
               ]
#------------------------------------------------------------------------------
#########DO NOT TOUCH ANYTHING BELOW IF YOU DON'T KNOW WHAT YOU'RE DOING#######
#------------------------------------------------------------------------------

#This method resets the special bgm that is bound to the given key to the normally playing one.
#If the player is on a map that is affected by this the bgm changes.
def deactivateSpecialBGM(identifier)
  #the save array doesn't exist and terefore all BGMs are normal
  if !$PokemonGlobal.bgm_state_array
    return
  end

  #turn of the given switch
  $PokemonGlobal.bgm_state_array[identifier] = false

  #update the maps on their bgms
  if $MapFactory
    $MapFactory.update_bgms
  end

  #if a new bgm is set for the current map, switch to that one
  $game_map.play_current_bgm
end


#This method activates the special bgm that is bound to the given key.
#If the player is on a map that is affected by this the bgm changes.
def playSpecialBGM(identifier)
  #if this is the first time a special bgm is used set up the hash
  if !$PokemonGlobal.bgm_state_array
    $PokemonGlobal.setup_bgm_state_array
  end

  #turn on the given switch
  $PokemonGlobal.bgm_state_array[identifier] = true
  #update the maps on their bgms
  if $MapFactory
    $MapFactory.update_bgms
  end

  #if a new bgm is set for the current map, switch to that one
  $game_map.play_current_bgm
end

class PokemonGlobalMetadata

  attr_accessor :bgm_state_array    #saves which special bgms are played

  #initializes all the keys with false
  def setup_bgm_state_array
    @bgm_state_array = {}
    REPLACE_BGMS.each{ |entry|
      @bgm_state_array.store(entry[0], false)
    }
  end
end

class Game_Map

  #update the bgm to what it should be rn (I tinkered with load_data)
  def update_bgm
    temp = load_data(sprintf("Data/Map%03d.rxdata",map_id))
    @map.bgm = temp.bgm
  end

  #if the bgm playing rn is different than the maps bgm, switch to the maps bgm
  def play_current_bgm
    bgm = $game_system.playing_bgm
    if (!bgm || bgm.name != @map.bgm.name || bgm.name != @map.bgm.volume || bgm.name != @map.bgm.pitch)
      pbCueBGM(@map.bgm.name,1.0,@map.bgm.volume,@map.bgm.pitch)
    end
  end
end

class PokemonMapFactory
  #calls update_bgm for each map that is loaded to make sure map transition bgms work
  def update_bgms
    @maps.each{ |map| map.update_bgm}
  end
end


#yeah sorry for changing the method here :D you're getting what I want, not
#what your gamefiles say
alias load_data_old_aiyinsi load_data
def load_data(file)
  ret = load_data_old_aiyinsi(file)
  if file.start_with?("Data/Map") && $PokemonGlobal && $PokemonGlobal.bgm_state_array && ret.respond_to?('bgm')
    map_id = file[8..file.length-1].to_i
    #iterate through REPLACE_BGMS and see if a switch is set to "On"
    REPLACE_BGMS.each{ |entry|
      if $PokemonGlobal.bgm_state_array[entry[0]]
        change_bgm = false
        #no map filter was given: always change bgm
        if !entry[2]
          change_bgm = true
        #a list of map IDs was given: check whether it contains the
        elsif entry[2].kind_of?(Array)
          if entry[2].include?(map_id)
            change_bgm = true
          end
        #play on outdoor maps
        elsif entry[2] == "outdoor"
          if GameData::MapMetadata.get($game_map.map_id).outdoor_map
            change_bgm = true
          end
        #play on indoor maps
        elsif entry[2] == "indoor"
          if !GameData::MapMetadata.get($game_map.map_id).outdoor_map
            change_bgm = true
          end
        end
        #if the bgm should be changed:
        if change_bgm
          #name
          ret.bgm.name = entry[1]
          #volume
          if entry[3]
            ret.bgm.volume = entry[3]
          end
          #pitch
          if entry[4]
            ret.bgm.pitch = entry[4]
          end
          break
          #break out of looping through REPLACE_BGMS loop
        end
      end
    } #end of each loop
  end
  return ret
end
Credits
Creator: aiyinsi
This script happened after a discussion with DerxwnaKapsyla and altering some of his code

Plugin Manager
by Marin
support for external plugin scripts by Luka S.J
tweaked by Maruno

This script is made for and uses some tweaked code from Pokémon Essentials:
"Pokémon Essentials" was created by:
Flameguru
Poccil (Peter O.)
Maruno

With contributions from:
AvatarMonkeyKirby
Marin
Boushy
MiDas Mike
Brother1440
Near Fantastica
FL.
PinkMan
Genzai Kawakami
Popper
help-14
Rataime
IceGod64
Savordez
Jacob O. Wobbrock
SoundSpawn
KitsuneKouta
the__end
Lisa Anthony
Venom12
Luka S.J.
Wachunga
and everyone else who helped out
Author
aiyinsi
Downloads
513
Views
1,616
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from aiyinsi

Back
Top