Advertisement
Guest User

bulletxt

a guest
Oct 16th, 2009
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.04 KB | None | 0 0
  1. =begin
  2.                         Continue BGM After Battle
  3.  
  4. Author: BulletXt(bulletxt@gmail.com)
  5. Version: 0.3 Beta1
  6. Date: 16/10/2009
  7.  
  8. Description:
  9. This script will make your map's bgm continue playing after battle ends
  10. instead of restarting.
  11.  
  12. WARNING: You must have installed Microsoft Visual C++ 2008 Redistributable Package,
  13.          you can get it here:
  14. http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&displaylang=en
  15.  
  16. WARNING2: you must not set a battle BGM that is MIDI format and/or part of RTP.
  17.          
  18.  
  19. To install to a new project:
  20. -copy this script and place it as FIRST script in the Material section
  21. -copy all dlls found in root directory of the demo
  22. -copy mplayer folder
  23. -copy Start.exe and Rescue.exe
  24.  
  25. When starting the game, you can either normally start it from Game.exe
  26. or from Start.exe (clicking on Start.exe avoids loading external gui).
  27. =end
  28.  
  29. #                              CONFIGURATION
  30.  
  31. #this is the name of the exe to start the game. Do not add file extension.
  32. STARTGAME = "Start"
  33. #this is the name of the Recover Audio engine exe. Do not add file extension.
  34. RESCUE = "Rescue"
  35.  
  36. #this is a switch ID. When ON, map's BGM will continue playing in battle.
  37. CONTINUE_BGM = 1
  38.  
  39. #this is a switch ID. When ON, it enables Random Battle BGM.
  40. ENABLE_RANDOM_BATTLE_BGM = 2
  41. =begin
  42. these are the Battle BGMs that you want to play randomly.
  43. example:
  44. BATTLE_BGMS_THAT_PLAY_RANDOMLY = ["Battle1", "Battle2","Battle3"]
  45. You can change this array at any time in game through a script call inside
  46. event. To do this type for example:
  47. $audio_random_battle = ["r_Battle1", "r_Battle2","r_Battle3"]
  48. =end
  49. BATTLE_BGMS_THAT_PLAY_RANDOMLY = ["r_Battle1", "r_Battle2","r_Battle3"]
  50.  
  51. ################################################################################
  52. ######################### END CONFIGURATION ####################################
  53. ################################################################################
  54.  
  55.  
  56. #this holds the random battle array globally
  57. $audio_random_battle = BATTLE_BGMS_THAT_PLAY_RANDOMLY
  58. $audio_battle_bgm_random_tmp_id = "nil"
  59. FORMAT_OF_SONGS = ["mp3","ogg","wav","wma"]
  60. ######################### CHECK IF ENGINE IS RUNNING ###########################
  61. #if in test mode, start the recover audio engine
  62.   begin
  63.     #send a string to server. if it exists it means it must not open a new recover gui.  
  64.     open("\\\\.\\pipe\\audio_engine_xt",'w') { |pipe| pipe.write("nil,nil,nil"); } rescue recover = 1    
  65.     #this returns true if there is no recover gui engine running.
  66.     if recover == 1
  67.       Thread.new{system (RESCUE)}
  68.       recover = 0
  69.     end  
  70. end
  71.  
  72. ############################ Handle F12 Reset key ##############################
  73. unless $f12_cleaner_F3XXEFA1.nil?
  74.     #if in test mode, warn the user he is leaving testing mode
  75.     if $TEST
  76.     p sprintf("You are now leaving testing mode.")
  77.     end
  78.  
  79. #kill recover GUI and mplayer
  80. system "start /MIN /B taskkill /F /IM #{RESCUE+".exe"} "
  81. system "start /MIN /B taskkill /F /IM #{"mplayer.exe"} "
  82.  
  83. # Opens the game executable in a new thread
  84. Thread.new{system (STARTGAME+".exe")}
  85. # Exits this thread
  86. exit
  87. end
  88. $f12_cleaner_F3XXEFA1 = true
  89.  
  90.  
  91. module AudioSuffix
  92.   def suffix_check
  93.     for codec in 0...FORMAT_OF_SONGS.size
  94.     path = "Audio\\BGM\\"
  95.     path.gsub!('\\', "/")
  96.     song_file_name = $game_system.battle_bgm.name + "." + FORMAT_OF_SONGS[codec]
  97.    
  98.       if FileTest.exist?(path+song_file_name)
  99.         $audio_suffix = "." + FORMAT_OF_SONGS[codec]
  100.         break
  101.       end
  102.     end  
  103.   end
  104.  
  105.   def recover
  106.   # start recover audio engine
  107.     Thread.new{system (RESCUE)}
  108.     #warn the user that the engine has crashed
  109.     $game_message.texts.push("The Audio Engine server has crashed.")
  110.     $game_message.texts.push("A Rescue GUI mode of the engine should have started.")
  111.     $game_message.texts.push("If it didn't, please manually click on #{RESCUE}.exe .")
  112.     $game_message.texts.push("Remember to close it after closing game.")
  113.     #do a sleep of n seconds to give the time for the engine to start
  114.     sleep(4) #FIX: its not said 6 seconds are enough
  115.   end
  116.  
  117.  
  118. end
  119.  
  120.  
  121. class Game_Map
  122.  
  123.   # initialize the Random Battle BGM array
  124.   # the original Random Battle BGM code was made from ERZENGEL
  125.   attr_accessor :rbmfiles
  126.   alias audio_rbm_initialize initialize
  127.   def initialize
  128.     #set @rbmfiles to the Battle BGM array set by user in CONFIGURATION
  129.     @rbmfiles = $audio_random_battle
  130.     audio_rbm_initialize
  131.   end
  132.  
  133.   #this is a real time update. gets executed each frame.
  134.   #this makes the random battle array always be aware of any change
  135.   #set from Player.
  136.   alias bulletxt_random_battle_update update
  137.   def update
  138.     bulletxt_random_battle_update
  139.     @rbmfiles = $audio_random_battle
  140.   end
  141. end
  142.  
  143.  
  144. class Scene_Map < Scene_Base
  145. include AudioSuffix
  146.  
  147.   def call_battle
  148.  
  149.     # This handles Random Battle BGM
  150.     rbmoff = $data_system.battle_bgm.name.clone
  151.   # if true, it means Random Battle BGM should happen
  152.   if $game_switches[ENABLE_RANDOM_BATTLE_BGM]
  153.      #debug battle bgm array  
  154.      #p $game_map.rbmfiles  
  155.     # this gets a random element from the array
  156.     audio = rand($game_map.rbmfiles.size)
  157.     #if < 1, it must not add anything to array
  158.     if $game_map.rbmfiles.size > 1
  159.      #this puts back the previously removed element into array. at first run
  160.      #this doesn't add anything because the variable is set to nil
  161.     $game_map.rbmfiles.push($audio_battle_bgm_random_tmp_id) if $audio_battle_bgm_random_tmp_id != "nil"
  162.     end
  163.     #this global variable holds the last random Battle BGM. it's needed so at
  164.     #next run we know the element to put back in array (since it gets deleted below)
  165.     $audio_battle_bgm_random_tmp_id = $game_map.rbmfiles[audio]
  166.     #debug the battle bgm that is about to play
  167.     #p $audio_battle_bgm_random_tmp_id
  168.     #this tells VX who is the random Battle BGM to play
  169.     $data_system.battle_bgm.name = $game_map.rbmfiles[audio]
  170.     #if < 1, it must not remove anything from array
  171.     if $game_map.rbmfiles.size > 1
  172. =begin  
  173. remove current Battle BGM from array, so at next battle the random won't
  174. play this again. This avoids that a battle BGM plays 2 times consecutively.
  175. The element gets back in to array at next run after getting the new random
  176. battle bgm to play.
  177. =end    
  178.     $game_map.rbmfiles.delete_at(audio)
  179.     end
  180.   else
  181.   #here the Random Battle BGM code finishes.
  182.   end    
  183.    
  184.     @spriteset.update
  185.     Graphics.update
  186.     $game_player.make_encounter_count
  187.     $game_player.straighten
  188.     $game_temp.map_bgm = RPG::BGM.last
  189.     $game_temp.map_bgs = RPG::BGS.last
  190.  
  191.     if $game_switches[CONTINUE_BGM]
  192.       continue_bgm
  193.       return
  194.     end
  195.    
  196.     #get values of current plaging bgm
  197.     $audio_name = $game_temp.map_bgm.name
  198.     $audio_volume = $game_temp.map_bgm.volume
  199.     $audio_pitch = $game_temp.map_bgm.pitch
  200.     #start playing the same bgm again but with volume at 0
  201.     Audio.bgm_play("Audio/BGM/" + $audio_name, 0, $audio_pitch) rescue nil
  202.     #make game temp bgm be equal to the new playing BGM, so after battle ends
  203.     #it knows who's the values of the bgm to restore (it actually just continues
  204.     #playing it but with volume restored)
  205.     $game_temp.map_bgm = RPG::BGM.new
  206.     $game_temp.map_bgm.name = $audio_name
  207.     $game_temp.map_bgm.volume = $audio_volume
  208.     $game_temp.map_bgm.pitch = $audio_pitch
  209.    
  210.     RPG::BGS.stop
  211.     Sound.play_battle_start
  212.    
  213.     #call suffix function, it returns the exact suffix of bgm
  214.     suffix_check
  215.     #prepeare bgm volume and name to send to server
  216.     volume = $game_system.battle_bgm.volume
  217.     id = $game_system.battle_bgm.name + $audio_suffix
  218.     battle_song = id + ",play," + volume.to_s()
  219.     open("\\\\.\\pipe\\audio_engine_xt",'w') { |pipe| pipe.write(battle_song); } rescue rec = 1    
  220.    
  221.     if rec == 1
  222.       recover
  223.       rec = 0
  224.       open("\\\\.\\pipe\\audio_engine_xt",'w') { |pipe| pipe.write(battle_song); } rescue nil
  225.     end
  226.    
  227.     $game_temp.next_scene = nil
  228.     $scene = Scene_Battle.new
  229.   end
  230.  
  231.  
  232.   def continue_bgm
  233.     Sound.play_battle_start
  234.     $game_temp.next_scene = nil
  235.     $scene = Scene_Battle.new
  236.   end
  237.  
  238. end
  239.  
  240. # Forced Victory ME Stop - KGC_ForceStopVictoryME
  241. # http://ytomy.sakura.ne.jp
  242. module KGC
  243.   module ForceStopVictoryME
  244.   # &#65533;—† Fade out time (milli-second)
  245.   #  If set to 0, the ME stops instantly upon scene change to map.
  246.   FADE_TIME = 1000
  247.   end
  248. end
  249. $imported = {} if $imported == nil
  250. $imported["ForceStopVictoryME"] = true
  251. #end code of Forced Victory ME Stop - KGC_ForceStopVictoryME
  252.  
  253. class Scene_Battle < Scene_Base
  254. include AudioSuffix
  255.  
  256.   alias bulletxt_continue_bgm_process_victory process_victory
  257.   def process_victory
  258.    
  259.     suffix_check
  260.     stop = $game_system.battle_bgm.name + $audio_suffix + ",stop," + "0"
  261.     open("\\\\.\\pipe\\audio_engine_xt",'w') { |pipe| pipe.write(stop); } rescue nil    
  262.     @info_viewport.visible = false
  263.     @message_window.visible = true
  264.     $game_system.battle_end_me.play  if $game_switches[CONTINUE_BGM] == false
  265.     unless $BTEST
  266.       $game_temp.map_bgm.play
  267.       $game_temp.map_bgs.play
  268.     end
  269.     display_exp_and_gold
  270.     display_drop_items
  271.     display_level_up
  272.     battle_end(0)
  273.   end
  274.  
  275.   alias bulletxt_continue_bgm_battle_end battle_end
  276.   def battle_end(result)
  277.     suffix_check
  278.     stop = $game_system.battle_bgm.name + $audio_suffix + ",stop," + "0"
  279.     open("\\\\.\\pipe\\audio_engine_xt",'w') { |pipe| pipe.write(stop); } rescue nil    
  280.     bulletxt_continue_bgm_battle_end(result)
  281.  
  282. # Forced Victory ME Stop - KGC_ForceStopVictoryME
  283. # http://ytomy.sakura.ne.jp
  284.     return if result != 0
  285.     @@_victory_me_thread = Thread.new {
  286.       time = KGC::ForceStopVictoryME::FADE_TIME
  287.        RPG::ME.fade(time)                         # Start ME Fade
  288.        sleep(time / 1000.0)                       # Wait until the fade is done.
  289.        RPG::ME.stop                               # Stop ME                      
  290.     }
  291.     #end code of Forced Victory ME Stop - KGC_ForceStopVictoryME
  292.   end  
  293.  
  294.  
  295. end
  296.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement