- Pokémon Essentials Version
- v18.1 ➖
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 v19 please use this script: Change Map BGMs (v19)
Please comment any bugs I can fix or improvements I could make.
If you are using Essentials v19 please use this script: Change Map BGMs (v19)
- Make a new script section somewhere above [[ Compiler ]]. Copy this script from the Code section below and paste it in the new script section.
- 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.
["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.
Script Code:
#------------------------------------------------------------------------------
#Change BGMs script by aiyinsi
#Version: 1.0
#------------------------------------------------------------------------------
#
#This script allows you to change the bgm that is played naturaly on maps.
#
#------------------------------------------------------------------------------
#SETUP INSTRUCTIONS:
#
# 1. Make a new script section somewhere above [[ Compiler ]] and paste this
# script in there
# 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 = [
]
#------------------------------------------------------------------------------
######DON'T TOUCH ANYTHING BELOW HERE 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.%s",map_id,($RPGVX) ? "rvdata" : "rxdata"))
@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.starts_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 pbGetMetadata(map_id,MetadataOutdoor)
change_bgm = true
end
#play on indoor maps
elsif entry[2] == "indoor"
if !pbGetMetadata(map_id,MetadataOutdoor)
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 happened after a Discord disussion with DerxwnaKapsyla. He also did some code.
most of this code is based of
"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
SoundSpawn
Jacob O. Wobbrock
the__end
KitsuneKouta
Venom12
Lisa Anthony
Wachunga
Luka S.J.
and everyone else who helped out