Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Submission: Music Selector System, by Prexus
Prexus
post Oct 15 2005, 03:23 AM
Post #1


Level 3
Group Icon

Group: Member
Posts: 31
Type: Event Designer
RM Skill: Masterful




Place in a new script above MAIN.

CODE
# Music Selector
# Written by: Prexus
# Special Thanks: Axe Man Deke (came up with code)
# http://prexus.rmxponline.com

# This only finds files in Audio/BGM, so if you are using RTP make sure to export
# the files you want to be able to select into that directory.

class Game_System
  def playing_bgm=(playing_bgm)
    @playing_bgm = playing_bgm
  end
def pick_song(array_index, volume = 100)
   array = Dir.entries("Audio/BGM")
   array.delete("..")
   array.delete(".")
   string = array[array_index]
   loop do
     if string.include?(".")
       string.chop!
     else
       break
     end
   end
   Audio.bgm_play("Audio/BGM/" + string, volume, 0)
   $game_system.playing_bgm.name = string
   Graphics.frame_reset
end
end

class Window_SelectVolume < Window_Base
  def initialize
    @number = 100
    dummy_bitmap = Bitmap.new(32, 32)
    @cursor_width = dummy_bitmap.text_size("0").width + 8
    dummy_bitmap.dispose
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $fontface
    self.contents.font.size = $fontsize
    self.z += 9999
    @index = 0
    refresh
    update_cursor_rect
  end
  def number
    return @number
  end
  def number=(number)
    @number = [[number, 0].max, 100].min
    refresh
  end
  def index=(index)
    @index = index
    refresh
  end
  def update_cursor_rect
    case @index
    when 0
      self.cursor_rect.set(self.width - 32 - 3 * @cursor_width, 32, @cursor_width, 32)
    when 1
      self.cursor_rect.set(self.width - 32 - 2 * @cursor_width, 32, @cursor_width, 32)
    when 2
      self.cursor_rect.set(self.width - 32 - 1 * @cursor_width, 32, @cursor_width, 32)
    when 3
      self.cursor_rect.set(self.width - 32 - 0 * @cursor_width, 32, @cursor_width, 32)
    end
  end
  def update
    super
    if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
      $game_system.se_play($data_system.cursor_se)
      place = 10 ** (3 - 1 - @index)
      n = @number / place % 10
      @number -= n * place
      n = (n + 1) % 10 if Input.repeat?(Input::UP)
      n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
      @number += n * place
      if @number > 100
        @number = 0
      end
      refresh
    end
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @index = (@index + 1) % 3
    end
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @index = (@index + 3 - 1) % 3
    end
    update_cursor_rect
  end
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    s = sprintf("%0*d", 3, @number)
    for i in 0...3
      case i
      when 0
        self.contents.draw_text(self.width-32 - 3 * @cursor_width+4, 32, 32, 32, s[0,1])
      when 1
        self.contents.draw_text(self.width-32 - 2 * @cursor_width+4, 32, 32, 32, s[1,1])
      when 2
        self.contents.draw_text(self.width-32 - 1 * @cursor_width+4, 32, 32, 32, s[2,1])
      when 3
        self.contents.draw_text(self.width-32 - 0 * @cursor_width+4, 32, 32, 32, s[3,1])
      end
    end
    self.contents.draw_text(4, 0, self.width-32, 32, "Volume")
  end
end

class Window_MusicList < Window_Selectable
  def initialize
    super(160, 0, 480, 480)
    refresh
    self.index = 0
  end
  def filename
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    @data = Dir.entries("Audio/BGM")
    @data.delete("..")
    @data.delete(".")
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    loop do
      if item.include?(".")
        item.chop!
      else
        break
      end
    end
    x = 4
    y = index * 32
    self.contents.draw_text(x, y, 608, 32, item)
  end
end

