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.

Random Battle Music

Hopefully this will be more popular than my last script.

This allows to have multiple battle bgm (one is selected randomly each battle) you could for example use it to play character's battle themes only while they are in the party.
And you can alter the possible choices in game as often as you like.

Thanks to Trickster for making this script better.
Code:
class Game_Party
  attr_accessor   :music
  alias pre_music_initialize initialize
  def initialize
    pre_music_initialize
    @music = []
  end
end

class Scene_Map
  def call_battle
    # Clear battle calling flag
    $game_temp.battle_calling = false
    # Clear menu calling flag
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    # Make encounter count
    $game_player.make_encounter_count
    # Memorize map BGM and stop BGM
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
    file = $game_party.music[rand($game_party.music.size)]
    audio_file = RPG::AudioFile.new(file)
    $game_system.bgm_play(audio_file)
    # Straighten player position
    $game_player.straighten
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
end

Code:
class Game_Party
  attr_accessor   :music
  alias pre_music_initialize initialize
  def initialize
    pre_music_initialize
    @music = []
  end
end

class Scene_Map
  def call_battle
    # Clear battle calling flag
    $game_temp.battle_calling = false
    # Clear menu calling flag
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    # Make encounter count
    $game_player.make_encounter_count
    # Memorize map BGM and stop BGM
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
     $game_system.bgm_play2($game_party.music[rand($game_party.music.size)])
    # Straighten player position
    $game_player.straighten
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
end

class Game_System
  def bgm_play2(bgm)
    @playing_bgm = bgm
    if bgm != nil and bgm != ""
      Audio.bgm_play("Audio/BGM/" + bgm, 100, 100)
    else
      Audio.bgm_stop
    end
    Graphics.frame_reset
  end
end

To add music the code is:
$game_party.music.push("MusicName")
Please note you do not need the file extention

To remove music the code is:
$game_party.music.delete("MusicName")
Please note you do not need the file extention

You probably want a default music at the start of the game, or default selection to do so change the line:
@music = []
to something like
@music = ['Theme01', 'Theme02', 'Theme04']

Any questions or comments?
 
Ive been waiting for someone to make this script! I hate that theres one battle bgm and the the only way to change it is by command!
But this is much better Thanks!
 
Pretty Simple, yet Effective.

Though why did you add the new variable in Game_Party rather than adding it in Game_System?

and instead of the new method in Game_System you could have just done this

Code:
file = $game_party.music[rand($game_party.music.size)]
audio_file = RPG::AudioFile.new(file)
$game_system.bgm_play(audio_file)

But well It is still functional, and many people will find this useful.
 
Trickster said:
Pretty Simple, yet Effective.
Thanks.

Trickster said:
Though why did you add the new variable in Game_Party rather than adding it in Game_System?
I dunno, I just picked a class that only appeared once.

Trickster said:
and instead of the new method in Game_System you could have just done this

Code:
file = $game_party.music[rand($game_party.music.size)]
audio_file = RPG::AudioFile.new(file)
$game_system.bgm_play(audio_file)

Because I couldn't get my attempt at that to work...*steals* so I made a new method.

I'll update the script thanks for that.
 

sixdd

Sponsor

What name do you want us to credit to when we use this awsome script in our games?

And here is a little update with your comments added in to the script, sorry I'm just a comment Nazi, hope you don't mind :D

Code:
#======================================
# Random Battle Music
# Created by: FOMAR0153
#======================================
#
# To call simply use
#
# To add music the code is:
# $game_party.music.push("MusicName")
# Please note you do not need the file extention
#
# To remove music the code is:
# $game_party.music.delete("MusicName")
# Please note you do not need the file extention
#
# You probably want a default music at the start
# of the game, or default selection to do so change the line:
# @music = []
# to something like
# @music = ['Theme01', 'Theme02', 'Theme04']
# 
#--------------------------------------

class Game_Party
  attr_accessor   :music
  alias pre_music_initialize initialize
  def initialize
    pre_music_initialize
    @music = []
  end
end

class Scene_Map
  def call_battle
    # Clear battle calling flag
    $game_temp.battle_calling = false
    # Clear menu calling flag
    $game_temp.menu_calling = false
    $game_temp.menu_beep = false
    # Make encounter count
    $game_player.make_encounter_count
    # Memorize map BGM and stop BGM
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
    file = $game_party.music[rand($game_party.music.size)]
    audio_file = RPG::AudioFile.new(file)
    $game_system.bgm_play(audio_file)
    # Straighten player position
    $game_player.straighten
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
end
 

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