Well I'm using the Mimi's battle music script I got awhile ago, never really used it until now and I think I found a bug. I searched about it but didn't find anything. Anyways when you have it set to play the field music in battle "$game_system.bgm_type = 4" it works great but if you decide to escape the battle, the field music never ends even when you enter onto another map with different music. Even when an event is supposed to change the music as well, the old field music remains and nothing you do changes it. If you win the battle, it works but only seems to bug up when you escape.
I'm just wondering if anyone could tell how to fix this problem if anyone knows.
Script below
[rgss]#==============================================================================
# ** Mimi's Battle Music
#------------------------------------------------------------------------------
# Â Â by DerVVulfman
# Â Â version 4.3-b (Game_System instance version)
# Â Â 05-01-2007
# Â Â Full SDK 2.2 Compatible (Does not need or require SDK 2.2)
#------------------------------------------------------------------------------
#
# Â INTRODUCTION:
#
# Â This system allows you to pre-program the music used during battle. Â You can
#  set up the system to play music based  on the party leader  or by a separate
# Â variable that can describe what kind of event your party is engaging.
#
#  This script was a request by a young friend.  She wanted to  have the music
# Â in her game's battlesystem to play the party leader's "THEME" instead of the
# Â default system's music. Â So I thought... why not?
#
# Â Branching off from her idea, I decided to add the "EVENT" variable. This way
# Â I could tie this system into other systems that use values that keep track
# Â of how far into a game the player has gotten.
# Â IE: Â If a player progresses to 'Act2', then the battlemusic may change...
# Â Â Â $bgm_event = 2
# Â Â Â Then if the player progresses to 'Act3 - the Nightmare....
# Â Â Â $bgm_event = 3
#
#------------------------------------------------------------------------------
#
# Â USAGE:
#
# Â This version uses instance values stored within the $game_system class. Â As
#  such, it has two bonuses:  reduced memory requirements  and a smaller RMXP
# Â script. Â This version is smaller than the one that uses ($)Global values.
#
# Â To perform a script or 'map event' script call, you will be using one or two
# Â of three Game_System instance values: Â bgm_type, bgm_event and bgm_living.
#
#  bgm_type   This value determines  whether the music  you are  using during
# Â Â Â Â Â Â Â combat will be based on the default systems, based on your lead
# Â Â Â Â Â Â Â hero, or based on the current events of your story.
# Â Â Â Â Â Â Â Â 0 = Normal music mode (like always)
#         1 = Hero music mode  (party leader's theme)
#         2 = Event Music mode  (requires $bgm_event to be set)
# Â Â Â Â Â Â Â Â 3 = Random Music mode (relief from monotony)
#         4 = Field Music mode  (off of the map...)
#
#  bgm_event   This value merely determines what music is used IF you're scrip-
# Â Â Â Â Â Â Â ting out your game to play the battle music based on the events
# Â Â Â Â Â Â Â your hero encounters.
#
#        This value is ONLY required to be called  when th e bgm_type is
# Â Â Â Â Â Â Â set to '2' (Event Music mode). Â Most other modes are autonomic.
# Â
#  bgm_living  This value determines if the 'Hero" music mode is based on the
# Â Â Â Â Â Â Â general lead hero of the party, or whether the music is based
# Â Â Â Â Â Â Â on the 'surviving' lead hero instead. Â As such, when this value
# Â Â Â Â Â Â Â is set to true, the music system only considers 'Living' party
# Â Â Â Â Â Â Â members.
#
#        This value is ONLY required to be called  when the  bgm_type is
# Â Â Â Â Â Â Â set to '1' (Hero Music mode). Â Also note that you can change it
# Â Â Â Â Â Â Â from map events by passing 'true' or 'nil values. Â DO NOT PASS
# Â Â Â Â Â Â Â A VALUE OF 'FALSE' AS THAT CAN FREEZE THE GAME (an 'RMXP' bug.)
#
# Â
# Â How to run:
#
# Â In an event... maybe an event like a monster (Action Button/Player Touch) or
#  an automated event... you change the value of  bgm_type (and/or  bgm_event).
#
#  By default  bgm_type is already set at 0, which tells it to play the default
# Â battle music as normal. If you set bgm_type = 1,then when the battle starts,
# Â the lead hero's theme music will play.
#
# Â If you included the 'bgm_living = true' as a call, Â then only the surviving
# Â party members are considered, Â so if the hero in the very first position is
# Â dead, then the lead party member considered will be the very next one... if
# Â he is alive... and so on...
#
# Â If you've changed 'bgm_type = 2' AND changed 'bgm_event = 1', then the first
#  programmed event battle music will play instead of  EITHER  the hero's music
# Â or the default battle music.
#
#------------------------------------------------------------------------------
#
# Â SETTING THE MUSIC:
#
# Â The config system is fairly simple. There are three hash arrays, one for the
# Â Event-Based Battle music, Â the second for Actor-Themed Battle music, and the
# Â third one for random music.
#
# Â All three follow the same setup principle:
# Â
# Â Â $game_system.music_event = { index => [ filename, volume, pitch ], .... }
#
#  The index value in the hash is the value of the  $bgm_event  value called in
# Â the system. Â Fairly simple. Â Now by default, the volume and pitch values are
# Â already set to '100', so you could leave them empty, like: Â 2 => ["Spooky"]
#  would set the second event's battlemusic to use a  "Spooky"  filename preset
# Â to 100 volume and pitch.
#
# Â The values of the volume control can range from 0 to 100,with 100 being the
# Â maximum volume. And the pitch value can range from 50 to 150. Â These values
# Â mimic the volume & pitch control settings built into the RMXP database. One
#  nuance with the pitch setting is that while .mid  music pitch values merely
#  change the pitch alone,  the speed of  digital audio files (mp3, wave, etc)
# Â are altered.
#
# Â The same configuration layout applies to the Actor-Themed array as well and
# Â uses their actorID numbers as index in its hash array.
#
#  You may notice that in this script,  the filenames do not have the  .mid or
# Â .mp3 extension. Â They aren't needed. Â How nice... Â
#
#------------------------------------------------------------------------------
#
# Â JUST IN CASE:
#
# Â By default, Â the music system will play the default battle music without any
#  problem.  You can even change the battle music with the  [Change Battle BMG]
# Â event. Â If you've changed the $bgm_type, don't worry. Â Resetting it back to
# Â zero (0) will allow the [Changed... battle BMG] to play just in case.
#
# Â Finally, Â with a little assistance from Meâ„¢ and Mr.Mo, Â I was able to create
#  an Error-Checking routine that  'ensures'  that no error in this system will
# Â cause the system to crash.
#
# Â For example, if you enter into the list of music used in the system, a piece
# Â that doesn't exist (either in the project or the RTP file), then this script
# Â will use the default battle background music instead. Â And if that's missing
# Â too, the battle music will be set to [none] to prevent errors.
#
#------------------------------------------------------------------------------
#
# Â CREDITS & THANKS
# Â Well... Thanks to Mimi-Chan who gave me the excuse to crank this script out. Â Â
#
#  Also,  thanks goes out to WithViolence  who found  a flaw where  if 'listed'
# Â music didn't exist in either the project's or RTP's music folder, the system
# Â could crash if the music was called. Â Likewise, thanks goes out to Meâ„¢'s and
# Â Mr.Mo's for their assistance in RGSS Support forum in... detecting the music
# Â files in the RTP. And thanks to grimreaper1357 for extensive testing of sys-
# Â tems including random map encounters and self switch conflicts.
#
#==============================================================================
Â
Â
Â
Â
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# Â This class handles data surrounding the system. Backround music, etc.
# Â is managed here as well. Refer to "$game_system" for the instance of
# Â this class.
#==============================================================================
Â
class Game_System
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :default_bgm        # Default BGM filename
 attr_accessor :default_bgmv       # Default BGM volume setting
 attr_accessor :default_bgmp       # Default BGM pitch setting
 attr_accessor :music_event        # Event Music Hash
 attr_accessor :music_actor        # Actor Music Hash
 attr_accessor :music_rand        # Random Music Hash
 attr_accessor :bgm_type         # Music Type
 attr_accessor :bgm_event         # Music Event
 attr_accessor :bgm_living        # Living Hero Boolean (true/nil)
 attr_accessor :mm_notfield        # 'Battle/Field'  on/off switch
 attr_accessor :mm_no_vm         # 'Victory Music' on/off switch