class Scene_MusicSelector
  def main
    @musictype = Window_Command.new(160, ["Battle BGM", "Current"])
    @musictype.x = 0
    @musictype.y = 0
    @musictype.active = true
    @musiclist = Window_MusicList.new
    @musiclist.index = -1
    @musiclist.active = false
    @volume = Window_SelectVolume.new
    @volume.active = false
    @volume.visible = false
    @volume.x = 0
    @volume.y = @musictype.y + @musictype.height
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @volume.dispose
    @musiclist.dispose
    @musictype.dispose
  end
  def update
    @volume.update
    @musiclist.update
    @musictype.update
    if @musictype.active
      update_type
      return
    end
    if @musiclist.active
      update_list
      return
    end
    if @volume.active
      update_volume
      return
    end
  end
  def update_type
    if Input.trigger?(Input::B
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      @musiclist.active = true
      @musictype.active = false
      @musiclist.index = 0
      return
    end
  end
  def update_list
    if Input.trigger?(Input::B
      @musictype.active = true
      @musictype.index = 0
      @musiclist.active = false
      @musiclist.index = -1
      return
    end
    if Input.trigger?(Input::C)
      @volume.number = 100
      @volume.index = 0
      @volume.visible = true
      @volume.active = true
      @musiclist.active = false
      return
    end
  end
  def update_volume
    if Input.trigger?(Input::B
      @volume.visible = false
      @volume.active = false
      @musiclist.active = true
      return
    end
    if Input.trigger?(Input::C)
      case @musictype.index
      when 0
        $data_system.battle_bgm.name = @musiclist.filename
        $data_system.battle_bgm.volume = @volume.number
      when 1
        $game_system.pick_song(@musiclist.index, @volume.number)
      end
      @volume.visible = false
      @volume.active = false
      @musictype.active = true
      @musictype.index = 0
      @musiclist.index = -1
      return
    end
  end
end


Just make an event call script:
$scene = Scene_MusicSelector.new

Then to change the song just hit space after selecting the song you want.


__________________________
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies (1 - 4)
Zinx10
post Jul 27 2008, 12:42 PM
Post #2


Master of Darkness
Group Icon

Group: Revolutionary
Posts: 1,194
Type: Developer
RM Skill: Advanced
Rev Points: 5




uhh....
line eleven is a error!
Line 11 says:
? def playing_bgm=(playing_bgm)

you should probably fix that!
if you fix it, then I will say it'll be good!


__________________________
My Games
Phelxyre: Time Unbound (Current Project)
Game Thread
A game where you start in the future, but you go to the past, to make things right, hopefully.

The Hidden World
Game Thread
An Arcade-style game where you must go through various puzzles to see if you go home.

Here are all the things I Support (They Include Links!)




Go to the top of the page
 
+Quote Post
   
jens009
post Jul 29 2008, 10:12 AM
Post #3


L Did you know? Death gods... only eat apples
Group Icon

Group: +Gold Member
Posts: 2,976
Type: Scripter
RM Skill: Skilled




You have to delete all the question marks at the beginning of each line. =]

Something happened when the forums were brought back up that caused the encoding to have question marks.


__________________________

My RMXP Project:


Farewell RRR. =]
Go to the top of the page
 
+Quote Post
   
skaterdoggy
post Aug 13 2008, 06:56 AM
Post #4


Level 2
Group Icon

Group: Member
Posts: 20
Type: Event Designer
RM Skill: Skilled




...it don't work for me because is incomplete...
plss reupload the script but without smilies;)
because when you copy input ::smile.gif appear smilie---smile.gif
and when you put it in your project it don't work example line ? ? if Input.trigger?(Input::cool.gif


__________________________
<a href="http://www.pricemyname.net/"><img src="http://www.pricemyname.net/wendigous.jpg" /></a>

[Show/Hide] My Projects
Ages Of Xordia



Go to the top of the page
 
+Quote Post
   
Rockman
post Aug 13 2008, 07:09 AM
Post #5


welcome to the rad sunglasses zone. you will never escape
Group Icon

Group: Revolutionary
Posts: 1,240
Type: Musician
RM Skill: Advanced




Yeah, we probably need the [code] tags to disallow smilies!
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 18th May 2013 - 11:31 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker