Main Menu
  • Welcome to The RPG Maker Resource Kit.

VX map playlist

Started by Mushu, June 28, 2011, 03:10:26 PM

0 Members and 1 Guest are viewing this topic.

Mushu

With the event conditional branch>scripts could you technically code it where if song "A" is playing then wait(x) seconds before playing song "B" and how many other songs, then put it all in a loop?

modern algebra


Mushu

so how would I put it in the script? like this?
A.bgm.play
and what would I type in to recall that script action?

modern algebra

#3
Play BGM is its own event command. It doesn't require a script and Conditional Branches also are not required (though they are useful since it will be easier to copy, so I will use them - however, you could just as easily only use Wait commands

It would be like this:

@>Loop
   @>Play BGM: BGM1, 100, 100
   @>Control Variable: [XXXX: Song Length] = song length in seconds (so 180 if the song is 3 minutes long)
   @>Loop
       @>Conditional Branch: Variable [XXXX: Song Length] > 0
           @> Wait: 60 frames
           @>Control Variables: [XXXX: Song Length] -= 1
         : Else
             Break Loop
         : Branch END
      : Repeat
   # Do the same for the next song, etc...
: Repeat



You could make it even cleaner if you put the counting loop in a common event and just called it after each time you set a song.

I attached a demo, and I even made it a little snazzier to fade it out.

There is, however, a problem - it won't keep counting down if you, for instance, click outside of the window to do something else on your computer or if you call a new scene and expect to have the map music play in it. The Audio module is, sadly, pretty restrictive in general, so a scripted solution could probably solve the second issue but not the first (or rather, the amount of work involved in solving the first would give you much more sophisticated way to track the time a song has been playing and the like, so it would make this method obsolete).

Also, changing maps would naturally interfere with that method since it uses a local parallel process event, but you could fix that by putting it in a common event.

exhydra

#4
To help with the problem of people clicking outside of the window, OriginalWij's Audio Position script is very exacting. Although it doesn't work when they take focus away from the window, when they click back it can still check against the current playing time of a song.


#==============================================================================
# Audio Position
#==============================================================================
# Author : OriginalWij
# Version : 1.0
#==============================================================================

#==============================================================================
# To use:
#   call: (from a Script Event command)
#     bgm_position - gets playing BGM position in seconds (float) *
#     bgs_position - gets playing BGS position in seconds (float) *
#
#     * = returns 0 if none playing
#     examples: $game_variables[42] = bgm_position
#               RPG::BGS.stop if bgs_position > 42
#==============================================================================

#==============================================================================
# What this does:
#   allows syncing to music by position (accurate to 0.01 seconds)
#==============================================================================

#==============================================================================
# RPG
#==============================================================================

module RPG
  #============================================================================
  # BGM
  #============================================================================
  class BGM < AudioFile
    #------------------------------------------------------------------------
    # Variables                                                         [New]
    #------------------------------------------------------------------------
    @@position = 0
    @@started  = false
    #------------------------------------------------------------------------
    # Play                                                              [Mod]
    #------------------------------------------------------------------------
    alias ow_ap_rpg_bgm_play play unless $@
    def play
      ow_ap_rpg_bgm_play
     
      if @name.empty?
        @@position = 0
      else
        if @@started == false
          @@position = Time.now
          @@started  = true
        end
      end
      #@@position = @name.empty? ? 0 : Time.now
    end
    #------------------------------------------------------------------------
    # Stop                                                          [Rewrite]
    #------------------------------------------------------------------------
    def self.stop
      Audio.bgm_stop
      @@last = BGM.new
      @@position = 0
      @@started  = false
    end
    #------------------------------------------------------------------------
    # Fade                                                          [Rewrite]
    #------------------------------------------------------------------------
    def self.fade(time)
      Audio.bgm_fade(time)
      @@last = BGM.new
      @@position = 0
      @@started  = false
    end
    #------------------------------------------------------------------------
    # Position                                                          [New]
    #------------------------------------------------------------------------
    def position
      return 0 if @@position == 0
      return Time.now - @@position
    end
  end

  #============================================================================
  # BGS
  #============================================================================
  class BGS < AudioFile
    #------------------------------------------------------------------------
    # Variables                                                         [New]
    #------------------------------------------------------------------------
    @@position = 0
    @@started = false
    #------------------------------------------------------------------------
    # Play                                                              [Mod]
    #------------------------------------------------------------------------
    alias ow_ap_rpg_bgs_play play unless $@
    def play
      ow_ap_rpg_bgs_play
      @@position = @name.empty? ? 0 : Time.now
     
      if @name.empty?
        @@position = 0
      else
        if @@started == false
          @@position = Time.now
          @@started  = true
        end
      end
    end

    #------------------------------------------------------------------------
    # Stop                                                          [Rewrite]
    #------------------------------------------------------------------------
    def self.stop
      Audio.bgs_stop
      @@last = BGS.new
      @@position = 0
      @@started  = false
    end
    #------------------------------------------------------------------------
    # Fade                                                          [Rewrite]
    #------------------------------------------------------------------------
    def self.fade(time)
      Audio.bgs_fade(time)
      @@last = BGS.new
      @@position = 0
      @@started  = false
    end
    #------------------------------------------------------------------------
    # Position                                                          [New]
    #------------------------------------------------------------------------
    def position
      return 0 if @@position == 0
      return Time.now - @@position
    end
  end

end

#==============================================================================
# Game_Interpreter
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # Get BGM Position                                                    [New]
  #--------------------------------------------------------------------------
  def bgm_position
    return RPG::BGM.last.position
  end
  #--------------------------------------------------------------------------
  # Get BGS Position                                                    [New]
  #--------------------------------------------------------------------------
  def bgs_position
    return RPG::BGS.last.position
  end

end


UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5