Â
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias mmbgm_init initialize
 def initialize
  # Perform the original call
  mmbgm_init
 Â
 Â
  #========================================================================
  #  **  C  O  N  F  I  G  U  R  A  T  I  O  N    S  Y  S  T  E  M  **  #
  #========================================================================
  # Hash used for event lists:
  @music_event = { 1 => ["026-Town04", 100, 100],
           2 => ["040-Dungeon06"],
           3 => ["053-Negative02"],
           4 => ["026-Town04"] }
  # Hash used for actor lists:
  @music_actor = { 1 => ["026-Town04"],
           2 => ["006-Boss02"],
           3 => ["007-Boss03"],
           4 => ["008-Boss04"],
           5 => ["009-LastBoss01"],
           6 => ["010-LastBoss02"],
           7 => ["011-LastBoss03"],
           8 => ["003-Battle03"] }
  # Hash used for random music:        Â
  @music_rand  = { 1 => ["026-Town04", 100, 100],
           2 => ["040-Dungeon06"] }
          Â
  # Initial values called via script/map events to change battlebacks
  # Initial battle music type ( 0 to 4 )    - Can change from map events -
  @bgm_type   = 0
  # Initial selection of event battlemusic.  - Can change from map events -
  @bgm_event   = 0
  # Initial setting of 'living' party hero.  - Can change from map events -
  @bgm_living  = nil
  # DO NOT TOUCH BELOW:
  # Control switches for automatic 'victory' music system.
  @mm_notfield  = nil
  @mm_no_vm   = nil
 end Â
 #--------------------------------------------------------------------------
 # * Play Background Music
 #   bgm : background music to be played
 #--------------------------------------------------------------------------
 alias mmbgm_play bgm_play
 def bgm_play(bgm)
  if !$game_system.mm_notfield Â
   mmbgm_play(bgm)
  end
 end
 #--------------------------------------------------------------------------
 # * Stop Background Music
 #--------------------------------------------------------------------------
 alias mmbgm_stop bgm_stop
 def bgm_stop
  if !$game_system.mm_notfield Â
   mmbgm_stop
  end
 end
 #--------------------------------------------------------------------------
 # * Play Music Effect
 #   me : music effect to be played
 #--------------------------------------------------------------------------
 alias mmme_play me_play
 def me_play(me)
  if !$game_system.mm_no_vm
   mmme_play(me)
  end
 end
