Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Mimi's Battle Music bug

Noru

Member

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]
 
just change

[rgss] 
musical_main
# After the whole battle routine finishes, switch the music back.
$game_system.battle_bgm.name = $game_system.default_bgm
 
[/rgss]

to

[rgss] 
musical_main
# After the whole battle routine finishes, switch the music back.
$game_system.battle_bgm.name = $game_system.default_bgm
$game_map.autoplay
 
[/rgss]
 

Noru

Member

Just tried that now and still didn't work, still can't change the music after someone hits escape from a random battle.
Anyways I do appreciate the help.
I'll see if anyone else might know what the problem is.

Edit: I just noticed that even switching it back to "$game_system.bgm_type = 0" doesn't fix it
 

Aerif

Member

I'm not sure if this will help or not but you should probably be using the latest version of the script:

[rgss] 
#==============================================================================
# ** Mimi's Battle Music
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 4.4-b (Game_System instance version)
#    10-10-2007
#    Full SDK 2.3 Compatible (Does not need or require SDK 2.3)
#------------------------------------------------------------------------------
#
#  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.  And now to
#  Nico_14_Ian for finding a strange bug when map events create a battle which
#  has been fixed
#
#==============================================================================
 
 
 
 
#==============================================================================
# ** 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
    flagged = musical_command_301
    # Reset the FIELD/NotField flag (can't use 'false'... freezes it)
    $mm_notfield = nil
    return flagged
  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
  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]

EDIT: Sorry, this version has the same issue. Damn.
 
my guess is that it doesn't reset

$game_system.mm_notfield

to nil after you escaped but only when you win the battle, (start_phase5 if i remember well only handles victory... )

Edit: Yup i'm right, phase5 only handles victory, so basically you need to add this:

[rgss] 
 
 alias mm_be battle_end
  def battle_end(result)
# 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
  $game_system.mm_notfield = nil
  # Reset the Victory Music's NoSE flag
  $game_system.mm_no_vm = nil
  mm_be(result)
end
 
[/rgss]

somewhere in the code before the last end.

Should work:p i think
 

Noru

Member

Just tried adding it in and now I get the "ArgumentError occurred.

wrong number of arguments(0 for 1)" Win or Escape. The Script points to the "mm_be" part when I open it again after the error.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top