Ever wanted the music to change to a set piece when you open your menu and to change back to the music that was playing on the map after you leave the menu? Well, here you go. Read the notes in the script or the notes after the script. They're the same notes but are also included in the script so you can look at them any time. Just read the notes and you shouldn't have any trouble understanding how to use the script. It was a few months ago that this was requested but I decided to repost it for use.
#-----------------------------------------------------------------
#----------------------Music in the Menu----------------------
#----------------------written by Shinami---------------------
#-----------------------------------------------------------------
#I decided to write this little script after I saw it had
#been requested on the Crankeye forums. It's really
#simple and easy to use. You just need to leave the
#quotation marks " " around your song name. If
#the name isn't the exact same as the one in your BGM
#folder, you will have problems.
#-----------------------------------------------------------------
#-------------------INCOMPATIBILITY-----------------------
#-----------------------------------------------------------------
#I havn't tested this on any other scripts outside of my own
#but since I used aliases, there should be a .01% chance
#of incompatibility. Basically, it'll only screw up when
#Hell freezes over, if you mistype the song name, or if
#you're using a CMS customly built using a different class
#name than Scene_Menu. I don't mind merging this into
#a CMS BUT you will need to post the CMS script or a
#link to the incompatible script if you want the merge to
#be done. I won't always immediately respond either
#since I do have a life outside of the internet.
#-----------------------------------------------------------------
#----------------HOW TO USE THIS SCRIPT----------------
#-----------------------------------------------------------------
#Insert the script above the script called Main and call it
#what ever you want. Afterwards, replace the text
#SONG NAME GOES HERE with the name of the music
#you want to play in the menu and it'll work just fine.
#-----------------------------------------------------------------
#------------------TOTAL TIME TAKEN----------------------
#-----------------------30 MINUTES--------------------------
#-----------------------------------------------------------------
#Also, thanks go to Blizzard for fixing a small error I
#overlooked!
#Okies...update #2 now makes it work like it was
#was intended to.
#Update #3 is to keep your background sounds from being stopped.
class Scene_Menu
alias initialize_later initialize
def initialize(menu_index = 0)
initialize_later(menu_index = 0)
bgm_name = "SONG NAME GOES HERE"#Name of file must match what you put here.
bgm_volume = 0 #How loud the music plays
bgm_pitch = 100#How fast the music plays
$game_system.bgs_memorize
Audio.bgs_stop
if $game_system.playing_bgm != bgm_name
@bgm = $game_system.playing_bgm #stores the map's music, $game_system.playing_bgm, for later use
Audio.bgm_play("Audio/BGM/" + bgm_name, bgm_volume, bgm_pitch)#begins playing menu music
end
end
alias update_command_later update_command
def update_command
update_command_later
if Input.trigger?(Input::B) and $scene.is_a?(Scene_Map)#This checks to see if you are exiting the menu.
#This plays the predefined cancel sound effect
$game_system.se_play($data_system.cancel_se)
#This tells the game to go back to the map.
$scene = Scene_Map.new
$game_system.bgs_restore
$game_system.bgm_play(@bgm)#recalls the map's music, @bgm, and begins playing.
end
end
end
#-----------------------------------------------------------------
#----------------------Music in the Menu----------------------
#----------------------written by Shinami---------------------
#-----------------------------------------------------------------
#I decided to write this little script after I saw it had
#been requested on the Crankeye forums. It's really
#simple and easy to use. You just need to leave the
#quotation marks " " around your song name. If
#the name isn't the exact same as the one in your BGM
#folder, you will have problems.
#-----------------------------------------------------------------
#-------------------INCOMPATIBILITY-----------------------
#-----------------------------------------------------------------
#I havn't tested this on any other scripts outside of my own
#but since I used aliases, there should be a .01% chance
#of incompatibility. Basically, it'll only screw up when
#Hell freezes over, if you mistype the song name, or if
#you're using a CMS customly built using a different class
#name than Scene_Menu. I don't mind merging this into
#a CMS BUT you will need to post the CMS script or a
#link to the incompatible script if you want the merge to
#be done. I won't always immediately respond either
#since I do have a life outside of the internet.
#-----------------------------------------------------------------
#----------------HOW TO USE THIS SCRIPT----------------
#-----------------------------------------------------------------
#Insert the script above the script called Main and call it
#what ever you want. Afterwards, replace the text
#SONG NAME GOES HERE with the name of the music
#you want to play in the menu and it'll work just fine.
#-----------------------------------------------------------------
#------------------TOTAL TIME TAKEN----------------------
#-----------------------30 MINUTES--------------------------
#-----------------------------------------------------------------
#Also, thanks go to Blizzard for fixing a small error I
#overlooked!
#Okies...update #2 now makes it work like it was
#was intended to.
#Update #3 is to keep your background sounds from being stopped.
Sweet I'm using it.
Quote from: Shinami on January 29, 2007, 12:54:18 PM
I don't mind merging this into a CMS BUT you will need to post the CMS script
No need for that, just put it under the CMS code and it should work fine with any CMS.
BTW, you have a bug. The music will end even when changing only into the Status/Equip/etc. screen.
[spoiler=Open this if you're too lazy to fix it yourself]Change this part:
alias update_later update
def update
if Input.trigger?(Input::B)
if @status_window.active == false #This checks to see if you are exiting the menu.
$game_system.bgm_play(@bgm)#recalls the map's music, @bgm, and begins playing.
end
end
update_later
end alias update_later update
def update
update_later
if Input.trigger?(Input::B) and $scene.is_a?(Scene_Map)
if @status_window.active == false #This checks to see if you are exiting the menu.
$game_system.bgm_play(@bgm)#recalls the map's music, @bgm, and begins playing.
end
end
end[/spoiler]
*slaps hand on forehead* so thats how to do that...I tried checking $scene against scene names but it never worked. Glad to know I was close! Script has been updated so you'll need to recopy the above script and all that jazz.
Uhh......I get this error, the music keeps playing after you exit...
Tested and fixed the bug. Sorry about that.
Quote from: Shinami on January 30, 2007, 12:41:37 AM
*slaps hand on forehead* so thats how to do that...I tried checking $scene against scene names but it never worked. Glad to know I was close! Script has been updated so you'll need to recopy the above script and all that jazz.
Actually you can do that as well:
$scene.class == Scene_MapBut this won't work for superclasses. Here is an example:
$game_actor[2] is a Game_Actor and Game_Actor has the superclass Game_Battler. Using
$game_actor[2].class == Game_ActorThis will result in
true.
$game_actor[2].is_a?(Game_Actor)This will also result in
true.
$game_actor[2].is_a?(Game_Battler)Again the result is
true.
$game_actor[2].class == Game_BattlerBut this one wil result in
false. See the difference?
$game_actor[2].class == Game_Battler
That is false because the method class isn't in Game_Battler?
I was trying this
if $scene == Scene_Map
Hey, instead of just turning the music OFF, can it memorize the BGM?
I am failing to understand what you are asking.
Well, the BGM restarts after exiting the menu. Can it memorize the place in the BGM before switching, then replay upon the exit?
Not without some recoding of how RMXP plays the files I would imagine. I don't know much about audio playback but I do know that the methods in Game_System didn't give an argument to restore the BGM to a set point. Although I realized another flaw in my script when double checking to make sure the above response was accurate. Currently, BGSs may not resume. I'll quickly work that in before continuing Redeye's CMS.
EDIT:Fixed the script to memorize background sounds playing when the menu is opened and to start the BGS when the menu is closed. Can't believe I didn't think of that when I wrote the script to begin with.
Quote from: arrowone on January 31, 2007, 08:40:20 PM
Well, the BGM restarts after exiting the menu. Can it memorize the place in the BGM before switching, then replay upon the exit?
This is as good as impossible in RMXP. Many have tried to make the map BGM continue from the place where it stopped after a battle, but failed. Those who actually succeeded in this (where I proudly count myself in ;D) sadly could not re-create Enterbrain's MIDI synthisizer. MP3s would loop correctly and stuff, but MIDIs were giving them a head-ache.