end Â
Â
          Â
          Â
#==============================================================================
# ** Mimi's Music
#------------------------------------------------------------------------------
# Â This module performs routines for choosing the music played during combat.
#==============================================================================
Â
module Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Music Call
 #--------------------------------------------------------------------------  Â
 def call_music
  # Reset the initial value
  mimi_name  = ""
  mimi_volume = 100
  mimi_pitch  = 100
  # Obtain originally set music...
  # Even works if you used the [Change Battle BGM] event command
  $game_system.default_bgm  = $game_system.battle_bgm.name
  $game_system.default_bgmv = $game_system.battle_bgm.volume
  $game_system.default_bgmp = $game_system.battle_bgm.pitch
  # Obtain the ID number of the party leader
  leader_id = $game_party.actors[0].id
  # Obtain the ID number of 'living' party leader
  if $game_system.bgm_living == true
   temp_id = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if temp_id == 0 ; then ; temp_id = actor.id ; end
    end
   end   Â
   leader_id = temp_id
  end
  # Branch based on what type of music we're using.
  case $game_system.bgm_type
  when 0  # Default (normal music settings)
   mimi_name  = $game_system.default_bgm
   mimi_volume = $game_system.default_bgmv
   mimi_pitch  = $game_system.default_bgmp
  when 1  # Hero BGM based
   mimi_name  = $game_system.music_actor[leader_id][0] if $game_system.music_actor.include?(leader_id)
   mimi_volume = $game_system.music_actor[leader_id][1] if $game_system.music_actor.include?(leader_id)
   mimi_pitch  = $game_system.music_actor[leader_id][2] if $game_system.music_actor.include?(leader_id)
  when 2  # Event BGM based
   mimi_name  = $game_system.music_event[$game_system.bgm_event][0] if $game_system.music_event.include?($game_system.bgm_event)
   mimi_volume = $game_system.music_event[$game_system.bgm_event][1] if $game_system.music_event.include?($game_system.bgm_event)
   mimi_pitch  = $game_system.music_event[$game_system.bgm_event][2] if $game_system.music_event.include?($game_system.bgm_event)
  when 3  # Random BGM based
   mimi_rand = (rand($game_system.music_rand.size)) + 1
   mimi_name  = $game_system.music_rand[mimi_rand][0] if $game_system.music_rand.include?(mimi_rand)
   mimi_volume = $game_system.music_rand[mimi_rand][1] if $game_system.music_rand.include?(mimi_rand)
   mimi_pitch  = $game_system.music_rand[mimi_rand][2] if $game_system.music_rand.include?(mimi_rand)
  when 4  # Field BGM based
   $game_system.mm_notfield = true
  end
  # Only perform if NOT field music
  if $game_system.bgm_type != 4
   #Audio Vol/Pitch error prevention
   mimi_volume = 100 if mimi_volume == nil
   mimi_pitch  = 100 if mimi_pitch  == nil
   if mimi_volume >  100 ; mimi_volume = 100 ; end
   if mimi_volume < 0 ;   mimi_volume = 0  ; end
   if mimi_pitch >  150 ;  mimi_volume = 150 ; end
   if mimi_pitch < 50 ;   mimi_volume = 50  ; end    Â
   # Apply changes
   $game_system.battle_bgm.name  = mimi_name
   $game_system.battle_bgm.volume = mimi_volume
   $game_system.battle_bgm.pitch  = mimi_pitch
   # Error checking.  Makes sure that what is chosen is a valid music file.
   # If not, then the system restores the default music file in it's place.
   begin
    @trd = RPG::AudioFile.new($game_system.battle_bgm.name)
     Audio.bgm_play("Audio/BGM/" + @trd.name,0,100)
     # Sound file is true
   rescue Errno::ENOENT
    # Sound file is invalid (restore default)
    $game_system.battle_bgm.name  = $game_system.default_bgm
    $game_system.battle_bgm.volume = $game_system.default_bgmv
    $game_system.battle_bgm.pitch  = $game_system.default_bgmp
   end
   # Error checking.  Makes sure that even the default music file is available.
   # If it is missing, then the system will set the battle music to >none<.
   begin
    @trd = RPG::AudioFile.new($game_system.battle_bgm.name)
    Audio.bgm_play("Audio/BGM/" + @trd.name,0,100)
    # Sound file is true
   rescue Errno::ENOENT
    # Sound file is invalid (restore default)
    $game_system.battle_bgm.name = ""
   end
  end
 end
end
Â
Â
Â
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# Â This class performs map screen processing.
#==============================================================================
Â
class Scene_Map
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Call
 #-------------------------------------------------------------------------- Â
 alias musical_call_battle call_battle
 def call_battle
  # The Included module (Battle Music Call)
  call_music
  # Now, perform the ORIGINAL Battle Call
  musical_call_battle
 end
end
Â
Â
Â
#==============================================================================
# ** Interpreter (part 6)
#------------------------------------------------------------------------------
# Â This interpreter runs event commands. This class is used within the
# Â Game_System class and the Game_Event class.
#==============================================================================
Â
class Interpreter
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Processing
 #--------------------------------------------------------------------------
 alias musical_command_301 command_301
 def command_301
  # The Included module (Battle Music Call)
  call_music
  # Now, perform the ORIGINAL battle call
  musical_command_301
 end
end
Â
Â
Â
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# Â This class performs battle screen processing.
#==============================================================================
Â
class Scene_Battle
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 alias musical_main main
 def main
  if $game_system.bgm_living == true
   # Obtain hero for theme system
   @main_hero = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if @main_hero == 0 ; then ; @main_hero = actor.id ; end
    end
   end
  end
  # Perform the 'main' battle routine
  musical_main
  # After the whole battle routine finishes, switch the music back.
  $game_system.battle_bgm.name = $game_system.default_bgm
  $game_map.autoplay
 end
Â
 #--------------------------------------------------------------------------
 # * Start After Battle Phase
 #--------------------------------------------------------------------------
 alias mm_sp5 start_phase5
 def start_phase5
  # Only perform if field music
  if $game_system.bgm_type == 4
   #Set the Victory Music's NoSE flag to true (turns off Victory Music)
   $game_system.mm_no_vm = true
  end
  # Perform the original call
  mm_sp5
  $game_system.mm_notfield = nil
  # Reset the Victory Music's NoSE flag
  $game_system.mm_no_vm = nil
 end
 #--------------------------------------------------------------------------
 # * Frame Update (main phase step 6 : refresh)
 #--------------------------------------------------------------------------
 alias mm_up4s6 update_phase4_step6
 def update_phase4_step6(battler = @active_battler)
  # Perform the original call
  @rtab = !@target_battlers
  @rtab ? mm_up4s6(battler) : mm_up4s6
  if $game_system.bgm_living == true
   # Obtain the currently serviving party hero
   temp_hero = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if temp_hero == 0 ; then ; temp_hero = actor.id ; end
    end
   end
   # If the primary hero died
   if temp_hero != @main_hero
    # Call the battle music
    call_music
    # Play battle BGM
    $game_system.bgm_play($game_system.battle_bgm)   Â
    # Set the current hero for checking
    @main_hero = temp_hero
   end
  end
 end  Â
