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.

Problem with Random Battle Music Script

Zek

Member

Well, it works perfectly fine except for boss fights, in my game I use different boss themes depending on the boss fought. The problem with it is that I can't change the Battle BGM that plays during the boss fight via event without it playing for every non-boss battle after the boss fight also. (Before you ask, yes I did turn on the switch that turns off the RBM before I changed it, then after the Battle Processing event I turned off the switch that turns off the RBM.)

If you don't know what the RBM script is, here it is:
Code:
#==========================================================================
# ** SG Random Battle Music
#==========================================================================
# sandgolem 
# Version 1
# 28.06.06
#==========================================================================

Scene_Map::SG_Random_BattleMusic = ['001-Battle01','002-Battle02']
Scene_Map::SG_Disable_RandomMusic = 11

#==========================================================================
#
# To check for updates or find more scripts, visit:
# http://www.gamebaker.com/rmxp/scripts/
#
# To use this script, copy it and insert it in a new section above "Main",
# under the default scripts, and the SDK if you're using it.
#
# Have problems? Official topic:
#   http://forums.gamebaker.com/showthread.php?t=157
#
#==========================================================================

begin
  SDK.log('SG Random Battle Music', 'sandgolem', 1, '28.06.06')
  if SDK.state('SG Random Battle Music') != true
    @sg_randbattlebgm_disabled = true
  end
  rescue
end

if !@sg_randbattlebgm_disabled
#--------------------------------------------------------------------------

class Scene_Map
  alias sandgolem_randombattlebgm_map_callbattle call_battle
  def call_battle
    sg_tempmusic = $data_system.battle_bgm.name.clone
    if !$game_switches[SG_Disable_RandomMusic]
      sg_temp = rand(SG_Random_BattleMusic.size)
      $data_system.battle_bgm.name = SG_Random_BattleMusic[sg_temp]
    end
    sandgolem_randombattlebgm_map_callbattle
    $data_system.battle_bgm.name = sg_tempmusic.clone
  end
end

#--------------------------------------------------------------------------
end

I'm wondering if there's anything that can be done to fix that so I can use more than one boss battle theme (I have four different boss themes I use for the various bosses in my game.)
 

S0L0

Member

here is the method myself use:

Code:
  def call_battle
    $game_temp.battle_calling = false
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    $game_player.make_encounter_count
#    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    $game_system.se_play($data_system.battle_start_se)
    
     if $game_variables[12] == 0
       case rand(4)
       when 0 
         Audio.bgm_play("Audio/BGM/001-Battle01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/002-Battle02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/003-Battle03", 100, 100)
       when 3
          Audio.bgm_play("Audio/BGM/004-Battle04", 100, 100)
        end
    elsif $game_variables[12] == 1
       case rand(4)
       when 0
          Audio.bgm_play("Audio/BGM/005-Boss01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/006-Boss02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/007-Boss03", 100, 100)
       when 3
          Audio.bgm_play("Audio/BGM/008-Boss04", 100, 100)
        end
    elsif $game_variables[12] == 2
       case rand(3)
       when 0
          Audio.bgm_play("Audio/BGM/009-LastBoss01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/010-LastBoss02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/011-LastBoss03", 100, 100)
        end
    end

#    $game_system.bgm_play($game_system.battle_bgm)
    $game_player.straighten
    $scene = Scene_Battle.new
  end

how to use, variable is automaitcly set to 0 (is defaulrt value), so all the monster encounters will call one of those 4 random muscis, but for boss, you want them to be contralable fights, correct? so you will add an event for be boss, so on that event you set the variable to "1" and in end of event set it back to "0" (for all ur encoutners continue be normal muscis), when you want add some hard-boss or final boss, you set variable as "2" and right on end of event you re-add it back to "0" as i said earlier

this way, you get in controll of everything, without need those huge or complex scripts, all by using one single switch

hope it helps u

NOTE: that code belongs to the Scene_Map so if you want add this code, directly (as i have) replace your def call for that one, or merge or whateva you want, otherwize, just add that code over the Main script, but don't forget to add the: "class Scene_Map" withtou quotes on begin of that script, and an extra "end" withotu quotes on end of that same script
 

S0L0

Member

hehehe thanks :P

i prefer create this kind of "scripts" on my own, then use those huge complex scripts out there, specialy for such effect

anyways i'm glad you liked it :)
 

S0L0

Member

sorry man, I told you a temporary code I'm testing, anyways for fix your "problem", simple

Code:
  def call_battle
    $game_temp.battle_calling = false
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    $game_player.make_encounter_count
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    $game_system.se_play($data_system.battle_start_se)
    
     if $game_variables[12] == 0
       case rand(4)
       when 0 
         Audio.bgm_play("Audio/BGM/001-Battle01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/002-Battle02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/003-Battle03", 100, 100)
       when 3
          Audio.bgm_play("Audio/BGM/004-Battle04", 100, 100)
        end
    elsif $game_variables[12] == 1
       case rand(4)
       when 0
          Audio.bgm_play("Audio/BGM/005-Boss01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/006-Boss02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/007-Boss03", 100, 100)
       when 3
          Audio.bgm_play("Audio/BGM/008-Boss04", 100, 100)
        end
    elsif $game_variables[12] == 2
       case rand(3)
       when 0
          Audio.bgm_play("Audio/BGM/009-LastBoss01", 100, 100)
       when 1
          Audio.bgm_play("Audio/BGM/010-LastBoss02", 100, 100)
       when 2
          Audio.bgm_play("Audio/BGM/011-LastBoss03", 100, 100)
        end
    end

#    $game_system.bgm_play($game_system.battle_bgm)
    $game_player.straighten
    $scene = Scene_Battle.new
  end

if you notice, the first disabled code line is re-enabled now, it's all you have to do for fix it :P
 

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