Mundo Maker
¡Bienvenid@ a Mundo Maker!

¿Quieres aprender todo sobre el RPG Maker?



Regístrate y forma parte de Mundo Maker.

[VX] Problema con Script de Reproductor de Música

Ver el tema anterior Ver el tema siguiente Ir abajo

RPG Maker VX [VX] Problema con Script de Reproductor de Música

Mensaje por Oscar92player el 2013-08-23, 17:36

Bueno, primero de todo quiero agradecer la ayuda que podáis ofrecer por adelantado, y en segundo lugar decir que el siguiente script no es mío, sino de un usuario llamado wltr3565. Os paso el link de su tema para los interesados en descargar la demo:
Music Room ~ ZUN's Style v1.1

El script es el siguiente:
Spoiler:

Código:
#================================================================================
#                        Music Room ~ ZUN's Style v1.1
#                                by wltr3565
#================================================================================
# Features:
# - No need to rename the music files!
# - Auto music unlock!
# - Based on ZUN's music room:
# ' That he usually add comments,
# ' That he usually lets the players to play locked musics,
# ' That he usually gives the music name different from the actual file's name,
# ' That he sometimes doesn't list some songs...
# - Auto command install on title! (Thanks to KGC)
# - Commentary format is like normal message in the events!
# - Checks between existing savefiles!
================================================================================
How it will work:
This script tracks the musics that was listed and played, for later to be
replayed in the Music Room Scene. The script detects the unlocked musics between
existing savefiles. You can play the unlocked ones, but to play the locked ones,
you can't just select it once, but twice for your own safety
(spoilers possible!).
================================================================================
How to Use:
There's some event commands for controlling the music locks. What's between []
is optional:

- $game_system.music_flag[id] = control
That one will control the flag of the musics' lock. id is the music's id, from
the set order. control is the control between true or false. true will unlock
the music, regardless, and false will lock the music, regardless.

- $game_system.music_unlocked?(id)
Checks if the music is alread unlocked. id is the music's id, from the set
order. Use it for conditional branches.

- $game_system.music_unlock_all
This command will make all of the musics available to be unlocked.

- $scene = Scene_Music.new[(file, call)]
This command will call the music room. File represents the saveslot for
obtaining the information from the assigned slot. call represents the target
Scene for coming back. The default is title. If you assign the call "Map", will
bring you back to the map. If you insert the file nil, will check all existing
saveslots.
More functions can be seen in the configurations below.
================================================================================
Install:
Insert below title-related scripts and above main.
================================================================================
Terms of Use:
Credit me, wltr3565. Free to use in commercial games as long I'm being credited.
Crediting who I thanked will be a good idea.
================================================================================
Thanks:
ZUN: His games and musics :P, and main inspiration.
KGC: Method for adding command in the menu.
================================================================================
=end
=begin
#===============================================================================
#   COMMENCING COMPATIBILITY FLAG
#===============================================================================
$imported = {} if $imported == nil
$imported["wltr3565's_Music_Room"] = true
#===============================================================================
#   END COMPATIBILITY FLAG
#===============================================================================
module WLTR
  module MUSIC_ROOM_SETUP
    MUSICS = [ # Don't touch
#===============================================================================
# List of musics available at the music room. Write their filename in a string,
# and be sure to add "," without the quotation for each musics, like this:
# Town1,
# Battle2,
#===============================================================================
    "Town5", # Music 1,
    "Field1", # Music 2,
    "Battle1", # Music 3 and so forth.
    "st31",
    "th06_15",
#===============================================================================
    ] # Don't touch
    
    MUSICS_NAME = [# Don't touch
#===============================================================================
# Each musics' name to be shown at the music room. Write it in a string. It will
# be used at each assigned musics in the same order, like this:
#        filename                                name
#        "Town1",                             "Melancholy",
#       "Battle2",                             "Battling",
# At the music room, the Town1 music will have it's name shown as Melancholy,
# and Battle2 as Battling.
#===============================================================================
    "Menú Principal",# Music 1,
    "Mapa",# Music 2 and so forth.
    "Batalla",
    "Beloved Tomboyish Girl",
    "U.N. Owen Was Her?!",
#===============================================================================
    ] # Don't touch
    
    MUSICS_COMMENT = [] # << EXTREMELY DO NOT TOUCH!
    
#===============================================================================
# In here you can make comments for the musics listed. The format for writing
# them is almost the same as the normal message in text events. To make one,
# do this:
# MUSICS_COMMENT[id] = comment
# The id represents the music's order from 0 that listed above. comment is the
# comment. Be sure to close the text with "". You can use | for making new lines
# other than using enter. Example:
#
# MUSICS_COMMENT[0] = "What we usually hear while testing our game...
# You guys must be bored."
# The Town1 music (from the example list of above) will show it's comments like
# this:
# What we usually hear while testing our game...
# You guys must be bored.
#
# Doesn't make one will make the comment empty.
#===============================================================================
    MUSICS_COMMENT[0] = "VX RTP's music."

    MUSICS_COMMENT[1] = "VX RTP's music."

    MUSICS_COMMENT[2] = "VX RTP's music."

    MUSICS_COMMENT[3] = "~ Beloved Tomboyish Girl ~"
    
    MUSICS_COMMENT[4] = "~ U.N. Owen Was Her?! ~"

#===============================================================================

#===============================================================================
# Comment for a locked music, to warn the players that the music is not yet
# unlocked in the game. The format for writing it is the same.
#===============================================================================
    EMPTY_COMMENT = "No disponible."
#===============================================================================

#===============================================================================
# Letter used to mark that the music is not yet unlocked. Write it in a string.
# Example: Melancholy will show ?????????? if it's not yet unlocked and the
# UNKNOWN_WORD is "?".
#===============================================================================
    UNKNOWN_WORD = ""
    
#===============================================================================
# The music room texts' font size. The higher the number, the bigger the
# the letters. Write it in a number. Suggested that the font size is not 20, but
# 16.
#===============================================================================
    FONT_SIZE = 16
    
#===============================================================================
# Custom background for the music room. Leave it "" if you don't want to use
# one. The background image must be located in Graphics/System folder.
# To note tha if you want to use a background, the big window that shows the
# music room's name at the top-left of the screen will vanish.
#===============================================================================
    BACKGROUND = "Auditory"
    
#===============================================================================
# The music room's name shown in the commands. Write it in a string.
#===============================================================================
    MUSIC_ROOM_NAME = "Auditorio"
    
#===============================================================================
# This will check if you want to let the music unlocked while played in the
# music room, while the music itself is not yet unlocked.
# true  : Let it unlocked.
# false : Don't unlock it.
#===============================================================================
    SPOIL_UNLOCK = false
    
#===============================================================================
# This will check if you can play a locked music after you select it twice.
# true  : Play it.
# false : Don't play it.
#===============================================================================
    LOCK_PLAYABLE = false
    
#===============================================================================
# Checks if you want the command to be useable for title screen.
# true  : Add it.
# false : Don't add it.
#===============================================================================
    ADD_TO_MENU = true
    
#===============================================================================
# The switch for limiting the accessibility of the music room at the title
# screen. Set the id. If the assigned switch is on, the command will show.
# If it's off, will not show. Useless if ADD_TO_MENU is false. Set below to nil
# if you want the music room accessable at anytime.
#===============================================================================
    TITLE_SWITCH = 1
    
#===============================================================================
# Number of columns that you want to have for the list.
#===============================================================================
    COLUMNS = 2
  end
end

"=============================================================================="
"   BELOW IS TOO DANGEROUS TO READ WITHOUT PROPER SCRIPTING SKILLS. THEREFOR,  "
"                            EDIT AT YOUR OWN RISK!                            "
"=============================================================================="

class Game_System
  attr_reader :music_list
  attr_accessor :music_flag
  attr_accessor :spoiler
  alias initialize_musics initialize
  def initialize
    initialize_musics
    
    @spoiler = false
    @music_list = WLTR::MUSIC_ROOM_SETUP::MUSICS
    @music_flag = []
    for i in 0..@music_list.size - 1
      @music_flag[i] = false
    end
  end
  
  def music_unlocked?(id)
    return @music_flag[id]
  end
  
  def music_unlock_all
    for i in 0..@music_list.size + 1
      @music_flag[i] = true
    end
  end
end

module RPG
  class BGM < AudioFile
    alias play_check play
    def play
      if !@name.empty?
        check = $game_system.music_list.index(@name)

        play_check
        
        return if $game_system.spoiler
        return if check == nil
        $game_system.music_flag[check] = true
      end
    end
  end
end

class Scene_Music < Scene_Base
  def initialize(file = nil, call = "Title")
    @last_bgm = RPG::BGM.last
    @index = 0
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @file = file
    @call = call
    @spoil = false
    $game_system.spoiler = true if !WLTR::MUSIC_ROOM_SETUP::SPOIL_UNLOCK
  end
  
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
  
  def start
    super
    create_menu_background
    if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
      @background = Sprite.new
      @background.bitmap = Cache.system(WLTR::MUSIC_ROOM_SETUP::BACKGROUND)
    else
      @background = Window_Base.new(0, 0, 272, 60)
      @background.contents.draw_text(0, 0, 272, 24, WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    end
    @viewport = Viewport.new(0, 0, 544, 416)
#    @music_list = Window_Music_List.new(0, 60, 272, 416 - 260, @file)
    @music_list = Window_Music_List.new(0, 60, 272, 416 - 188, @file)
    @music_list.viewport = @viewport
#    @comment = Window_Comment.new(0, 416 - 200, 544, 200)
    @comment = Window_Comment.new(0, 416 - 128, 544, 128)
    @comment.viewport = @viewport
    @spoil = true if $game_system.music_flag[0] == false
    @comment.refresh(@spoil)
    @spoil = false
    @index = @music_list.index
  end

  def terminate
    super
    dispose_menu_background
    @music_list.dispose
    @comment.dispose
    @background.dispose if @background != nil
  end

  def return_scene
    eval("$scene = Scene_" + @call + ".new")
    $game_system.spoiler = false
    @last_bgm.play
  end

  def update
    super
    update_menu_background
    @music_list.update
    @comment.update
    update_music
  end
  
  def update_music
    @spoil = false if @music_list.index != @index
    @index = @music_list.index if @music_list.index != @index
    if Input.trigger?(Input::C)
      if @available_musics[@music_list.index] == true
        bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
        bgm.play
        @spoil = false
        @comment.id = @music_list.index
        spoil = false
        spoil = true if !$game_system.music_flag[@music_list.index]
        @comment.refresh(spoil)
      else
        if @spoil == false
          RPG::BGM.stop
          @comment.id = @music_list.index
          @comment.refresh
          @spoil = true if WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
        else
          return if !WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
          bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
          bgm.play
          @comment.id = @music_list.index
          @spoil = false
          @comment.refresh(true)
          @music_list.refresh if !$game_system.spoiler
        end
      end
    elsif Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(Input::X)
      RPG::BGM.stop
    elsif Input.trigger?(Input::Y)
      RPG::BGM.fade(600)
    end
  end
end

class Window_Music_List < Window_Selectable
  def initialize(x, y, width, height, file = nil)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @column_max = WLTR::MUSIC_ROOM_SETUP::COLUMNS
    if @column_max > 1
      self.width += 272
    end
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @index = 0
    refresh
  end
  
  def refresh
    self.contents.clear
    @data = WLTR::MUSIC_ROOM_SETUP::MUSICS_NAME
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      rect.width -= 4
      name = item
      known = @available_musics[index]
      if !known
        count = name.size + 1
        name = "¿?"
        for i in 1...count
          name += WLTR::MUSIC_ROOM_SETUP::UNKNOWN_WORD
        end
      end
      rect.width -= 4
      self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
      self.contents.draw_text(rect.x, rect.y, 24, rect.height, sprintf("%2d:", index + 1), 2)
      self.contents.draw_text(rect.x + 24, rect.y, self.width - 32, rect.height, name)
    end
  end
  
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
end

class Window_Comment < Window_Base
  attr_accessor :id
  def initialize(x, y, width, height, id = 0)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @id = id
    self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
    pre_start
    refresh
  end
  
  def pre_start
#===============================================================================
# Insert a code or two here if you want to do something before the first refresh
# starts.
#===============================================================================

#===============================================================================
  end
  
  def pre_refresh
#===============================================================================
# Insert a code or two here if you want to do something before the refresh
# starts.
#===============================================================================

#===============================================================================
  end
  
  def refresh(spoil = false)
    pre_refresh
    @x = 0
    @y = 0
    self.contents.clear
    text = WLTR::MUSIC_ROOM_SETUP::MUSICS_COMMENT[@id]
    text = WLTR::MUSIC_ROOM_SETUP::EMPTY_COMMENT if !$game_system.music_unlocked?(@id) and spoil == false
    text = "" if text == nil
    process = text
    text = convert_special_characters(process)
    @comment = []
    for i in 0..text.size - 1
      @comment << text[i, 1]
    end
    update
  end
  
  def convert_special_characters(text)
    text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
    text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
    text.gsub!(/\n/i) { "|" }
    return text
  end
  
  def update
    super
    word = @comment.shift
    return if word == nil
    case word
    when "|"
      @x = 0
      @y += self.contents.text_size(word).height
    else
      self.contents.draw_text(@x, @y, 40, WLH, word)
      width = self.contents.text_size(word).width
      @x += width
    end
  end
end

#==============================================================================
# ■ Window_Command
#==============================================================================
# Stole this from KGC...
class Window_Command < Window_Selectable
  unless method_defined?(:add_command)
  #--------------------------------------------------------------------------
  # ○ コマンドを追加
  #    追加した位置を返す
  #--------------------------------------------------------------------------
  def add_command(command)
    @commands << command
    @item_max = @commands.size
    item_index = @item_max - 1
    refresh_command
    draw_item(item_index)
    return item_index
  end
  #--------------------------------------------------------------------------
  # ○ コマンドをリフレッシュ
  #--------------------------------------------------------------------------
  def refresh_command
    buf = self.contents.clone
    self.height = [self.height, row_max * WLH + 32].max
    create_contents
    self.contents.blt(0, 0, buf, buf.rect)
    buf.dispose
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを挿入
  #--------------------------------------------------------------------------
  def insert_command(index, command)
    @commands.insert(index, command)
    @item_max = @commands.size
    refresh_command
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを削除
  #--------------------------------------------------------------------------
  def remove_command(command)
    @commands.delete(command)
    @item_max = @commands.size
    refresh
  end
  end
end

class Scene_Title < Scene_Base
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_cleardata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
        @game_message   = Marshal.load(file)
        @game_switches  = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
    if @file_exist and WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      @unlock_flag = @game_switches[WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH] unless @unlock_flag == true
    end
  end
  
  # Stole this from KGC's enemy guide.
  if WLTR::MUSIC_ROOM_SETUP::ADD_TO_MENU
  #--------------------------------------------------------------------------
  # ● コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias create_command_window_item_almanac create_command_window
  def create_command_window
    create_command_window_item_almanac

    return if $imported["CustomMenuCommand"]
    for i in 0..3
      @filename = make_filename(i)
      load_cleardata
    end
    if WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      return if !@unlock_flag
    end
    @__command_music_room =
      @command_window.add_command(WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    if @command_window.oy > 0
      @command_window.oy -= Window_Base::WLH
    end
  end
  end
  #--------------------------------------------------------------------------
  # ● コマンド選択の更新
  #--------------------------------------------------------------------------
  alias update_command_selection_music_room update
  def update
    current_menu_index = @__command_music_room
    call_item_almanac = false

    if Input.trigger?(Input::C)
      case @command_window.index
      when @__command_music_room  # モンスター図鑑
        call_enemy_guide_flag = true
      end
    end

    # モンスター図鑑に移行
    if call_enemy_guide_flag
      Sound.play_decision
      $scene = Scene_Music.new
      return
    end

    update_command_selection_music_room
  end
end
#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================

En realidad, aunque el título habla sólo de un problema, en realidad son varios. Se trata de éstos:

-El primer problema es relacionado con el texto. Cuando escribes los comentarios de una de las músicas, no muestran ni las tildes ni aquellos símbolos que no estén en la ortografía y abecedario ingleses. Debido a ese problema, cuando escribo un comentario que lleve alguna tilde e incluso la ñ, se ve un rombo con una interrogación dentro, en lugar de la palabra correctamente escrita.

-Otro problema surge con los mapas configurados para que no suene ni una música ni sonido del mapa anterior, como el de la siguiente imagen:


El problema es que aunque hayas configurado el mapa para que no suene nada de música ni efectos de ambiente, siguen sonando los del anterior mapa cuando no debería ser así. Además, si oyes alguna música del reproductor, esta sigue escuchándose en mapas configurados así.


Por lo demás, creo que no hay más problemas que puedan considerarse graves dentro del script. Y si por casualidad encontraseis algún otro problema, bienvenida sea la solución xDD

P.D.: No hace falta decir que quien resuelva el problema, aparecerá en los créditos del juego que estamos produciendo unos amigos y yo. Al fin y al cabo, el creador del script ha participado creándolo, pero también tiene mérito aquel que haya reparado sus errores.
avatar
Oscar92player
Principiante
Principiante

0/3

Créditos 346

Gracias : 39

Volver arriba Ir abajo

RPG Maker VX Re: [VX] Problema con Script de Reproductor de Música

Mensaje por orochii el 2013-08-23, 19:55

wltr3565, el de Cruna Aktrid C:.
===
El problema de las letras, ese de que queden rombos interrogativos (?), es porque la Ñ, así como cualquier otra letra con acento así como los kanjis son letras de dos bytes (digamos que dos caracteres xD). Es algo así como n~, a´, etcétera, sólo que al mostrarlo Ruby hace su magia y los junta xd (en realidad usan caracteres especiales, sino en un texto escribes ~enterbrain~ y te saldría ~enterbraiñ xD).
Eso lo pude solucionar, hice un pequeño malabar.
También solucioné el bug de que cuando el nombre de la música estaba vacío, no hiciera el cambio. En teoría debería funcionar todo bien xD.
Código:
=begin
================================================================================
                        Music Room ~ ZUN's Style v1.1
                                by wltr3565
================================================================================
This is mainly for my project (or shouldn't I?). Among all music room scripts
that I found, none of them sastify me. They lack commentary. Comments are very
important for your composers, you know, or to add more description for the
music...
================================================================================
Features:
- No need to rename the music files!
- Auto music unlock!
- Based on ZUN's music room:
' That he usually add comments,
' That he usually lets the players to play locked musics,
' That he usually gives the music name different from the actual file's name,
' That he sometimes doesn't list some songs...
- Auto command install on title! (Thanks to KGC)
- Commentary format is like normal message in the events!
- Checks between existing savefiles!
================================================================================
How it will work:
This script tracks the musics that was listed and played, for later to be
replayed in the Music Room Scene. The script detects the unlocked musics between
existing savefiles. You can play the unlocked ones, but to play the locked ones,
you can't just select it once, but twice for your own safety
(spoilers possible!).
================================================================================
How to Use:
There's some event commands for controlling the music locks. What's between []
is optional:

- $game_system.music_flag[id] = control
That one will control the flag of the musics' lock. id is the music's id, from
the set order. control is the control between true or false. true will unlock
the music, regardless, and false will lock the music, regardless.

- $game_system.music_unlocked?(id)
Checks if the music is alread unlocked. id is the music's id, from the set
order. Use it for conditional branches.

- $game_system.music_unlock_all
This command will make all of the musics available to be unlocked.

- $scene = Scene_Music.new[(file, call)]
This command will call the music room. File represents the saveslot for
obtaining the information from the assigned slot. call represents the target
Scene for coming back. The default is title. If you assign the call "Map", will
bring you back to the map. If you insert the file nil, will check all existing
saveslots.
More functions can be seen in the configurations below.
================================================================================
Install:
Insert below title-related scripts and above main.
================================================================================
Terms of Use:
Credit me, wltr3565. Free to use in commercial games as long I'm being credited.
Crediting who I thanked will be a good idea.
================================================================================
Thanks:
ZUN: His games and musics :P, and main inspiration.
KGC: Method for adding command in the menu.
================================================================================
=end
#===============================================================================
#  COMMENCING COMPATIBILITY FLAG
#===============================================================================
$imported = {} if $imported == nil
$imported["wltr3565's_Music_Room"] = true
#===============================================================================
#  END COMPATIBILITY FLAG
#===============================================================================
module WLTR
  module MUSIC_ROOM_SETUP
    MUSICS = [ # Don't touch
#===============================================================================
# List of musics available at the music room. Write their filename in a string,
# and be sure to add "," without the quotation for each musics, like this:
# Town1,
# Battle2,
#===============================================================================
    "Town5", # Music 1,
    "Field1", # Music 2,
    "Battle1", # Music 3 and so forth.
    "st31",
    "th06_15",
#===============================================================================
    ] # Don't touch
   
    MUSICS_NAME = [# Don't touch
#===============================================================================
# Each musics' name to be shown at the music room. Write it in a string. It will
# be used at each assigned musics in the same order, like this:
#        filename                                name
#        "Town1",                            "Melancholy",
#      "Battle2",                            "Battling",
# At the music room, the Town1 music will have it's name shown as Melancholy,
# and Battle2 as Battling.
#===============================================================================
    "Town5", # Music 1,
    "Field1", # Music 2 and so forth.
    "Battle1",
    "Beloved Tomboyish Girl",
    "U.N. Owen Was Her?!",
#===============================================================================
    ] # Don't touch
   
    MUSICS_COMMENT = [] # << EXTREMELY DO NOT TOUCH!
   
#===============================================================================
# In here you can make comments for the musics listed. The format for writing
# them is almost the same as the normal message in text events. To make one,
# do this:
# MUSICS_COMMENT[id] = comment
# The id represents the music's order from 0 that listed above. comment is the
# comment. Be sure to close the text with "". You can use | for making new lines
# other than using enter. Example:
#
# MUSICS_COMMENT[0] = "What we usually hear while testing our game...
# You guys must be bored."
# The Town1 music (from the example list of above) will show it's comments like
# this:
# What we usually hear while testing our game...
# You guys must be bored.
#
# Doesn't make one will make the comment empty.
#===============================================================================
    MUSICS_COMMENT[0] = "VX RTP's music. Commonly used for title screen.
   
Enterbraiñ á just prefer this music for new projects' title theme.
But really, why don't they name it \"Title\" or something more
fit other than \"Town5\"?"

    MUSICS_COMMENT[1] = "VX RTP's music.
   
I do like this one personally, too bad, I'm not even sure what's
the best situation for using this piece... No need to answer
this, really."

    MUSICS_COMMENT[2] = "VX RTP's music. The default battle theme.

Enterbrain do made 4 battle themes for us to use, but they
selected this for the default. Because of the default battle
system?"

    MUSICS_COMMENT[3] = "~ Beloved Tomboyish Girl ~
Composed by ZUN, Cirno's theme from TH12.3.

This piece was not made purely by ZUN himself, it's rearranged
by Tasofro's composer.
I love this theme! The theme's so stupid, but cool at a time.
One of the best Tasofro's Touhou music remix, I guess."
   
    MUSICS_COMMENT[4] = "~ U.N. Owen Was Her?! ~
Composed by ZUN, Flandre Scarlet's theme from TH06.

One of ZUN's most loli-tastic musics. The theme's very chaotic
aswell. Really Touhou-like.
This one's the MIDI version. I prefer the MIDI version compared
to the WAV  version because the MIDI version more fit for RPG
games..."
   
#===============================================================================

#===============================================================================
# Comment for a locked music, to warn the players that the music is not yet
# unlocked in the game. The format for writing it is the same.
#===============================================================================
    EMPTY_COMMENT = "*** The selected music has not yet been played in the game. ***

      The comments may contain spoiler, as well as the music
itself. Select the music again to play the music, or select
another music."
#===============================================================================

#===============================================================================
# Letter used to mark that the music is not yet unlocked. Write it in a string.
# Example: Melancholy will show ?????????? if it's not yet unlocked and the
# UNKNOWN_WORD is "?".
#===============================================================================
    UNKNOWN_WORD = "?"
   
#===============================================================================
# The music room texts' font size. The higher the number, the bigger the
# the letters. Write it in a number. Suggested that the font size is not 20, but
# 16.
#===============================================================================
    FONT_SIZE = 16
   
#===============================================================================
# Custom background for the music room. Leave it "" if you don't want to use
# one. The background image must be located in Graphics/System folder.
# To note tha if you want to use a background, the big window that shows the
# music room's name at the top-left of the screen will vanish.
#===============================================================================
    BACKGROUND = ""
   
#===============================================================================
# The music room's name shown in the commands. Write it in a string.
#===============================================================================
    MUSIC_ROOM_NAME = "Music Room"
   
#===============================================================================
# This will check if you want to let the music unlocked while played in the
# music room, while the music itself is not yet unlocked.
# true  : Let it unlocked.
# false : Don't unlock it.
#===============================================================================
    SPOIL_UNLOCK = false
   
#===============================================================================
# This will check if you can play a locked music after you select it twice.
# true  : Play it.
# false : Don't play it.
#===============================================================================
    LOCK_PLAYABLE = true
   
#===============================================================================
# Checks if you want the command to be useable for title screen.
# true  : Add it.
# false : Don't add it.
#===============================================================================
    ADD_TO_MENU = true
   
#===============================================================================
# The switch for limiting the accessibility of the music room at the title
# screen. Set the id. If the assigned switch is on, the command will show.
# If it's off, will not show. Useless if ADD_TO_MENU is false. Set below to nil
# if you want the music room accessable at anytime.
#===============================================================================
    TITLE_SWITCH = 1
   
#===============================================================================
# Number of columns that you want to have for the list.
#===============================================================================
    COLUMNS = 2
  end
end

"=============================================================================="
"  BELOW IS TOO DANGEROUS TO READ WITHOUT PROPER SCRIPTING SKILLS. THEREFOR,  "
"                            EDIT AT YOUR OWN RISK!                            "
"=============================================================================="

class Game_System
  attr_reader :music_list
  attr_accessor :music_flag
  attr_accessor :spoiler
  alias initialize_musics initialize unless $@
  def initialize
    initialize_musics
   
    @spoiler = false
    @music_list = WLTR::MUSIC_ROOM_SETUP::MUSICS
    @music_flag = []
    for i in 0..@music_list.size - 1
      @music_flag[i] = false
    end
  end
 
  def music_unlocked?(id)
    return @music_flag[id]
  end
 
  def music_unlock_all
    for i in 0..@music_list
      @music_flag[i] = true
    end
  end
end

module RPG
  class BGM < AudioFile
    alias play_check play unless $@
    def play
      if !@name.empty?
        check = $game_system.music_list.index(@name)
        $game_system.music_flag[check] = true unless ($game_system.spoiler)||(check == nil)
      end
      play_check
    end
  end
end

class Scene_Music < Scene_Base
  def initialize(file = nil, call = "Title")
    @last_bgm = RPG::BGM.last
    @index = 0
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @file = file
    @call = call
    @spoil = false
    $game_system.spoiler = true if !WLTR::MUSIC_ROOM_SETUP::SPOIL_UNLOCK
  end
 
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
 
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters    = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm      = Marshal.load(file)
        @last_bgs      = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
 
  def start
    super
    create_menu_background
    if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
      @background = Sprite.new
      @background.bitmap = Cache.system(WLTR::MUSIC_ROOM_SETUP::BACKGROUND)
    else
      @background = Window_Base.new(0, 0, 272, 60)
      @background.contents.draw_text(0, 0, 272, 24, WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    end
    @viewport = Viewport.new(0, 0, 544, 416)
    @music_list = Window_Music_List.new(0, 60, 272, 416 - 260, @file)
    @music_list.viewport = @viewport
    @comment = Window_Comment.new(0, 416 - 200, 544, 200)
    @comment.viewport = @viewport
    @spoil = true if $game_system.music_flag[0] == false
    @comment.refresh(@spoil)
    @spoil = false
    @index = @music_list.index
  end

  def terminate
    super
    dispose_menu_background
    @music_list.dispose
    @comment.dispose
    @background.dispose if @background != nil
  end

  def return_scene
    eval("$scene = Scene_" + @call + ".new")
    $game_system.spoiler = false
    @last_bgm.play
  end

  def update
    super
    update_menu_background
    @music_list.update
    @comment.update
    update_music
  end
 
  def update_music
    @spoil = false if @music_list.index != @index
    @index = @music_list.index if @music_list.index != @index
    if Input.trigger?(Input::C)
      if @available_musics[@music_list.index] == true
        bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
        bgm.play
        @spoil = false
        @comment.id = @music_list.index
        spoil = false
        spoil = true if !$game_system.music_flag[@music_list.index]
        @comment.refresh(spoil)
      else
        if @spoil == false
          RPG::BGM.stop
          @comment.id = @music_list.index
          @comment.refresh
          @spoil = true if WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
        else
          return if !WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
          bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
          bgm.play
          @comment.id = @music_list.index
          @spoil = false
          @comment.refresh(true)
          @music_list.refresh if !$game_system.spoiler
        end
      end
    elsif Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(Input::X)
      RPG::BGM.stop
    elsif Input.trigger?(Input::Y)
      RPG::BGM.fade(600)
    end
  end
end

class Window_Music_List < Window_Selectable
  def initialize(x, y, width, height, file = nil)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @column_max = WLTR::MUSIC_ROOM_SETUP::COLUMNS
    if @column_max > 1
      self.width += 272
    end
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @index = 0
    refresh
  end
 
  def refresh
    self.contents.clear
    @data = WLTR::MUSIC_ROOM_SETUP::MUSICS_NAME
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #    index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      rect.width -= 4
      name = item
      known = @available_musics[index]
      if !known
        count = name.size + 1
        name = ""
        for i in 1...count
          name += WLTR::MUSIC_ROOM_SETUP::UNKNOWN_WORD
        end
      end
      rect.width -= 4
      self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
      self.contents.draw_text(rect.x, rect.y, 24, rect.height, sprintf("%2d:", index + 1), 2)
      self.contents.draw_text(rect.x + 24, rect.y, self.width - 32, rect.height, name)
    end
  end
 
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
 
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters    = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm      = Marshal.load(file)
        @last_bgs      = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
end

class Window_Comment < Window_Base
  attr_accessor :id
  def initialize(x, y, width, height, id = 0)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @id = id
    self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
    pre_start
    refresh
  end
 
  def pre_start
#===============================================================================
# Insert a code or two here if you want to do something before the first refresh
# starts.
#===============================================================================

#===============================================================================
  end
 
  def pre_refresh
#===============================================================================
# Insert a code or two here if you want to do something before the refresh
# starts.
#===============================================================================

#===============================================================================
  end
 
  def refresh(spoil = false)
    pre_refresh
    @x = 0
    @y = 0
    self.contents.clear
    text = WLTR::MUSIC_ROOM_SETUP::MUSICS_COMMENT[@id]
    text = WLTR::MUSIC_ROOM_SETUP::EMPTY_COMMENT if !$game_system.music_unlocked?(@id) and spoil == false
    text = "" if text == nil
    process = text
    text = convert_special_characters(process)
    sig = false
    @comment = []
    for i in 0...text.size
      if sig==true
        sig = false
        next
      end
      s = text[i,2]
      chr = "ñÑáéíóúàèìòùäëïöüâêîôûãõÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÃÕ"
      l = ( chr.include?(s) ) ? 2 : 1
      @comment << text[i, l]
      sig = true if l==2
    end
    update
  end
 
  def convert_special_characters(text)
    text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
    text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
    text.gsub!(/\n/i) { "|" }
    return text
  end
 
  def update
    super
    word = @comment.shift
    return if word == nil
    case word
    when "|"
      @x = 0
      @y += self.contents.text_size(word).height
    else
      self.contents.draw_text(@x, @y, 40, WLH, word)
      width = self.contents.text_size(word).width
      @x += width
    end
  end
end

#==============================================================================
# ■ Window_Command
#==============================================================================
# Stole this from KGC...
class Window_Command < Window_Selectable
  unless method_defined?(:add_command)
  #--------------------------------------------------------------------------
  # ○ コマンドを追加
  #    追加した位置を返す
  #--------------------------------------------------------------------------
  def add_command(command)
    @commands << command
    @item_max = @commands.size
    item_index = @item_max - 1
    refresh_command
    draw_item(item_index)
    return item_index
  end
  #--------------------------------------------------------------------------
  # ○ コマンドをリフレッシュ
  #--------------------------------------------------------------------------
  def refresh_command
    buf = self.contents.clone
    self.height = [self.height, row_max * WLH + 32].max
    create_contents
    self.contents.blt(0, 0, buf, buf.rect)
    buf.dispose
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを挿入
  #--------------------------------------------------------------------------
  def insert_command(index, command)
    @commands.insert(index, command)
    @item_max = @commands.size
    refresh_command
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを削除
  #--------------------------------------------------------------------------
  def remove_command(command)
    @commands.delete(command)
    @item_max = @commands.size
    refresh
  end
  end
end

class Scene_Title < Scene_Base
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
 
  def load_cleardata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters    = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm      = Marshal.load(file)
        @last_bgs      = Marshal.load(file)
        @game_system    = Marshal.load(file)
        @game_message  = Marshal.load(file)
        @game_switches  = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
    if @file_exist and WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      @unlock_flag = @game_switches[WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH] unless @unlock_flag == true
    end
  end
 
  # Stole this from KGC's enemy guide.
  if WLTR::MUSIC_ROOM_SETUP::ADD_TO_MENU
  #--------------------------------------------------------------------------
  # ● コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias create_command_window_item_almanac create_command_window unless $@
  def create_command_window
    create_command_window_item_almanac

    return if $imported["CustomMenuCommand"]
    for i in 0..3
      @filename = make_filename(i)
      load_cleardata
    end
    if WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      return if !@unlock_flag
    end
    @__command_music_room =
      @command_window.add_command(WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    if @command_window.oy > 0
      @command_window.oy -= Window_Base::WLH
    end
  end
  end
  #--------------------------------------------------------------------------
  # ● コマンド選択の更新
  #--------------------------------------------------------------------------
  alias update_command_selection_music_room update unless $@
  def update
    current_menu_index = @__command_music_room
    call_item_almanac = false

    if Input.trigger?(Input::C)
      case @command_window.index
      when @__command_music_room  # モンスター図鑑
        call_enemy_guide_flag = true
      end
    end

    # モンスター図鑑に移行
    if call_enemy_guide_flag
      Sound.play_decision
      $scene = Scene_Music.new
      return
    end

    update_command_selection_music_room
  end
end
#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Dale a ver qué tal y dices, salut,
Orochii Zouveleki
avatar
orochii
Reportero

0/3

Créditos 7724

Gracias : 436

Volver arriba Ir abajo

RPG Maker VX Re: [VX] Problema con Script de Reproductor de Música

Mensaje por Oscar92player el 2013-08-26, 18:10

@orochii escribió:wltr3565, el de Cruna Aktrid C:.
===
El problema de las letras, ese de que queden rombos interrogativos (?), es porque la Ñ, así como cualquier otra letra con acento así como los kanjis son letras de dos bytes (digamos que dos caracteres xD). Es algo así como n~, a´, etcétera, sólo que al mostrarlo Ruby hace su magia y los junta xd (en realidad usan caracteres especiales, sino en un texto escribes ~enterbrain~ y te saldría ~enterbraiñ xD).
Eso lo pude solucionar, hice un pequeño malabar.
También solucioné el bug de que cuando el nombre de la música estaba vacío, no hiciera el cambio. En teoría debería funcionar todo bien xD.
Código:
=begin
================================================================================
                        Music Room ~ ZUN's Style v1.1
                                by wltr3565
================================================================================
This is mainly for my project (or shouldn't I?). Among all music room scripts
that I found, none of them sastify me. They lack commentary. Comments are very
important for your composers, you know, or to add more description for the
music...
================================================================================
Features:
- No need to rename the music files!
- Auto music unlock!
- Based on ZUN's music room:
' That he usually add comments,
' That he usually lets the players to play locked musics,
' That he usually gives the music name different from the actual file's name,
' That he sometimes doesn't list some songs...
- Auto command install on title! (Thanks to KGC)
- Commentary format is like normal message in the events!
- Checks between existing savefiles!
================================================================================
How it will work:
This script tracks the musics that was listed and played, for later to be
replayed in the Music Room Scene. The script detects the unlocked musics between
existing savefiles. You can play the unlocked ones, but to play the locked ones,
you can't just select it once, but twice for your own safety
(spoilers possible!).
================================================================================
How to Use:
There's some event commands for controlling the music locks. What's between []
is optional:

- $game_system.music_flag[id] = control
That one will control the flag of the musics' lock. id is the music's id, from
the set order. control is the control between true or false. true will unlock
the music, regardless, and false will lock the music, regardless.

- $game_system.music_unlocked?(id)
Checks if the music is alread unlocked. id is the music's id, from the set
order. Use it for conditional branches.

- $game_system.music_unlock_all
This command will make all of the musics available to be unlocked.

- $scene = Scene_Music.new[(file, call)]
This command will call the music room. File represents the saveslot for
obtaining the information from the assigned slot. call represents the target
Scene for coming back. The default is title. If you assign the call "Map", will
bring you back to the map. If you insert the file nil, will check all existing
saveslots.
More functions can be seen in the configurations below.
================================================================================
Install:
Insert below title-related scripts and above main.
================================================================================
Terms of Use:
Credit me, wltr3565. Free to use in commercial games as long I'm being credited.
Crediting who I thanked will be a good idea.
================================================================================
Thanks:
ZUN: His games and musics :P, and main inspiration.
KGC: Method for adding command in the menu.
================================================================================
=end
#===============================================================================
#   COMMENCING COMPATIBILITY FLAG
#===============================================================================
$imported = {} if $imported == nil
$imported["wltr3565's_Music_Room"] = true
#===============================================================================
#   END COMPATIBILITY FLAG
#===============================================================================
module WLTR
  module MUSIC_ROOM_SETUP
    MUSICS = [ # Don't touch
#===============================================================================
# List of musics available at the music room. Write their filename in a string,
# and be sure to add "," without the quotation for each musics, like this:
# Town1,
# Battle2,
#===============================================================================
    "Town5", # Music 1,
    "Field1", # Music 2,
    "Battle1", # Music 3 and so forth.
    "st31",
    "th06_15",
#===============================================================================
    ] # Don't touch
    
    MUSICS_NAME = [# Don't touch
#===============================================================================
# Each musics' name to be shown at the music room. Write it in a string. It will
# be used at each assigned musics in the same order, like this:
#        filename                                name
#        "Town1",                             "Melancholy",
#       "Battle2",                             "Battling",
# At the music room, the Town1 music will have it's name shown as Melancholy,
# and Battle2 as Battling.
#===============================================================================
    "Town5", # Music 1,
    "Field1", # Music 2 and so forth.
    "Battle1",
    "Beloved Tomboyish Girl",
    "U.N. Owen Was Her?!",
#===============================================================================
    ] # Don't touch
    
    MUSICS_COMMENT = [] # << EXTREMELY DO NOT TOUCH!
    
#===============================================================================
# In here you can make comments for the musics listed. The format for writing
# them is almost the same as the normal message in text events. To make one,
# do this:
# MUSICS_COMMENT[id] = comment
# The id represents the music's order from 0 that listed above. comment is the
# comment. Be sure to close the text with "". You can use | for making new lines
# other than using enter. Example:
#
# MUSICS_COMMENT[0] = "What we usually hear while testing our game...
# You guys must be bored."
# The Town1 music (from the example list of above) will show it's comments like
# this:
# What we usually hear while testing our game...
# You guys must be bored.
#
# Doesn't make one will make the comment empty.
#===============================================================================
    MUSICS_COMMENT[0] = "VX RTP's music. Commonly used for title screen.
    
Enterbraiñ á just prefer this music for new projects' title theme.
But really, why don't they name it \"Title\" or something more
fit other than \"Town5\"?"

    MUSICS_COMMENT[1] = "VX RTP's music.
    
I do like this one personally, too bad, I'm not even sure what's
the best situation for using this piece... No need to answer
this, really."

    MUSICS_COMMENT[2] = "VX RTP's music. The default battle theme.

Enterbrain do made 4 battle themes for us to use, but they
selected this for the default. Because of the default battle
system?"

    MUSICS_COMMENT[3] = "~ Beloved Tomboyish Girl ~
Composed by ZUN, Cirno's theme from TH12.3.

This piece was not made purely by ZUN himself, it's rearranged
by Tasofro's composer.
I love this theme! The theme's so stupid, but cool at a time.
One of the best Tasofro's Touhou music remix, I guess."
    
    MUSICS_COMMENT[4] = "~ U.N. Owen Was Her?! ~
Composed by ZUN, Flandre Scarlet's theme from TH06.

One of ZUN's most loli-tastic musics. The theme's very chaotic
aswell. Really Touhou-like.
This one's the MIDI version. I prefer the MIDI version compared
to the WAV  version because the MIDI version more fit for RPG
games..."
    
#===============================================================================

#===============================================================================
# Comment for a locked music, to warn the players that the music is not yet
# unlocked in the game. The format for writing it is the same.
#===============================================================================
    EMPTY_COMMENT = "*** The selected music has not yet been played in the game. ***

      The comments may contain spoiler, as well as the music
itself. Select the music again to play the music, or select
another music."
#===============================================================================

#===============================================================================
# Letter used to mark that the music is not yet unlocked. Write it in a string.
# Example: Melancholy will show ?????????? if it's not yet unlocked and the
# UNKNOWN_WORD is "?".
#===============================================================================
    UNKNOWN_WORD = "?"
    
#===============================================================================
# The music room texts' font size. The higher the number, the bigger the
# the letters. Write it in a number. Suggested that the font size is not 20, but
# 16.
#===============================================================================
    FONT_SIZE = 16
    
#===============================================================================
# Custom background for the music room. Leave it "" if you don't want to use
# one. The background image must be located in Graphics/System folder.
# To note tha if you want to use a background, the big window that shows the
# music room's name at the top-left of the screen will vanish.
#===============================================================================
    BACKGROUND = ""
    
#===============================================================================
# The music room's name shown in the commands. Write it in a string.
#===============================================================================
    MUSIC_ROOM_NAME = "Music Room"
    
#===============================================================================
# This will check if you want to let the music unlocked while played in the
# music room, while the music itself is not yet unlocked.
# true  : Let it unlocked.
# false : Don't unlock it.
#===============================================================================
    SPOIL_UNLOCK = false
    
#===============================================================================
# This will check if you can play a locked music after you select it twice.
# true  : Play it.
# false : Don't play it.
#===============================================================================
    LOCK_PLAYABLE = true
    
#===============================================================================
# Checks if you want the command to be useable for title screen.
# true  : Add it.
# false : Don't add it.
#===============================================================================
    ADD_TO_MENU = true
    
#===============================================================================
# The switch for limiting the accessibility of the music room at the title
# screen. Set the id. If the assigned switch is on, the command will show.
# If it's off, will not show. Useless if ADD_TO_MENU is false. Set below to nil
# if you want the music room accessable at anytime.
#===============================================================================
    TITLE_SWITCH = 1
    
#===============================================================================
# Number of columns that you want to have for the list.
#===============================================================================
    COLUMNS = 2
  end
end

"=============================================================================="
"   BELOW IS TOO DANGEROUS TO READ WITHOUT PROPER SCRIPTING SKILLS. THEREFOR,  "
"                            EDIT AT YOUR OWN RISK!                            "
"=============================================================================="

class Game_System
  attr_reader :music_list
  attr_accessor :music_flag
  attr_accessor :spoiler
  alias initialize_musics initialize unless $@
  def initialize
    initialize_musics
    
    @spoiler = false
    @music_list = WLTR::MUSIC_ROOM_SETUP::MUSICS
    @music_flag = []
    for i in 0..@music_list.size - 1
      @music_flag[i] = false
    end
  end
  
  def music_unlocked?(id)
    return @music_flag[id]
  end
  
  def music_unlock_all
    for i in 0..@music_list
      @music_flag[i] = true
    end
  end
end

module RPG
  class BGM < AudioFile
    alias play_check play unless $@
    def play
      if !@name.empty?
        check = $game_system.music_list.index(@name)
        $game_system.music_flag[check] = true unless ($game_system.spoiler)||(check == nil)
      end
      play_check
    end
  end
end

class Scene_Music < Scene_Base
  def initialize(file = nil, call = "Title")
    @last_bgm = RPG::BGM.last
    @index = 0
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @file = file
    @call = call
    @spoil = false
    $game_system.spoiler = true if !WLTR::MUSIC_ROOM_SETUP::SPOIL_UNLOCK
  end
  
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
  
  def start
    super
    create_menu_background
    if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
      @background = Sprite.new
      @background.bitmap = Cache.system(WLTR::MUSIC_ROOM_SETUP::BACKGROUND)
    else
      @background = Window_Base.new(0, 0, 272, 60)
      @background.contents.draw_text(0, 0, 272, 24, WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    end
    @viewport = Viewport.new(0, 0, 544, 416)
    @music_list = Window_Music_List.new(0, 60, 272, 416 - 260, @file)
    @music_list.viewport = @viewport
    @comment = Window_Comment.new(0, 416 - 200, 544, 200)
    @comment.viewport = @viewport
    @spoil = true if $game_system.music_flag[0] == false
    @comment.refresh(@spoil)
    @spoil = false
    @index = @music_list.index
  end

  def terminate
    super
    dispose_menu_background
    @music_list.dispose
    @comment.dispose
    @background.dispose if @background != nil
  end

  def return_scene
    eval("$scene = Scene_" + @call + ".new")
    $game_system.spoiler = false
    @last_bgm.play
  end

  def update
    super
    update_menu_background
    @music_list.update
    @comment.update
    update_music
  end
  
  def update_music
    @spoil = false if @music_list.index != @index
    @index = @music_list.index if @music_list.index != @index
    if Input.trigger?(Input::C)
      if @available_musics[@music_list.index] == true
        bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
        bgm.play
        @spoil = false
        @comment.id = @music_list.index
        spoil = false
        spoil = true if !$game_system.music_flag[@music_list.index]
        @comment.refresh(spoil)
      else
        if @spoil == false
          RPG::BGM.stop
          @comment.id = @music_list.index
          @comment.refresh
          @spoil = true if WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
        else
          return if !WLTR::MUSIC_ROOM_SETUP::LOCK_PLAYABLE
          bgm = RPG::BGM.new($game_system.music_list[@music_list.index])
          bgm.play
          @comment.id = @music_list.index
          @spoil = false
          @comment.refresh(true)
          @music_list.refresh if !$game_system.spoiler
        end
      end
    elsif Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(Input::X)
      RPG::BGM.stop
    elsif Input.trigger?(Input::Y)
      RPG::BGM.fade(600)
    end
  end
end

class Window_Music_List < Window_Selectable
  def initialize(x, y, width, height, file = nil)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @column_max = WLTR::MUSIC_ROOM_SETUP::COLUMNS
    if @column_max > 1
      self.width += 272
    end
    @available_musics = []
    for i in 0..WLTR::MUSIC_ROOM_SETUP::MUSICS.size - 1
      @available_musics[i] = false
    end
    if file == nil
      for i in 0..3
        @filename = make_filename(i)
        load_musicdata
        next if !@file_exist
        counter = 0
        for flag in @game_system.music_flag
          if flag == true
            @available_musics[counter] = true
          end
          counter += 1
        end
      end
    elsif @file != 0
      @filename = make_filename(file)
      load_musicdata
      counter = 0
      for flag in @game_system.music_flag
        if flag == true
          @available_musics[counter] = true
        end
        counter += 1
      end
    end
    counter = 0
    for flag in $game_system.music_flag
      if flag == true
        @available_musics[counter] = true
      end
      counter += 1
    end
    @index = 0
    refresh
  end
  
  def refresh
    self.contents.clear
    @data = WLTR::MUSIC_ROOM_SETUP::MUSICS_NAME
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      rect.width -= 4
      name = item
      known = @available_musics[index]
      if !known
        count = name.size + 1
        name = ""
        for i in 1...count
          name += WLTR::MUSIC_ROOM_SETUP::UNKNOWN_WORD
        end
      end
      rect.width -= 4
      self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
      self.contents.draw_text(rect.x, rect.y, 24, rect.height, sprintf("%2d:", index + 1), 2)
      self.contents.draw_text(rect.x + 24, rect.y, self.width - 32, rect.height, name)
    end
  end
  
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_musicdata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
  end
end

class Window_Comment < Window_Base
  attr_accessor :id
  def initialize(x, y, width, height, id = 0)
    super(x, y, width, height)
    self.opacity = 0 if WLTR::MUSIC_ROOM_SETUP::BACKGROUND != ""
    @id = id
    self.contents.font.size = WLTR::MUSIC_ROOM_SETUP::FONT_SIZE
    pre_start
    refresh
  end
  
  def pre_start
#===============================================================================
# Insert a code or two here if you want to do something before the first refresh
# starts.
#===============================================================================

#===============================================================================
  end
  
  def pre_refresh
#===============================================================================
# Insert a code or two here if you want to do something before the refresh
# starts.
#===============================================================================

#===============================================================================
  end
  
  def refresh(spoil = false)
    pre_refresh
    @x = 0
    @y = 0
    self.contents.clear
    text = WLTR::MUSIC_ROOM_SETUP::MUSICS_COMMENT[@id]
    text = WLTR::MUSIC_ROOM_SETUP::EMPTY_COMMENT if !$game_system.music_unlocked?(@id) and spoil == false
    text = "" if text == nil
    process = text
    text = convert_special_characters(process)
    sig = false
    @comment = []
    for i in 0...text.size
      if sig==true
        sig = false
        next
      end
      s = text[i,2]
      chr = "ñÑáéíóúàèìòùäëïöüâêîôûãõÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÃÕ"
      l = ( chr.include?(s) ) ? 2 : 1
      @comment << text[i, l]
      sig = true if l==2
    end
    update
  end
  
  def convert_special_characters(text)
    text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
    text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
    text.gsub!(/\n/i) { "|" }
    return text
  end
  
  def update
    super
    word = @comment.shift
    return if word == nil
    case word
    when "|"
      @x = 0
      @y += self.contents.text_size(word).height
    else
      self.contents.draw_text(@x, @y, 40, WLH, word)
      width = self.contents.text_size(word).width
      @x += width
    end
  end
end

#==============================================================================
# ■ Window_Command
#==============================================================================
# Stole this from KGC...
class Window_Command < Window_Selectable
  unless method_defined?(:add_command)
  #--------------------------------------------------------------------------
  # ○ コマンドを追加
  #    追加した位置を返す
  #--------------------------------------------------------------------------
  def add_command(command)
    @commands << command
    @item_max = @commands.size
    item_index = @item_max - 1
    refresh_command
    draw_item(item_index)
    return item_index
  end
  #--------------------------------------------------------------------------
  # ○ コマンドをリフレッシュ
  #--------------------------------------------------------------------------
  def refresh_command
    buf = self.contents.clone
    self.height = [self.height, row_max * WLH + 32].max
    create_contents
    self.contents.blt(0, 0, buf, buf.rect)
    buf.dispose
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを挿入
  #--------------------------------------------------------------------------
  def insert_command(index, command)
    @commands.insert(index, command)
    @item_max = @commands.size
    refresh_command
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ コマンドを削除
  #--------------------------------------------------------------------------
  def remove_command(command)
    @commands.delete(command)
    @item_max = @commands.size
    refresh
  end
  end
end

class Scene_Title < Scene_Base
  def make_filename(file_index)
    return "Save#{file_index + 1}.rvdata"
  end
  
  def load_cleardata
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      begin
        @characters     = Marshal.load(file)
        @frame_count    = Marshal.load(file)
        @last_bgm       = Marshal.load(file)
        @last_bgs       = Marshal.load(file)
        @game_system    = Marshal.load(file)
        @game_message   = Marshal.load(file)
        @game_switches  = Marshal.load(file)
      rescue
        @file_exist = false
      ensure
        file.close
      end
    end
    if @file_exist and WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      @unlock_flag = @game_switches[WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH] unless @unlock_flag == true
    end
  end
  
  # Stole this from KGC's enemy guide.
  if WLTR::MUSIC_ROOM_SETUP::ADD_TO_MENU
  #--------------------------------------------------------------------------
  # ● コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias create_command_window_item_almanac create_command_window unless $@
  def create_command_window
    create_command_window_item_almanac

    return if $imported["CustomMenuCommand"]
    for i in 0..3
      @filename = make_filename(i)
      load_cleardata
    end
    if WLTR::MUSIC_ROOM_SETUP::TITLE_SWITCH != nil
      return if !@unlock_flag
    end
    @__command_music_room =
      @command_window.add_command(WLTR::MUSIC_ROOM_SETUP::MUSIC_ROOM_NAME)
    if @command_window.oy > 0
      @command_window.oy -= Window_Base::WLH
    end
  end
  end
  #--------------------------------------------------------------------------
  # ● コマンド選択の更新
  #--------------------------------------------------------------------------
  alias update_command_selection_music_room update unless $@
  def update
    current_menu_index = @__command_music_room
    call_item_almanac = false

    if Input.trigger?(Input::C)
      case @command_window.index
      when @__command_music_room  # モンスター図鑑
        call_enemy_guide_flag = true
      end
    end

    # モンスター図鑑に移行
    if call_enemy_guide_flag
      Sound.play_decision
      $scene = Scene_Music.new
      return
    end

    update_command_selection_music_room
  end
end
#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Dale a ver qué tal y dices, salut,
Orochii Zouveleki

Gracias por responder tan pronto, Orochii.
Siento no haber podido responderte antes, porque tengo problemas con internet y estoy limitado a usarlo únicamente entre semana.

Todavía no lo he probado, pero de un momento a otro haré la prueba y te avisaré si va todo bien.
Muchas gracias por la ayuda, se agradece.

Óscar92player.


EDIT: Un trabajo increíble, Orochii. Los dos fallos están más que solucionados.
Y como lo prometido es deuda, tu nombre aparecerá en los créditos de nuestro juego.

He aquí una imagen de esos créditos preliminares:


Ya llevamos 4 años con el juego y aún no vamos ni por la mitad, pero espero que algún día el juego y esa imagen de los créditos que acabo de mostrarte puedan ver la luz xDD

No puedo hablar mucho más del proyecto, porque el director aún no está de acuerdo en publicar noticias tan pronto, debido a que sólo está desarrollado un pequeño porcentaje de la historia y la jugabilidad.
(En resumen, que llevamos tan poco hecho en 4 años que aún no queremos mostrar lo poco que hay para no dar falsas ilusiones xDD).

De hecho, y no quisiera extenderme mucho más en eso, no nos gustaría a mis compañeros y a mí que nuestro juego acabase en la papelera como ocurrió con el Valkyrie Stories de Hanzo Kimura. Fue un golpe enorme, después de ver lo bien que estaba hecho y lo mal que terminó.

Orochii, muchas gracias por prestarnos tu ayuda. La necesitábamos.notworthy
avatar
Oscar92player
Principiante
Principiante

0/3

Créditos 346

Gracias : 39

Volver arriba Ir abajo

RPG Maker VX Re: [VX] Problema con Script de Reproductor de Música

Mensaje por orochii el 2013-08-27, 00:19

Ajajajajaja, vaya, si me muero mañana y no termino mi Dreki, igual mi nombre quedará inmortalizado en algo, ¡huzzah! Esperen, ya voy a jugar de peligroso en la calle 8D.

Bromas aparte, pues, gracias. Igual, si quieres pónme en letras más pequeñas, que tampoco fue la gran cosa xD (además el contraste hará que los ojos de todos caigan en mi nombre, estrategia > pomposidad >=DD).

Ahora sí fuera bromas, me alegra que vaya bien, les dejo su manera de agradecer a su escogencia. Igual ahí estaré esperando el juego, se oye algo grande C:.

Salut,
Orochii Zouveleki
avatar
orochii
Reportero

0/3

Créditos 7724

Gracias : 436

Volver arriba Ir abajo

RPG Maker VX Re: [VX] Problema con Script de Reproductor de Música

Mensaje por Oscar92player el 2013-08-27, 16:07

Puff, con lo bien que iba, ahora encuentro otro fallo.

Resulta que el problema del mapa configurado para que no suene ninguna música ni efecto de ambiente está resuelto, pero a medias.

Cuando abro el reproductor de música en un mapa así, todo va perfecto excepto cuando el reproductor se cierra, porque empieza a sonar de nuevo la música del mapa anterior xDD

¿Sería mucha molestia si te pidiera de nuevo ayuda, Orochii?
avatar
Oscar92player
Principiante
Principiante

0/3

Créditos 346

Gracias : 39

Volver arriba Ir abajo

RPG Maker VX Re: [VX] Problema con Script de Reproductor de Música

Mensaje por Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba


Permisos de este foro:
No puedes responder a temas en este foro.