end
[/rgss]
I'm just wondering if anyone could tell how to fix this problem if anyone knows.
Script below
[rgss]#==============================================================================
# ** Mimi's Battle Music
#------------------------------------------------------------------------------
# Â Â by DerVVulfman
# Â Â version 4.3-b (Game_System instance version)
# Â Â 05-01-2007
# Â Â Full SDK 2.2 Compatible (Does not need or require SDK 2.2)
#------------------------------------------------------------------------------
#
# Â INTRODUCTION:
#
# Â This system allows you to pre-program the music used during battle. Â You can
#  set up the system to play music based  on the party leader  or by a separate
# Â variable that can describe what kind of event your party is engaging.
#
#  This script was a request by a young friend.  She wanted to  have the music
# Â in her game's battlesystem to play the party leader's "THEME" instead of the
# Â default system's music. Â So I thought... why not?
#
# Â Branching off from her idea, I decided to add the "EVENT" variable. This way
# Â I could tie this system into other systems that use values that keep track
# Â of how far into a game the player has gotten.
# Â IE: Â If a player progresses to 'Act2', then the battlemusic may change...
# Â Â Â $bgm_event = 2
# Â Â Â Then if the player progresses to 'Act3 - the Nightmare....
# Â Â Â $bgm_event = 3
#
#------------------------------------------------------------------------------
#
# Â USAGE:
#
# Â This version uses instance values stored within the $game_system class. Â As
#  such, it has two bonuses:  reduced memory requirements  and a smaller RMXP
# Â script. Â This version is smaller than the one that uses ($)Global values.
#
# Â To perform a script or 'map event' script call, you will be using one or two
# Â of three Game_System instance values: Â bgm_type, bgm_event and bgm_living.
#
#  bgm_type   This value determines  whether the music  you are  using during
# Â Â Â Â Â Â Â combat will be based on the default systems, based on your lead
# Â Â Â Â Â Â Â hero, or based on the current events of your story.
# Â Â Â Â Â Â Â Â 0 = Normal music mode (like always)
#         1 = Hero music mode  (party leader's theme)
#         2 = Event Music mode  (requires $bgm_event to be set)
# Â Â Â Â Â Â Â Â 3 = Random Music mode (relief from monotony)
#         4 = Field Music mode  (off of the map...)
#
#  bgm_event   This value merely determines what music is used IF you're scrip-
# Â Â Â Â Â Â Â ting out your game to play the battle music based on the events
# Â Â Â Â Â Â Â your hero encounters.
#
#        This value is ONLY required to be called  when th e bgm_type is
# Â Â Â Â Â Â Â set to '2' (Event Music mode). Â Most other modes are autonomic.
# Â
#  bgm_living  This value determines if the 'Hero" music mode is based on the
# Â Â Â Â Â Â Â general lead hero of the party, or whether the music is based
# Â Â Â Â Â Â Â on the 'surviving' lead hero instead. Â As such, when this value
# Â Â Â Â Â Â Â is set to true, the music system only considers 'Living' party
# Â Â Â Â Â Â Â members.
#
#        This value is ONLY required to be called  when the  bgm_type is
# Â Â Â Â Â Â Â set to '1' (Hero Music mode). Â Also note that you can change it
# Â Â Â Â Â Â Â from map events by passing 'true' or 'nil values. Â DO NOT PASS
# Â Â Â Â Â Â Â A VALUE OF 'FALSE' AS THAT CAN FREEZE THE GAME (an 'RMXP' bug.)
#
# Â
# Â How to run:
#
# Â In an event... maybe an event like a monster (Action Button/Player Touch) or
#  an automated event... you change the value of  bgm_type (and/or  bgm_event).
#
#  By default  bgm_type is already set at 0, which tells it to play the default
# Â battle music as normal. If you set bgm_type = 1,then when the battle starts,
# Â the lead hero's theme music will play.
#
# Â If you included the 'bgm_living = true' as a call, Â then only the surviving
# Â party members are considered, Â so if the hero in the very first position is
# Â dead, then the lead party member considered will be the very next one... if
# Â he is alive... and so on...
#
# Â If you've changed 'bgm_type = 2' AND changed 'bgm_event = 1', then the first
#  programmed event battle music will play instead of  EITHER  the hero's music
# Â or the default battle music.
#
#------------------------------------------------------------------------------
#
# Â SETTING THE MUSIC:
#
# Â The config system is fairly simple. There are three hash arrays, one for the
# Â Event-Based Battle music, Â the second for Actor-Themed Battle music, and the
# Â third one for random music.
#
# Â All three follow the same setup principle:
# Â
# Â Â $game_system.music_event = { index => [ filename, volume, pitch ], .... }
#
#  The index value in the hash is the value of the  $bgm_event  value called in
# Â the system. Â Fairly simple. Â Now by default, the volume and pitch values are
# Â already set to '100', so you could leave them empty, like: Â 2 => ["Spooky"]
#  would set the second event's battlemusic to use a  "Spooky"  filename preset
# Â to 100 volume and pitch.
#
# Â The values of the volume control can range from 0 to 100,with 100 being the
# Â maximum volume. And the pitch value can range from 50 to 150. Â These values
# Â mimic the volume & pitch control settings built into the RMXP database. One
#  nuance with the pitch setting is that while .mid  music pitch values merely
#  change the pitch alone,  the speed of  digital audio files (mp3, wave, etc)
# Â are altered.
#
# Â The same configuration layout applies to the Actor-Themed array as well and
# Â uses their actorID numbers as index in its hash array.
#
#  You may notice that in this script,  the filenames do not have the  .mid or
# Â .mp3 extension. Â They aren't needed. Â How nice... Â
#
#------------------------------------------------------------------------------
#
# Â JUST IN CASE:
#
# Â By default, Â the music system will play the default battle music without any
#  problem.  You can even change the battle music with the  [Change Battle BMG]
# Â event. Â If you've changed the $bgm_type, don't worry. Â Resetting it back to
# Â zero (0) will allow the [Changed... battle BMG] to play just in case.
#
# Â Finally, Â with a little assistance from Meâ„¢ and Mr.Mo, Â I was able to create
#  an Error-Checking routine that  'ensures'  that no error in this system will
# Â cause the system to crash.
#
# Â For example, if you enter into the list of music used in the system, a piece
# Â that doesn't exist (either in the project or the RTP file), then this script
# Â will use the default battle background music instead. Â And if that's missing
# Â too, the battle music will be set to [none] to prevent errors.
#
#------------------------------------------------------------------------------
#
# Â CREDITS & THANKS
# Â Well... Thanks to Mimi-Chan who gave me the excuse to crank this script out. Â Â
#
#  Also,  thanks goes out to WithViolence  who found  a flaw where  if 'listed'
# Â music didn't exist in either the project's or RTP's music folder, the system
# Â could crash if the music was called. Â Likewise, thanks goes out to Meâ„¢'s and
# Â Mr.Mo's for their assistance in RGSS Support forum in... detecting the music
# Â files in the RTP. And thanks to grimreaper1357 for extensive testing of sys-
# Â tems including random map encounters and self switch conflicts.
#
#==============================================================================
Â
Â
Â
Â
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# Â This class handles data surrounding the system. Backround music, etc.
# Â is managed here as well. Refer to "$game_system" for the instance of
# Â this class.
#==============================================================================
Â
class Game_System
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_accessor :default_bgm        # Default BGM filename
 attr_accessor :default_bgmv       # Default BGM volume setting
 attr_accessor :default_bgmp       # Default BGM pitch setting
 attr_accessor :music_event        # Event Music Hash
 attr_accessor :music_actor        # Actor Music Hash
 attr_accessor :music_rand        # Random Music Hash
 attr_accessor :bgm_type         # Music Type
 attr_accessor :bgm_event         # Music Event
 attr_accessor :bgm_living        # Living Hero Boolean (true/nil)
 attr_accessor :mm_notfield        # 'Battle/Field'  on/off switch
 attr_accessor :mm_no_vm         # 'Victory Music' on/off switch
Â
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias mmbgm_init initialize
 def initialize
  # Perform the original call
  mmbgm_init
 Â
 Â
  #========================================================================
  #  **  C  O  N  F  I  G  U  R  A  T  I  O  N    S  Y  S  T  E  M  **  #
  #========================================================================
  # Hash used for event lists:
  @music_event = { 1 => ["026-Town04", 100, 100],
           2 => ["040-Dungeon06"],
           3 => ["053-Negative02"],
           4 => ["026-Town04"] }
  # Hash used for actor lists:
  @music_actor = { 1 => ["026-Town04"],
           2 => ["006-Boss02"],
           3 => ["007-Boss03"],
           4 => ["008-Boss04"],
           5 => ["009-LastBoss01"],
           6 => ["010-LastBoss02"],
           7 => ["011-LastBoss03"],
           8 => ["003-Battle03"] }
  # Hash used for random music:        Â
  @music_rand  = { 1 => ["026-Town04", 100, 100],
           2 => ["040-Dungeon06"] }
          Â
  # Initial values called via script/map events to change battlebacks
  # Initial battle music type ( 0 to 4 )    - Can change from map events -
  @bgm_type   = 0
  # Initial selection of event battlemusic.  - Can change from map events -
  @bgm_event   = 0
  # Initial setting of 'living' party hero.  - Can change from map events -
  @bgm_living  = nil
  # DO NOT TOUCH BELOW:
  # Control switches for automatic 'victory' music system.
  @mm_notfield  = nil
  @mm_no_vm   = nil
 end Â
 #--------------------------------------------------------------------------
 # * Play Background Music
 #   bgm : background music to be played
 #--------------------------------------------------------------------------
 alias mmbgm_play bgm_play
 def bgm_play(bgm)
  if !$game_system.mm_notfield Â
   mmbgm_play(bgm)
  end
 end
 #--------------------------------------------------------------------------
 # * Stop Background Music
 #--------------------------------------------------------------------------
 alias mmbgm_stop bgm_stop
 def bgm_stop
  if !$game_system.mm_notfield Â
   mmbgm_stop
  end
 end
 #--------------------------------------------------------------------------
 # * Play Music Effect
 #   me : music effect to be played
 #--------------------------------------------------------------------------
 alias mmme_play me_play
 def me_play(me)
  if !$game_system.mm_no_vm
   mmme_play(me)
  end
 end
end Â
Â
          Â
          Â
#==============================================================================
# ** Mimi's Music
#------------------------------------------------------------------------------
# Â This module performs routines for choosing the music played during combat.
#==============================================================================
Â
module Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Music Call
 #--------------------------------------------------------------------------  Â
 def call_music
  # Reset the initial value
  mimi_name  = ""
  mimi_volume = 100
  mimi_pitch  = 100
  # Obtain originally set music...
  # Even works if you used the [Change Battle BGM] event command
  $game_system.default_bgm  = $game_system.battle_bgm.name
  $game_system.default_bgmv = $game_system.battle_bgm.volume
  $game_system.default_bgmp = $game_system.battle_bgm.pitch
  # Obtain the ID number of the party leader
  leader_id = $game_party.actors[0].id
  # Obtain the ID number of 'living' party leader
  if $game_system.bgm_living == true
   temp_id = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if temp_id == 0 ; then ; temp_id = actor.id ; end
    end
   end   Â
   leader_id = temp_id
  end
  # Branch based on what type of music we're using.
  case $game_system.bgm_type
  when 0  # Default (normal music settings)
   mimi_name  = $game_system.default_bgm
   mimi_volume = $game_system.default_bgmv
   mimi_pitch  = $game_system.default_bgmp
  when 1  # Hero BGM based
   mimi_name  = $game_system.music_actor[leader_id][0] if $game_system.music_actor.include?(leader_id)
   mimi_volume = $game_system.music_actor[leader_id][1] if $game_system.music_actor.include?(leader_id)
   mimi_pitch  = $game_system.music_actor[leader_id][2] if $game_system.music_actor.include?(leader_id)
  when 2  # Event BGM based
   mimi_name  = $game_system.music_event[$game_system.bgm_event][0] if $game_system.music_event.include?($game_system.bgm_event)
   mimi_volume = $game_system.music_event[$game_system.bgm_event][1] if $game_system.music_event.include?($game_system.bgm_event)
   mimi_pitch  = $game_system.music_event[$game_system.bgm_event][2] if $game_system.music_event.include?($game_system.bgm_event)
  when 3  # Random BGM based
   mimi_rand = (rand($game_system.music_rand.size)) + 1
   mimi_name  = $game_system.music_rand[mimi_rand][0] if $game_system.music_rand.include?(mimi_rand)
   mimi_volume = $game_system.music_rand[mimi_rand][1] if $game_system.music_rand.include?(mimi_rand)
   mimi_pitch  = $game_system.music_rand[mimi_rand][2] if $game_system.music_rand.include?(mimi_rand)
  when 4  # Field BGM based
   $game_system.mm_notfield = true
  end
  # Only perform if NOT field music
  if $game_system.bgm_type != 4
   #Audio Vol/Pitch error prevention
   mimi_volume = 100 if mimi_volume == nil
   mimi_pitch  = 100 if mimi_pitch  == nil
   if mimi_volume >  100 ; mimi_volume = 100 ; end
   if mimi_volume < 0 ;   mimi_volume = 0  ; end
   if mimi_pitch >  150 ;  mimi_volume = 150 ; end
   if mimi_pitch < 50 ;   mimi_volume = 50  ; end    Â
   # Apply changes
   $game_system.battle_bgm.name  = mimi_name
   $game_system.battle_bgm.volume = mimi_volume
   $game_system.battle_bgm.pitch  = mimi_pitch
   # Error checking.  Makes sure that what is chosen is a valid music file.
   # If not, then the system restores the default music file in it's place.
   begin
    @trd = RPG::AudioFile.new($game_system.battle_bgm.name)
     Audio.bgm_play("Audio/BGM/" + @trd.name,0,100)
     # Sound file is true
   rescue Errno::ENOENT
    # Sound file is invalid (restore default)
    $game_system.battle_bgm.name  = $game_system.default_bgm
    $game_system.battle_bgm.volume = $game_system.default_bgmv
    $game_system.battle_bgm.pitch  = $game_system.default_bgmp
   end
   # Error checking.  Makes sure that even the default music file is available.
   # If it is missing, then the system will set the battle music to >none<.
   begin
    @trd = RPG::AudioFile.new($game_system.battle_bgm.name)
    Audio.bgm_play("Audio/BGM/" + @trd.name,0,100)
    # Sound file is true
   rescue Errno::ENOENT
    # Sound file is invalid (restore default)
    $game_system.battle_bgm.name = ""
   end
  end
 end
end
Â
Â
Â
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# Â This class performs map screen processing.
#==============================================================================
Â
class Scene_Map
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Call
 #-------------------------------------------------------------------------- Â
 alias musical_call_battle call_battle
 def call_battle
  # The Included module (Battle Music Call)
  call_music
  # Now, perform the ORIGINAL Battle Call
  musical_call_battle
 end
end
Â
Â
Â
#==============================================================================
# ** Interpreter (part 6)
#------------------------------------------------------------------------------
# Â This interpreter runs event commands. This class is used within the
# Â Game_System class and the Game_Event class.
#==============================================================================
Â
class Interpreter
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Battle Processing
 #--------------------------------------------------------------------------
 alias musical_command_301 command_301
 def command_301
  # The Included module (Battle Music Call)
  call_music
  # Now, perform the ORIGINAL battle call
  musical_command_301
 end
end
Â
Â
Â
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# Â This class performs battle screen processing.
#==============================================================================
Â
class Scene_Battle
 include Mimi_Music
 #--------------------------------------------------------------------------
 # * Main Processing
 #--------------------------------------------------------------------------
 alias musical_main main
 def main
  if $game_system.bgm_living == true
   # Obtain hero for theme system
   @main_hero = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if @main_hero == 0 ; then ; @main_hero = actor.id ; end
    end
   end
  end
  # Perform the 'main' battle routine
  musical_main
  # After the whole battle routine finishes, switch the music back.
  $game_system.battle_bgm.name = $game_system.default_bgm
  $game_map.autoplay
 end
Â
 #--------------------------------------------------------------------------
 # * Start After Battle Phase
 #--------------------------------------------------------------------------
 alias mm_sp5 start_phase5
 def start_phase5
  # Only perform if field music
  if $game_system.bgm_type == 4
   #Set the Victory Music's NoSE flag to true (turns off Victory Music)
   $game_system.mm_no_vm = true
  end
  # Perform the original call
  mm_sp5
  $game_system.mm_notfield = nil
  # Reset the Victory Music's NoSE flag
  $game_system.mm_no_vm = nil
 end
 #--------------------------------------------------------------------------
 # * Frame Update (main phase step 6 : refresh)
 #--------------------------------------------------------------------------
 alias mm_up4s6 update_phase4_step6
 def update_phase4_step6(battler = @active_battler)
  # Perform the original call
  @rtab = !@target_battlers
  @rtab ? mm_up4s6(battler) : mm_up4s6
  if $game_system.bgm_living == true
   # Obtain the currently serviving party hero
   temp_hero = 0
   for i in 0...$game_party.actors.size
    actor = $game_party.actors
    if !actor.dead?
     if temp_hero == 0 ; then ; temp_hero = actor.id ; end
    end
   end
   # If the primary hero died
   if temp_hero != @main_hero
    # Call the battle music
    call_music
    # Play battle BGM
    $game_system.bgm_play($game_system.battle_bgm)   Â
    # Set the current hero for checking
    @main_hero = temp_hero
   end
  end
 end  Â
end
[/rgss]