Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Berans

1
Berans' Interactive Piano Script
Authors: Berans, Blizzard
Version: 1.12
Type: Interactive Music Player
Key Term: Misc System



Introduction
This script creates a virtual piano keyboard to play some tunes on. It makes use of Custom Game Controls in "Tons of Add-ons" by Blizzard to allow full keyboard functionality.
Now included "code input" functionality


Features


  • 4-octave, 48 key, piano keyboard
  • Graphics and Sound samples supplied in the demo
  • Uses Custom Game Controls from "Tons of Add-ons" by Blizzard
  • Virtually lagfree
  • Hours of fun
  • NEW: Now features brand-new "Code Input" functionality



Screenshots

Spoiler: ShowHide






Demo

Demo
New demo, version 1.12 ^_^


Script


Spoiler: ShowHide

#==============================================================================
#==============================================================================
#Berans' "Interactive Piano" script v1.12
#Last edited: 24 August 2008
#
#------------------------------------------------------------------------------
#What's new in v1.12
# - Improved parsing so that codes longer than 1 line will no longer give
#   problems
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.11
# - Script now features support for "input codes"
# - Raises an error when Tons of Add-ons is not installed
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#
#This script creates an interactive piano to play with. It makes use of
#Blizzard's Custom Game Controls from his "Tons of Add-ons" script, to allow
#for all different keyboard inputs.
#
#Credits: Berans    - Creating the script, graphics and sounds
#         Blizzard  - For use of his Custom Game Controls from "Tons of Add-ons"
#------------------------------------------------------------------------------
#Features
#------------------------------------------------------------------------------
# - 4-octave keyboard (48 keys)
# - Graphics and sound samples included
# - Uses Custom Game Controls from "Tons of Add-ons" by Blizzard
# - Virtually lagfree
# - Loads of fun ;)
# - NEW: You can now use the piano to input codes
#------------------------------------------------------------------------------
#Compatibility
#------------------------------------------------------------------------------
#This script should not have incompatibility issues with other scripts,
#including the SDK.
#This script requires the Custom Game Controls from Tons of Add-ons to operate
#properly. Unless the script is changed, the Custom Game Controls must be set up
#as in the demo.
#
#==============================================================================
#Instructions
#==============================================================================
#
#------------------------------------------------------------------------------
#Set up
#------------------------------------------------------------------------------
# - Download the demo of script was obtained separately
# - Copy Audio files from the "Audio/BGM" folder to your own project
# - Feel free to provide your own Audiofiles, provided they use the same names
# - Copy the picture files from "Graphics/Pictures" folder to your own project
# - Use the import feature to set the piano's transparant color to white
# - Use the import feature to set the "Piano Lights" transparant color to white
#   and the semi-transparant color to the other color used
# - Feel free to play around with the color used for the lights to create your
#   own feel
# - Insert this script into your own project if you haven't already done so :P
# - Insert the demo's "Tons of Add-ons" script into your project (all 3 parts)
#   if you don't have Tons of Add-ons yet. Otherwise, just replace your Custom
#   Game Controls with the one in the demo.
# - To customize the keys, just change the set-up in Tons of Add-ons.
#   It is recommended to leave the key's names the same
#   example: Instead of FS = [Key['\\']] you could make it FS = [Key['`']]
#
#------------------------------------------------------------------------------
#Using the script
#------------------------------------------------------------------------------
# - Call the scene from an event using a script call
# - Put the following in the script call "$scene = Scene_Piano.new"
#   (leave out the quotes)
# - You can change the script call as follows to create a "musical code" that
#   turns on a game switch when entered correctly
#   $scene = Scene_Piano.new(switch,code,mode) see "further instruction" below
#   for how to use this feature
#
#------------------------------------------------------------------------------
#Further instructions
#------------------------------------------------------------------------------
#
#   Using the "Code input" feature:
#   call the script with the format $scene = Scene_Piano.new(switch,code,mode)
#   replace switch with the switch number you want to have turned on by a
#   correct input. Replace code by a "musical code" of the following format:
#   'C1B1As1D1'
#   The format must include the single quotes. Everything up to the numer
#   represents a note. i.e C1 is the first C on the keyboard. Notes with an s in
#   the name represent sharps. The sharp notes include Cs,Ds,Fs,Gs and As
#   and the non-sharp notes include C-G
#   Finally, you can replace mode by either 0, 1 or 2 to have a different style
#   of inputting the code
#   mode 0 means that, if you get the code wrong, nothing happens
#   mode 1 means that, if you get the code wrong, a sound plays notifying you
#   of the wrong input, and the input starts over
#   mode 2 means that, if you get the code wrong, a sound plays and the scene
#   is quit to map
#   leaving mode out automatically uses mode 0
#==============================================================================
#==============================================================================

#==============================================================================
#**Scene_Piano
#------------------------------------------------------------------------------
#This class handles processing for the piano screen
#==============================================================================
class Scene_Piano
 #----------------------------------------------------------------------------
 #*Object initializations
 #----------------------------------------------------------------------------
 def initialize(switch = nil, string = nil, mode = 0)
   if $tons_version == nil || $tons_version < 6.56
   raise 'This script requires Custom Game Controls from Tons of add-ons.' +
         'Please get Tons of Add-ons 6.56 or higher.'
   end
   @switch = switch
   @string = ''
   unless string == nil
     @required = string.gsub("\n"){nil}
   end
   @mode = mode
 end
 #----------------------------------------------------------------------------
 #*Main processing
 #----------------------------------------------------------------------------
 def main
   #Memorize Map/Menu BGM
   $game_system.bgm_memorize
   #Fade out BGM
   $game_system.bgm_fade(2)
   #Memorize Map/Menu BGS
   $game_system.bgs_memorize
   #Fade out BGS
   $game_system.bgs_fade(2)
   #This keeps track of the animation frames for the piano's lighting effects
   @animation = []
   #create a value for @animation for each key
   for i in 0...48
     @animation.push(-1)
   end
   #Create spritesets
   @spriteset = Spriteset_Map.new
   @piano = Spriteset_Piano.new
   #Create windows
   @piano_dummy = Piano_Dummy.new
   @help_window = Window_PianoHelp.new
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   #Dispose windows and spriteset
   @spriteset.dispose
   @piano.dispose
   @piano_dummy.dispose
   @help_window.dispose
   #Restore Map/Menu BGM
   $game_system.bgm_restore
   #Restore Map/Menu BGS
   $game_system.bgs_restore
   #Ensure that events are updated if switch has changed
   $game_map.refresh
 end
 
 #----------------------------------------------------------------------------
 #*Frame update
 #----------------------------------------------------------------------------
 def update
   if Input.trigger?(Input::CTRL)
     $scene = Scene_Map.new
   end
   #Check for inputs for every different key
   if Input.trigger?(Input::ONE)
     Audio.se_play("Audio/SE/C4",100,100)
     @string += 'C4'
     @animation[21] = 0
     @piano_dummy.refresh(21)
   end
   if Input.trigger?(Input::TWO)
     Audio.se_play('Audio/SE/Cs4',100,100)
     @string += 'Cs4'
     @animation[43] = 0
     @piano_dummy.refresh(43)
   end
   if Input.trigger?(Input::THREE)
     Audio.se_play("Audio/SE/D4",100,100)
     @string += 'D4'
     @animation[22] = 0
     @piano_dummy.refresh(22)
   end
   if Input.trigger?(Input::FOUR)
     Audio.se_play("Audio/SE/Ds4",100,100)
     @string += 'Ds4'
     @animation[44] = 0
     @piano_dummy.refresh(44)
   end
   if Input.trigger?(Input::FIVE)
     Audio.se_play("Audio/SE/E4",100,100)
     @string += 'E4'
     @animation[23] = 0
     @piano_dummy.refresh(23)
   end
   if Input.trigger?(Input::SIX)
     Audio.se_play("Audio/SE/F4",100,100)
     @string += 'F4'
     @animation[24] = 0
     @piano_dummy.refresh(24)
   end
   if Input.trigger?(Input::SEVEN)
     Audio.se_play("Audio/SE/Fs4",100,100)
     @string += 'Fs4'
     @animation[45] = 0
     @piano_dummy.refresh(45)
   end
   if Input.trigger?(Input::EIGHT)
     Audio.se_play("Audio/SE/G4",100,100)
     @string += 'G4'
     @animation[25] = 0
     @piano_dummy.refresh(25)
   end
   if Input.trigger?(Input::NINE)
     Audio.se_play('Audio/SE/Gs4',100,100)
     @string += 'Gs4'
     @animation[46] = 0
     @piano_dummy.refresh(46)
   end
   if Input.trigger?(Input::ZERO)
     Audio.se_play('Audio/SE/A4',100,100)
     @string += 'A4'
     @animation[26] = 0
     @piano_dummy.refresh(26)
   end
   if Input.trigger?(Input::DASH)
     Audio.se_play('Audio/SE/As4',100,100)
     @string += 'As4'
     @animation[47] = 0
     @piano_dummy.refresh(47)
   end
   if Input.trigger?(Input::IS)
     Audio.se_play('Audio/SE/B4',100,100)
     @string += 'B4'
     @animation[27] = 0
     @piano_dummy.refresh(27)
   end
   if Input.trigger?(Input::QQ)
     Audio.se_play('Audio/SE/C3',100,100)
     @string += 'C3'
     @animation[14] = 0
     @piano_dummy.refresh(14)
   end
   if Input.trigger?(Input::WW)
     Audio.se_play('Audio/SE/Cs3',100,100)
     @string += 'Cs3'
     @animation[38] = 0
     @piano_dummy.refresh(38)
   end
   if Input.trigger?(Input::E)
     Audio.se_play('Audio/SE/D3',100,100)
     @string += 'D3'
     @animation[15] = 0
     @piano_dummy.refresh(15)
   end
   if Input.trigger?(Input::RR)
     Audio.se_play('Audio/SE/Ds3',100,100)
     @string += 'Ds3'
     @animation[39] = 0
     @piano_dummy.refresh(39)
   end
   if Input.trigger?(Input::T)
     Audio.se_play('Audio/SE/E3',100,100)
     @string += 'E3'
     @animation[16] = 0
     @piano_dummy.refresh(16)
   end
   if Input.trigger?(Input::YY)
     Audio.se_play('Audio/SE/F3',100,100)
     @string += 'F3'
     @animation[17] = 0
     @piano_dummy.refresh(17)
   end
   if Input.trigger?(Input::U)
     Audio.se_play('Audio/SE/Fs3',100,100)
     @string += 'Fs3'
     @animation[40] = 0
     @piano_dummy.refresh(40)
   end
   if Input.trigger?(Input::I)
     Audio.se_play('Audio/SE/G3',100,100)
     @string += 'G3'
     @animation[18] = 0
     @piano_dummy.refresh(18)
   end
   if Input.trigger?(Input::O)
     Audio.se_play('Audio/SE/Gs3',100,100)
     @string += 'Gs3'
     @animation[41] = 0
     @piano_dummy.refresh(41)
   end
   if Input.trigger?(Input::P)
     Audio.se_play('Audio/SE/A3',100,100)
     @string += 'A3'
     @animation[19] = 0
     @piano_dummy.refresh(19)
   end
   if Input.trigger?(Input::LBRACK)
     Audio.se_play('Audio/SE/As3',100,100)
     @string += 'As3'
     @animation[42] = 0
     @piano_dummy.refresh(42)
   end
   if Input.trigger?(Input::RBRACK)
     Audio.se_play('Audio/SE/B3',100,100)
     @string += 'B3'
     @animation[20] = 0
     @piano_dummy.refresh(20)
   end
   if Input.trigger?(Input::X)
     Audio.se_play('Audio/SE/C2',100,100)
     @string += 'C2'
     @animation[7] = 0
     @piano_dummy.refresh(7)
   end
   if Input.trigger?(Input::Y)
     Audio.se_play('Audio/SE/CS2',100,100)
     @string += 'Cs2'
     @animation[33] = 0
     @piano_dummy.refresh(33)
   end
   if Input.trigger?(Input::Z)
     Audio.se_play('Audio/SE/D2',100,100)
     @string += 'D2'
     @animation[8] = 0
     @piano_dummy.refresh(8)
   end
   if Input.trigger?(Input::F)
     Audio.se_play('Audio/SE/Ds2',100,100)
     @string += 'Ds2'
     @animation[34] = 0
     @piano_dummy.refresh(34)
   end
   if Input.trigger?(Input::G)
     Audio.se_play('Audio/SE/E2',100,100)
     @string += 'E2'
     @animation[9] = 0
     @piano_dummy.refresh(9)
   end
   if Input.trigger?(Input::H)
     Audio.se_play('Audio/SE/F2',100,100)
     @string += 'F2'
     @animation[10] = 0
     @piano_dummy.refresh(10)
   end
   if Input.trigger?(Input::J)
     Audio.se_play('Audio/SE/Fs2',100,100)
     @string += 'Fs2'
     @animation[35] = 0
     @piano_dummy.refresh(35)
   end
   if Input.trigger?(Input::K)
     Audio.se_play('Audio/SE/G2',100,100)
     @string += 'G2'
     @animation[11] = 0
     @piano_dummy.refresh(11)
   end
   if Input.trigger?(Input::L)
     Audio.se_play('Audio/SE/Gs2',100,100)
     @string += 'Gs2'
     @animation[36] = 0
     @piano_dummy.refresh(36)
   end
   if Input.trigger?(Input::COLON)
     Audio.se_play('Audio/SE/A2',100,100)
     @string += 'A2'
     @animation[12] = 0
     @piano_dummy.refresh(12)
   end
   if Input.trigger?(Input::QUOTE)
     Audio.se_play('Audio/SE/As2',100,100)
     @string += 'As2'
     @animation[37] = 0
     @piano_dummy.refresh(37)
   end
   if Input.trigger?(Input::C)
     Audio.se_play('Audio/SE/B2',100,100)
     @string += 'B2'
     @animation[13] = 0
     @piano_dummy.refresh(13)
   end
   if Input.trigger?(Input::LSHIFT)
     Audio.se_play('Audio/SE/C1',100,100)
     @string += 'C1'
     @animation[0] = 0
     @piano_dummy.refresh(0)
   end
   if Input.trigger?(Input::ZZ)
     Audio.se_play('Audio/SE/Cs1',100,100)
     @string += 'Cs1'
     @animation[28] = 0
     @piano_dummy.refresh(28)
   end
   if Input.trigger?(Input::XX)
     Audio.se_play('Audio/SE/D1',100,100)
     @string += 'D1'
     @animation[1] = 0
     @piano_dummy.refresh(1)
   end
   if Input.trigger?(Input::CC)
     Audio.se_play('Audio/SE/Ds1',100,100)
     @string += 'Ds1'
     @animation[29] = 0
     @piano_dummy.refresh(29)
   end
   if Input.trigger?(Input::V)
     Audio.se_play('Audio/SE/E1',100,100)
     @string += 'E1'
     @animation[2] = 0
     @piano_dummy.refresh(2)
   end
   if Input.trigger?(Input::BB)
     Audio.se_play('Audio/SE/F1',100,100)
     @string += 'F1'
     @animation[3] = 0
     @piano_dummy.refresh(3)
   end
   if Input.trigger?(Input::N)
     Audio.se_play('Audio/SE/Fs1',100,100)
     @string += 'Fs1'
     @animation[30] = 0
     @piano_dummy.refresh(30)
   end
   if Input.trigger?(Input::M)
     Audio.se_play('Audio/SE/G1',100,100)
     @string += 'G1'
     @animation[4] = 0
     @piano_dummy.refresh(4)
   end
   if Input.trigger?(Input::COMMA)
     Audio.se_play('Audio/SE/Gs1',100,100)
     @string += 'Gs1'
     @animation[31] = 0
     @piano_dummy.refresh(31)
   end
   if Input.trigger?(Input::DOT)
     Audio.se_play('Audio/SE/A1',100,100)
     @string += 'A1'
     @animation[5] = 0
     @piano_dummy.refresh(5)
   end
   if Input.trigger?(Input::FS)
     Audio.se_play('Audio/SE/As1',100,100)
     @string += 'As1'
     @animation[32] = 0
     @piano_dummy.refresh(32)
   end
   if Input.trigger?(Input::RSHIFT)
     Audio.se_play('Audio/SE/B1',100,100)
     @string += 'B1'
     @animation[6] = 0
     @piano_dummy.refresh(6)
   end
   #update lighting effects
   animation
   #Check for code input
   if @required != nil
     #If mode is free input
     if @mode == 0
       #If correct code was input
       if @string == @required
         Audio.se_play('Audio/SE/055-Right01',100,100)
         $game_switches[@switch] = true
         $scene = Scene_Map.new
       end
     #If mode is specific input length
     elsif @mode == 1
       #When string length is correct
       if @string.gsub(/[1-4]/){nil}.gsub(/s/){nil}.length ==
         @required.gsub(/[1-4]/){nil}.gsub(/s/){nil}.length
         if @string == @required
           Audio.se_play('Audio/SE/055-Right01',100,100)
           $game_switches[@switch] = true
           $scene = Scene_Map.new
         else
           Audio.se_play('Audio/SE/057-Wrong01',100,100)
           $game_switches[@switch] = false
           @string = ''
         end
       end
     #If mode is quit after input length
     elsif @mode == 2
       #When string length is correct
       if @string.gsub(/[1-4]/){nil}.gsub(/s/){nil}.length ==
         @required.gsub(/[1-4]/){nil}.gsub(/s/){nil}.length
         if @string == @required
           Audio.se_play('Audio/SE/055-Right01',100,100)
           $game_switches[@switch] = true
           $scene = Scene_Map.new
         else
           Audio.se_play('Audio/SE/057-Wrong01',100,100)
           $game_switches[@switch] = false
           $scene = Scene_Map.new
         end
       end
     end
   end
 end
 
 #----------------------------------------------------------------------------
 #*animation
 #----------------------------------------------------------------------------
 #Takes care of animating the keys' lighting effects
 #----------------------------------------------------------------------------
 def animation
   for i in 0...@animation.size
     if @animation[i] == 0
       #Create lighting effect for the key
       @piano_dummy.refresh(i)
     end
     #Unless animation "i" is active
     unless @animation[i] == -1
       #Progress a frame
       @animation[i] += 1
       #If animation has been on for 8 frames
       if @animation[i] == 8
         #Remove lighting effect
         @piano_dummy.clear(i)
         #Turn off the animation
         @animation[i] = -1
       end
     end
   end
 end
end

#==============================================================================
#**Spriteset_Piano
#------------------------------------------------------------------------------
#This class takes care of drawing the piano's graphics onscreen
#==============================================================================

class Spriteset_Piano
 
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize
   @viewport = Viewport.new(0,150,640,480)
   @viewport.z = 5000
   @sprite = Sprite.new(@viewport)
   @piano = RPG::Cache.picture('Piano.png')
   @sprite.bitmap = @piano
 end
 
 #----------------------------------------------------------------------------
 #*Dispose
 #----------------------------------------------------------------------------
 def dispose
   @viewport.dispose
   @sprite.dispose
 end
end


#==============================================================================
#**Piano_Dummy
#------------------------------------------------------------------------------
#This class draws the piano's lighting effects
#==============================================================================

class Piano_Dummy
 
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize
   @sprite = []
   @lights = RPG::Cache.picture('Piano Lights')
   #Create a rect for the different keys
   @rect = Rect.new(0,0,22,93)
   @rect2 = Rect.new(24,0,22,93)
   @rect3 = Rect.new(48,0,22,93)
   @rect4 = Rect.new(72,0,12,50)
 end
 
 #----------------------------------------------------------------------------
 #*Refresh
 #----------------------------------------------------------------------------
 def refresh(key)
   #create a new bitmap for the key's lighting effect
   if @sprite[key] == nil
     @sprite[key] = Sprite.new
     @sprite[key].bitmap = Bitmap.new(640,480)
     @sprite[key].z = 9999
     @sprite[key].visible = false
   end
   #Clear lighting effect to avoid overlap
   @sprite[key].bitmap.clear
   #If key is a white key
   if key < 28
     x = key * 22 + 1*(key -1)
     y = 150
     if key > 17
       x -= 1
     end
     #Create correct effect in the given bitmap
     case key % 7
     when 0
       @sprite[key].bitmap.blt(x,y,@lights,@rect)
     when 1
       @sprite[key].bitmap.blt(x,y,@lights,@rect2)
     when 2
       @sprite[key].bitmap.blt(x,y,@lights,@rect3)
     when 3
       @sprite[key].bitmap.blt(x,y,@lights,@rect)
     when 4
       @sprite[key].bitmap.blt(x,y,@lights,@rect2)
     when 5
       @sprite[key].bitmap.blt(x,y,@lights,@rect2)
     when 6
       @sprite[key].bitmap.blt(x,y,@lights,@rect3)
     end
   #If key is a black key
   else
     x = 13 + (key - 28) * 28
     y = 150
     #Create x offsets for different key groups
     if (key - 28) > 1
       x += 12
       if (key - 28) == 4
         x -= 2
       end
     end
     if (key - 28) > 4
       x += 10
     end
     if (key - 28) > 6
       x += 10
       if (key - 28) == 9
         x -= 2
       end
     end
     if (key - 28) > 9
       x += 10
     end
     if (key - 28) > 11
       x += 10
       if key - 28 == 12
         x += 2
       end
       if key - 28 == 14
         x -= 2
       end
     end
     if (key - 28) > 14
       x += 11
     end
     if (key - 28) > 16
       x += 10
       if key - 28 == 17
         x+= 2
       end
     end
     #Create correct effect in the given bitmap
     @sprite[key].bitmap.blt(x,y,@lights,@rect4)
   end
   #Make lighting effect visible            
   @sprite[key].visible = true
 end
 
 #----------------------------------------------------------------------------
 #*Dispose
 #----------------------------------------------------------------------------
 def dispose
   for i in 0...@sprite.size
     unless @sprite[i] == nil
       @sprite[i].dispose
     end
   end
 end
 
 #----------------------------------------------------------------------------
 #*clear
 #----------------------------------------------------------------------------
 #Removes the specified key's lighting bitmap when called
 #----------------------------------------------------------------------------
 def clear(key)
   if @sprite[key] != nil
     @sprite[key].dispose
     @sprite[key] = nil
   end
 end
end

class Window_PianoHelp < Window_Base
 def initialize
   super(0,0,640,64)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.draw_text(0,0,640,32,"Press the 'Ctrl' button to exit")
 end
end

Insert the script above main and under the standard scripts.
NOTE: Graphics and audio files are needed for this script to work, get them from the demo.


Instructions

Instruction inside the script


Compatibility

This is NOT compatible with custom input modules other than Blizzard's Custom Game Controls in Tons of Add-ons.
Blizzard's Custom Game Controls is required to use this script.
Other than that, this script should have no compatibility issues and will function independantly.


Credits and Thanks


  • Berans - Creating the script, graphics and audio samples
  • Blizzard - Use of his Input module and inspiration



Author's Notes

Just have fun with this. Once again, I've more or less hidden access to the scene, just for laughs.
Please credit me if you use this in a project.
2
Berans' Interactive Drumkit script
Authors: Berans, Sniper308
Version: 1.11
Type: Interactive music player
Key Term: Misc System



Introduction

Another unique script by me, inspired, and with graphics, by Sniper308. It's a little Drumkit which lets you pump out some beats ingame.


Features


  • Easy to set up
  • Can customize drum-sounds however you like
  • Graphics included
  • Fully lagfree



Screenshots

Spoiler: ShowHide



Demo

Berans' Interactive Drumkit demo v1.00


Script


Spoiler: ShowHide

#==============================================================================
#==============================================================================
#Berans' "Interactive drumkit" script v1.11
#Last edited: 24 August 2008
#
#------------------------------------------------------------------------------
#What's new in v1.11
# - Script now features support for "input codes"
# - Added instructions to customize controls
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#
#This script creates an "interactive drumkit" allowing you to play some nice
#beats within your game. It's easy to adapt to your own liking to create
#many different sounds
#
#Credits: Berans    - Making the script
#         Sniper308 - Providing the graphics and idea for the script
#
#------------------------------------------------------------------------------
#Features
#------------------------------------------------------------------------------
# -Easy set-up
# -Can change drum sounds to anything you like
# -comes with nice graphics
# -Fully lagfree
# -NEW: You can now use the drums to input codes
#------------------------------------------------------------------------------
#Compatibility
#------------------------------------------------------------------------------
#This script does not rewrite any standard methods and does not use any global
#variables. Should be compatible with anything, including the SDK
#
#==============================================================================
#Instructions
#==============================================================================
#
#------------------------------------------------------------------------------
#Setup
#------------------------------------------------------------------------------
# -Download the demo if the script was obtained separately
# -Copy the Audio files in Audio/SE to your own project, and make sure the names
#  stay the same. You can provide your own Audio files, but they must be called
#  "Tom-1","Tom-2","Tom-3","Hi-Hat" and "Bassdrum" respectively
# -Copy the picture files in Graphics/Pictures to your own project, making sure
#  the names stay the same. You can easily change the color of the "lighting"
#  effect by changing the color of the objects in "DrumsLights"
# -Import the picture files into your game, making white transparant in both
#  files, clearing the semi-transparant color for "Rock Band Drums" and making
#  the color of the main objects in "DrumsLights" semi-transparant
#
#------------------------------------------------------------------------------
#Optional
#------------------------------------------------------------------------------
#To change the drum's controls find the lines in the script below with the
#comment "Control" above them and change what's after "Input::"
#The lines correspond to the drums from left to right, followed by the bass drum
#With the standard engine's input module, possibilities to follow Input:: are:
#A,B,C,X,Y,Z,L,R,CTRL,ALT,SHIFT,F5,F6,F7,F8,DOWN,LEFT,UP and RIGHT
#Check the helpfile for what each of these corresponds to on your keyboard.
#This will also help the script functioning with a custom Input module as you
#can customize the controls to take the module into account.
#
#------------------------------------------------------------------------------
#Using the script
#------------------------------------------------------------------------------
# - To call the script, use the "script" command within any event.
#   In the script write "$scene = Scene_Drums.new", without the quotes
# - You can change the script call as follows to create a "Ryhtm code" that
#   turns on a game switch when entered correctly
#   $scene = Scene_Drums.new(switch,code,mode)
# - To use this feature, replace switch with a switch number in the game that
#   you want to affect
#   Replace code with an "input code" in the following format:
#   '14232B23B1' (include the single quotes)
#   Where 1-4 correspond to each of the drums from left to right, and B
#   corresponds to the pedal
#   Finally, you can replace mode by either 0, 1 or 2 to have a different style
#   of inputting the code
#   mode 0 means that, if you get the code wrong, nothing happens
#   mode 1 means that, if you get the code wrong, a sound plays notifying you
#   of the wrong input, and the input starts over
#   mode 2 means that, if you get the code wrong, a sound plays and the scene
#   is quit to map
#   leaving mode out automatically uses mode 0
#==============================================================================
#==============================================================================

 
#==============================================================================
#**Scene_Drums
#------------------------------------------------------------------------------
#This class handles processing for the drums screen
#==============================================================================
class Scene_Drums
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize(switch = nil,string = nil,mode = 0)
   @switch = switch
   @string = ''
   unless string == nil
     @required = string.gsub("\n"){nil}
   end
   @mode = mode
 end
 
 #----------------------------------------------------------------------------
 #*Main processing
 #----------------------------------------------------------------------------
 def main
   #Memorize Map/Menu BGM
   $game_system.bgm_memorize
   #Fade out BGM
   $game_system.bgm_fade(2)
   #Memorize Map/Menu BGS
   $game_system.bgs_memorize
   #Fade out BGS
   $game_system.bgs_fade(2)
   #This keeps track of the animation frames for the drum's lighting effects
   @animation = []
   #create a value for @animation for each drum
   for i in 0...5
     @animation.push(-1)
   end
   #Create spritesets
   @spriteset = Spriteset_Map.new
   @drums = Spriteset_Drums.new
   #Create windows
   @help_window = Window_Drumshelp.new
   @drumdummy = Drum_Dummy.new
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @help_window.dispose
   @spriteset.dispose
   @drums.dispose
   @drumdummy.dispose
   #Restore Map/Menu BGM
   $game_system.bgm_restore
   #Restore Map/Menu BGS
   $game_system.bgs_restore
   #Ensure that events are updated if switch has changed
   $game_map.refresh
 end
 
 #----------------------------------------------------------------------------
 #*Frame update
 #----------------------------------------------------------------------------
 def update
   if Input.trigger?(Input::B)
     $scene = Scene_Map.new
   end
   if Input.trigger?(Input::F5)
     Audio.se_play("Audio/SE/Tom-1",100,100)
     @string += '1'
     @animation[0] = 0
     @drumdummy.refresh(0)
   end
   if Input.trigger?(Input::F6)
     Audio.se_play("Audio/SE/Tom-2",100,100)
     @string += '2'
     @animation[1] = 0
     @drumdummy.refresh(1)
   end
   if Input.trigger?(Input::F7)
     Audio.se_play("Audio/SE/Tom-3",100,100)
     @string += '3'
     @animation[2] = 0
     @drumdummy.refresh(2)
   end
   if Input.trigger?(Input::F8)
     Audio.se_play("Audio/SE/Hi-Hat",100,100)
     @string += '4'
     @animation[3] = 0
     @drumdummy.refresh(3)
   end
   if Input.trigger?(Input::C)
     Audio.se_play("Audio/SE/Bassdrum",100,100)
     @string += 'B'
     @animation[4] = 0
     @drumdummy.refresh(4)
   end
   #update lighting effects
   animation
   #Check for code input
   if @required != nil
     #If mode is free input
     if @mode == 0
       #If correct code was input
       if @string == @required
         Audio.se_play('Audio/SE/055-Right01',100,100)
         $game_switches[@switch] = true
         $scene = Scene_Map.new
       end
     #If mode is specific input length
     elsif @mode == 1
       #When string length is correct
       if @string.length == @required.length
         if @string == @required
           Audio.se_play('Audio/SE/055-Right01',100,100)
           $game_switches[@switch] = true
           $scene = Scene_Map.new
         else
           Audio.se_play('Audio/SE/057-Wrong01',100,100)
           $game_switches[@switch] = false
           @string = ''
         end
       end
     #If mode is quit after input length
     elsif @mode == 2
       #When string length is correct
       if @string.length == @required.length
         if @string == @required
           Audio.se_play('Audio/SE/055-Right01',100,100)
           $game_switches[@switch] = true
           $scene = Scene_Map.new
         else
           Audio.se_play('Audio/SE/057-Wrong01',100,100)
           $game_switches[@switch] = false
           $scene = Scene_Map.new
         end
       end
     end
   end
 end
 
 #----------------------------------------------------------------------------
 #*animation
 #----------------------------------------------------------------------------
 #Takes care of animating the drum's lighting effects
 #----------------------------------------------------------------------------
 def animation
   for i in 0...@animation.size
     if @animation[i] == 0
       #Create lighting effect for the drum
       @drumdummy.refresh(i)
     end
     unless @animation[i] == -1
       #Progress a frame
       @animation[i] += 1
       if @animation[i] == 10
         #Remove lighting effect
         @drumdummy.clear(i)
         @animation[i] = -1
       end
     end
   end
 end
end


#==============================================================================
#**Window_Drumshelp
#------------------------------------------------------------------------------
#Help window displaying the different input possibilities
#==============================================================================

class Window_Drumshelp < Window_Base
 
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize
   super(0,0,640,64)
   self.contents = Bitmap.new(width - 32, height - 32)
   text = ["F5: Drum 1", "F6: Drum 2", "F7: Drum 3", "F8: Hi-Hat", "Enter: Bass"]
   w = self.contents.width/text.size
   for i in 0...text.size
     self.contents.draw_text(i * w,0,w,32,text[i],1)
   end
 end
end


#==============================================================================
#**Spriteset_Drums
#------------------------------------------------------------------------------
#This class takes care of drawing the drum's graphics onscreen
#==============================================================================

class Spriteset_Drums
 
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize
   @viewport = Viewport.new(35,95,640,480)
   @viewport.z = 5000
   @sprite = Sprite.new(@viewport)
   @drums = RPG::Cache.picture('Rock Band Drums.png')
   @sprite.bitmap = @drums
 end
 
 #----------------------------------------------------------------------------
 #*Dispose
 #----------------------------------------------------------------------------
 def dispose
   @viewport.dispose
   @sprite.dispose
 end
end


#==============================================================================
#**Drum_Dummy
#------------------------------------------------------------------------------
#This class draws the drum's lighting effects
#==============================================================================

class Drum_Dummy
 
 #----------------------------------------------------------------------------
 #*Object initialization
 #----------------------------------------------------------------------------
 def initialize
   @sprite = []
   @lights = RPG::Cache.picture('DrumsLights')
   #Create a rect for the drums and pedal
   @rect = Rect.new(1,1,130,130)
   @rect2 = Rect.new(1,134,130,130)
   #create a new bitmap for each drum's lighting effect
   for i in 0...5
     @sprite[i] = Sprite.new
     @sprite[i].bitmap = Bitmap.new(640,480)
     @sprite[i].z = 9999
     @sprite[i].visible = false
   end
 end
 
 #----------------------------------------------------------------------------
 #*Refresh
 #----------------------------------------------------------------------------
 def refresh(drum)
   #Clear lighting effect to avoid overlap
   @sprite[drum].bitmap.clear
   case drum
   #Get coordinates based on drum
   when 0
     x = 43
     y = 198
   when 1
     x = 170
     y = 99
   when 2
     x = 335
     y = 99
   when 3
     x = 462
     y = 198
   when 4
     x = 255
     y = 371
   end
   #Create correct effect in the given bitmap
   if drum == 4 ? @sprite[drum].bitmap.blt(x,y,@lights,@rect2) :
                  @sprite[drum].bitmap.blt(x,y,@lights,@rect)
   end
   #Make lighting effect visible            
   @sprite[drum].visible = true
 end
 
 #----------------------------------------------------------------------------
 #*Dispose
 #----------------------------------------------------------------------------
 def dispose
   for i in 0...@sprite.size
     @sprite[i].dispose
   end
 end
 
 #----------------------------------------------------------------------------
 #*clear
 #----------------------------------------------------------------------------
 #Removes the specified drum's lighting effect when called
 #----------------------------------------------------------------------------
 def clear(drum)
   @sprite[drum].bitmap.clear
 end
end

Paste this script above main and under the other standard scripts.


Instructions

Instructions in script.
NOTE: Audiofiles and images can be obtained in the demo, this script won't function properly without them


Compatibility
This script does not rewrite any standard methods and does not make use of its own global variables. It should be compatible with anything out there, including the SDK


Credits and Thanks


  • Berans - Making the script
  • Sniper308 - Inspiring the script and providing the graphics



Author's Notes

Please credit me and sniper308 if you use this in your game. Other than that, have fun with it!
I'm always open for feedback.
Also, there are two ways to access the scene in the demo, both of which are hidden ;)
you'll be able to see them easily in the editor though :p
3
iPod script
Authors: Berans
Version: 1.15-final
Type: Music Player
Key Term: Misc Add-On




Introduction

I made this script as a response to a request on a different forum, and decided it was my first script decent enough to post up here.
It simply displays a nice "iPod" graphic, and lets you pick songs to play from a list.


Features


  • Relatively easy setup
  • IPod Graphic
  • Allows for as many songs as you wish
  • Allows for author and genre names
  • Allows unlockable songs
  • Currently selected song is remembered, and saved in your save game
  • Unlocked songs saved in save game
  • Entirely Lag-free
  • Map as background
  • Option to have the current BGM change with your selected song
  • iPod menu with some for-fun, customizable options
  • NEW: iPod menu now features a "sort-by" option (title, author or genre). Your selected option is saved with your game



Screenshots



If you do not want to download the demo, save the following 2 images to your computer, and import them into your game as outlined in the script
Spoiler: ShowHide







Demo

New Demo:
iPod Demo v1.00-beta

Note: No new demo for v1.12, just paste the new script in the old demo to test functionality.


Script

The script should be placed somewhere above main, and below Scene_Debug
Spoiler: ShowHide

#==============================================================================
#==============================================================================
#Berans' "iPod" script v1.15-final
#Last edited: 12 August 2008
#
#------------------------------------------------------------------------------
#What's new in v1.15
# -Script now automatically adds any songs you have in your project to the
#  PLAYBACK list. An array in the config module allows you to also add any songs
#  from the RTP
# -Minor bugfix regarding the mute function
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.13
# -Major bugfixes and some code improvement
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.12
# -Further code improvements
# -Changed iPod menu options to include "Sorting"
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.01
# -Minor code cleanups
# -Debugging
# -Added "Back" option in the iPod menu
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v1.00
# -Added a "menu" feature on the ipod with a few small options
# -Code cleaned up
#------------------------------------------------------------------------------
#
#------------------------------------------------------------------------------
#What's new in v0.99
# -Fixed a few small glitches
# -The game now remembers whether or not you were playing a song upon exiting
#  the iPod, to accomodate BGM_CHANGER better.
# -The game now remembers and saves the BGM_CHANGER option, so it can be changed
#  ingame with a new, easy-to-use script command
#------------------------------------------------------------------------------
#
#will allow you to playback songs from a list using a simple window which looks
#like an ipod
#
#feel free to edit and change any names, provided you have changed them in your
#audio/bgm folder(this would let you have custom names drawn in the menu)
#see further instructions below
#
#Credits: Berans    - Making the script
#         Blizzard  - Lessons on scripting and scripting conventions
#         Sniper308 - Requesting the script
#------------------------------------------------------------------------------
#Features
#------------------------------------------------------------------------------
# -Allows for as many songs as you wish
# -Relatively easy setup
# -IPod Graphic
# -Allows for author and genre names
# -Allows unlockable songs
# -Currently selected song is remembered, and saved in your save game
# -Unlocked songs saved in save game
# -Entirely Lag-free
# -Map as background
# -Option to have the current BGM change with your selected song
# -NEW: BGM_CHANGER option now remembered and saved with new easy-to-use command
# -NEW: iPod menu with a few for-fun options
# -NEW: iPod menu now features a "sort" option, standard sorting now set to song
#  title(sort option is saved in save game)
# -NEW: Automatically sets up any custom songs you have to use in the script
#------------------------------------------------------------------------------
#Compatibility
#------------------------------------------------------------------------------
#Should be compatible with most scripts, including the SDK
#Since this is a beta test, please notify me if something's not working
#
#==============================================================================
#Instructions
#==============================================================================
#
#------------------------------------------------------------------------------
#Setup:
#------------------------------------------------------------------------------
#Songs in your project's "Audio/BGM" folder will automatically be setup to be
#used in the script. If you want to use songs from the RTP that aren't in your
#project's "Audio/BGM" folder, add them in the "PLAYBACK1" array in the Config
#section of the script.
#The names must be spelled exactly as in the RTP's "Audio/BGM" folder, enclosed
#in quotation marks, and separated by a comma.
#example:
#PLAYBACK = ["001-Battle01, "002-Battle02", "003-Battle03"]
#In playback initial, add the number of all the songs you want to have initially
#unlocked, separated by comma. The numbers correspond to a list of songs,
#consisting of your custom songs, arranged alphabetically followed by the RTP
#songs in the order you have specified.
#example:
#you have the custom songs "Song1", "Song2" and "Song3" in your "Audio/BGM" folder
#and have specified "001-Battle01" to be included in the list.
#song 1 will then be "Song1", 2 - "Song2" 3 - "Song3" and 4 "001-Battle01"
#The PLAYBACK_AUTHOR and PLAYBACK_GENRE "hashes" respectively hold information on
#the author and genre, of each song.
#To add an author or genre name, simply add "yoursongnumber => description"
#anywhere in the correct hash. The author's/genre's name must be enclosed in
#quotation marks, and the number and name together, separated by a comma
#If a song number is not in there, the author or
#genre are automatically set to "unkown" for that song
#example:
#PLAYBACK_AUTHOR = {20 => "the author of your 20th song",
#                   1 => "the author of your 1st song", 3 => "another author"}
#the same exact same format goes for genre
#If you want all the songs in your PLAYBACK array to be "unlocked" from the
#start, simply set "unlockables" to "false"
#If you want the "IPod" to change the currently playing BGM for a map when a
#song is selected and played, set bgm_changer to "true"
#
#------------------------------------------------------------------------------
#Required Graphics and instructions:
#------------------------------------------------------------------------------
#For this script to work properly, the following files are needed, and have to
#be placed in the "Graphics/Pictures" folder in your game:
#   -IPod.png
#   -IPod2.png
#you'll also need to import the files within your project and set the correct
#transparancies
#Transparancy for IPod.png must be set to white
#Transparancy for IPod2.png must be set to the darker shade of grey, with the
#semi-transparant color set to the lighter grey
#
#------------------------------------------------------------------------------
#Using the script
#------------------------------------------------------------------------------
#To call the script, within an event use the "script" command
#in the script write "$scene = Scene_Playback.new" (without quotation marks)
#If you want the "ipod" to return to menu upon exit, add (true) after
#Scene_Playback.new. This works well in combination with a common event with an
#item.
#
#To "unlock" a song, ensure its name is in the PLAYBACK array in the
#configuration below, then, use the "script" command in an event, and enter the
#following: "unlock_song(your_song_number)"
#The song number directly corresponds to the position in the PLAYBACK array
#example:
#Your PLAYBACK array is ["yoursong-01", "yoursong-02", "someothersong"]
#and you want to unlock "yoursong-02
#simply write "unlock_song(2)" within your script command
#
#To change the BGM_CHANGER option ingame, use the following code in an event,
#within a "script..." command: "bgm_changer(condition)" (without the quotes)
#replace the word condition with either true or false, depending on what you
#would like the option to be
#
#NOTE:
#Long song/author/genre names may look squashed. For optimal looks, try to keep
#names under 15 characters.
#==============================================================================
#==============================================================================


#==============================================================================
#Begin Configuration
#==============================================================================

module Playback
  UNLOCKABLES = true
  BGM_CHANGER = false
  PLAYBACK1 = [ "001-Battle01", "002-Battle02",   "003-Battle03",
               "004-Battle04",   "005-Boss01",     "006-Boss02",
                 "007-Boss03",   "008-Boss04", "009-LastBoss01",
              "035-Dungeon01",   "063-Slow06",]
  PLAYBACK_INITIAL = [3,8]
 
  PLAYBACK_AUTHOR = {1  => "DragonForce", 2  => "Enterbrain", 3 => "Enterbrain",
                     4  => "Enterbrain" , 5  => "Enterbrain", 6 => "Enterbrain",
                     7  => "Enterbrain" , 8  => "Enterbrain", 9 => "Enterbrain",
                     10 => "Enterbrain" , 12 => "Enterbrain", }
 
  PLAYBACK_GENRE = {1 => "Classic"}
 
#==============================================================================
#End Configuration
#==============================================================================

  PLAYBACK2 = Dir.entries("Audio/BGM")
  PLAYBACK2.delete("..")
  PLAYBACK2.delete(".")
  for i in 0...PLAYBACK2.size
    PLAYBACK2[i] = PLAYBACK2[i].gsub(/[.][A-Za-z0-9._,]+/) {nil}
  end
  PLAYBACK = PLAYBACK2.concat(PLAYBACK1)
  PLAYBACK_UNLOCKED = []
  for i in 0...PLAYBACK.size
    PLAYBACK_UNLOCKED.push nil
  end
  unless PLAYBACK_INITIAL.empty?
    for i in 0...PLAYBACK_INITIAL.size
      PLAYBACK_UNLOCKED[PLAYBACK_INITIAL[i] -1] = PLAYBACK[PLAYBACK_INITIAL[i] -1]
    end
  end
  if !UNLOCKABLES
    for i in 0...PLAYBACK.size
      PLAYBACK_UNLOCKED[i] = PLAYBACK[i]
    end
  end
  unless $game_system == nil
    unless $game_system.bgm_changer == nil
      if $game_system.bgm_changer
        BGM_CHANGER = true
      elsif !$game_system.bgm_changer
        BGM_CHANGER = false
      end
    end
  end
  $playback_list = []
  for i in 0...PLAYBACK_UNLOCKED.size
    if PLAYBACK_UNLOCKED[i] != nil
      $playback_list[i] = [Playback::PLAYBACK_UNLOCKED[i],
                           Playback::PLAYBACK_AUTHOR[i+1] == nil ? "Unkown" :
                           Playback::PLAYBACK_AUTHOR[i+1],
                           Playback::PLAYBACK_GENRE[i+1] == nil ? "Unkown" :
                           Playback::PLAYBACK_GENRE[i+1]]
    end
  end
  $playback_list = $playback_list.compact
end

#==============================================================================
#**Window_Playback
#------------------------------------------------------------------------------
#This window displays the playback screen
#==============================================================================

class Window_Playback < Window_Selectable
 
  attr_accessor  :playback_bgm
 
  def initialize
    super (212,66,216,170)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 4
    @column_max = 4
    self.z -= 100
    self.index = 0
    self.active = true
    #Get the playback bgm to draw the text right
    get_playback_bgm
    refresh
  end
 
  def refresh
    self.contents.clear
    unless $game_system.playback_list.empty?
      if $game_system.playback_list[@playback_bgm] != nil
        bgm = $game_system.playback_list[@playback_bgm][0]
      else
        @check = 0
        #check all possible songs for an unlocked entry
        loop do
          @check += 1
          @playback_bgm += 1
          @playback_bgm %= $game_system.playback_list.size
          if $game_system.playback_list[@playback_bgm] != nil
            bgm = $game_system.playback_list[@playback_bgm][0]
            break
          end
        end
      end
    else
      bgm = "No Songs Unlocked"
      $nosongs = true
    end
    if !$nosongs
      text = (@playback_bgm + 1).to_s + ": " + bgm
      if $game_system.playback_list[@playback_bgm] != nil
        text2 = "Author: " + $game_system.playback_list[@playback_bgm][1]
      else
        text2 = "Author: Unkown"
      end
      if $game_system.playback_list[@playback_bgm] != nil
        text3 = "Genre: " + $game_system.playback_list[@playback_bgm][2]
      else
        text3 = "Genre: Unkown"
      end
    else
      text = bgm
      text2 = ""
      text3 = ""
    end
    self.contents.draw_text(0,8,self.contents.width,32,text,1)
    self.contents.draw_text(0,40,self.contents.width,32,text2,1)
    self.contents.draw_text(0,72,self.contents.width,32,text3,1)
  end
 
  def update_cursor_rect
    self.cursor_rect.empty
  end
 
  def get_playback_bgm
    if $game_system.playback_bgm == nil
      @playback_bgm = 0
      $game_system.playback_bgm = @playback_bgm
    else
      @playback_bgm = $game_system.playback_bgm
    end
  end
end


#==============================================================================
#**Scene_Playback
#------------------------------------------------------------------------------
#This class handles processing for the playback window
#==============================================================================

class Scene_Playback
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :mute
 
  def initialize(frommenu = false)
    @animation_flag = false
    @mute = false
    @temp_hash = {}
    @temp_hash2 = {}
    @temp_array = []
    if $game_system.playback_list.empty?
    $game_system.playback_list = $playback_list
    end
    if $game_system.sort_option == nil
      sort(0)
      $game_system.sort_option = 0
    else
      sort($game_system.sort_option)
    end
    for i in 0...$game_system.unlocked_songs.size
      unlock_song($game_system.unlocked_songs[i]+1)
    end
    if $game_temp.mute
      @mute = true
    end
    if $game_system.bgm_changer == nil
      $game_system.bgm_changer = Playback::BGM_CHANGER
    end
    if $game_temp.playing == nil
      @playing = false
    else
      @playing = $game_temp.playing
    end
    @frommenu = frommenu
  end
 
  def main
    #ensure map/menu bgm is kept
    $game_system.bgm_memorize
    @spriteset = Spriteset_Map.new
    @spriteset2 = Spriteset_Ipod.new
    @dummy_window = Ipod_Dummy.new
    @playback_window = Window_Playback.new
    @imenu_window = Window_iMenu.new
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @playback_window.dispose
    @spriteset.dispose
    @spriteset2.dispose
    $nosongs = false
    @dummy_window.dispose
    @imenu_window.dispose
  end
 
  def update
    if @playback_window.active
      update_playback
    end
    if @imenu_window.active
      update_imenu
    end
  end
 
  def update_playback
    if @playback_window.index != @playback_window_check
      @dummy_window.refresh(@playback_window.index)
    end
    if Input.repeat?(Input::RIGHT) && @playback_window.index == 3
      $game_system.se_play($data_system.cursor_se)
      @playback_window.index = 0
      return
    end
    if Input.repeat?(Input::LEFT) && @playback_window.index == 0
      $game_system.se_play($data_system.cursor_se)
      @playback_window.index = 3
      return
    end
    if Input.trigger?(Input::C)
      #Menu
      if @playback_window.index == 0
        $game_system.se_play($data_system.decision_se)
        @playback_window.active = false
        @playback_window.index = -1
        @imenu_window.visible = true
        @imenu_window.active = true
        @imenu_window.index = 0
        @imenu_wait = true
        return
      end
      unless $nosongs
        case @playback_window.index
        #Select next
        when 1
          $game_system.se_play($data_system.decision_se)
          #select the next BGM
          #the loop allows it to skip "nil" entries to aid in unlockables
          loop do
            @playback_window.playback_bgm += 1
            @playback_window.playback_bgm %= $game_system.playback_list.size
            $game_system.playback_bgm = @playback_window.playback_bgm
            if $game_system.playback_list[$game_system.playback_bgm] != nil
              break
            end
          end
          @playback_window.refresh
          #change the currently playing song if one was already playing
          if @playing
            bgm = RPG::AudioFile.new($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)
            $game_system.bgm_play(bgm)
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
        #Play/Stop
        when 2
          if @init
            @init = false
          end
          if $game_system.playback_bgm != nil
            if !@playing
              $game_system.se_play($data_system.decision_se)
              #create BGM for playing
              bgm = RPG::AudioFile.new($game_system.playback_list[
                                       $game_system.playback_bgm][0],
                                       100,100)
              $game_system.bgm_play(bgm)
              if $game_system.bgm_changer
                $game_system.bgm_memorize
              end
            else
              $game_system.se_play($data_system.cancel_se)
              $game_system.bgm_play(nil)
            end
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
          case @playing
          when true
            @playing = false
          when false
            @playing = true
          end
        #Select Previous
        when 3
          $game_system.se_play($data_system.decision_se)
          #select the previous BGM
          #the loop allows it to skip "nil" entries to aid in unlockables
          loop do
            @playback_window.playback_bgm += $game_system.playback_list.size - 1
            @playback_window.playback_bgm %= $game_system.playback_list.size
            $game_system.playback_bgm = @playback_window.playback_bgm
            if $game_system.playback_list[$game_system.playback_bgm] != nil
              break
            end
          end
          @playback_window.refresh
          #change the currently playing song if one was already playing
          if @playing
            bgm = RPG::AudioFile.new($game_system.playback_list[
                                     $game_system.playback_bgm][0],
                                     100, 100)
            $game_system.bgm_play(bgm)
            if @mute != false
              @mute = false
              @imenu_window.refresh
            end
          end
        end
      else
        $game_system.se_play($data_system.buzzer_se)
      end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      #get the correct @playing setting for when the iPod is restarted
      if $game_system.bgm_changer
        $game_temp.playing = @playing
      else
        @playing = false
      end
      if !@frommenu
        #restore the map/menu bgm
        if !$game_system.bgm_changer
          if @mute
            $game_map.map.bgm.volume = 0
          else
            $game_map.map.bgm.volume = 100
          end
          $game_system.bgm_play($game_map.map.bgm)
        end
        $scene = Scene_Map.new
        if !@playing && $game_system.bgm_changer
          if $game_system.playing_bgm == $game_map.map.bgm
            return
          end
          $game_system.bgm_play(nil)
        end
      else
        #restore the map/menu bgm
        if !$game_system.bgm_changer
          if @mute
            $game_map.map.bgm.volume = 0
          else
            $game_map.map.bgm.volume = 100
          end
          $game_system.bgm_play($game_map.map.bgm)
        end
        #change this to go to a different menu upon exit
        $scene = Scene_Menu.new
        if !@playing && $game_system.bgm_changer
          if $game_system.playing_bgm == $game_map.map.bgm
            return
          end
          $game_system.bgm_play(nil)
        end
      end
    end
    $game_temp.playing = @playing
    @playback_window_check = @playback_window.index
    @playback_window.update
  end
 
  def update_imenu
    if @imenu_wait
      @imenu_wait = false
      return
    end
    if @imenu_window.index != @imenu_window_check
      @dummy_window.refresh(@imenu_window.index)
    end
    if Input.repeat?(Input::RIGHT)
      if @imenu_window.index == 3
        $game_system.se_play($data_system.cursor_se)
        @imenu_window.index = 0
        return
      end
    end
    if Input.repeat?(Input::LEFT)
      if @imenu_window.index == 0
        $game_system.se_play($data_system.cursor_se)
        @imenu_window.index = 3
        return
      end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @imenu_window.active = false
      @imenu_window.visible = false
      @playback_window.index = @imenu_window.index
      @imenu_window.index = -1
      @playback_window.active = true
    end
    if Input.trigger?(Input::C)
      case @imenu_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        if !@mute
          unless $game_system.playing_bgm == nil
            $game_system.playing_bgm.volume = 0
            $game_system.bgm_play($game_system.playing_bgm)
          end
          @mute = true
        elsif @mute
          unless $game_system.playing_bgm == nil
            $game_system.playing_bgm.volume = 100
            $game_system.bgm_play($game_system.playing_bgm)
          end
          @mute = false
        end
        @imenu_window.refresh
        $game_temp.mute = @mute
      when 1
        $game_system.se_play($data_system.cancel_se)
        if $game_system.bgm_changer
            $game_temp.playing = @playing
          else
            @playing = false
          end
          #restore the map/menu bgm
          if !$game_system.bgm_changer
              $game_system.bgm_play($game_map.map.bgm)
            end
          #change menu option 2 here
          $scene = Scene_Map.new
          if !@playing && $game_system.bgm_changer
            if $game_system.playing_bgm == $game_map.map.bgm
              return
            end
            $game_system.bgm_play(nil)
          end
      when 2
        if $nosongs
          $game_system.se_play($data_system.buzzer_se)
          return
        else
          $game_system.se_play($data_system.decision_se)
          $game_system.sort_option += 1
          $game_system.sort_option %= 3
          sort($game_system.sort_option)
          @imenu_window.refresh
          @playback_window.refresh
        end
      when 3
        $game_system.se_play($data_system.cancel_se)
        @imenu_window.active = false
        @imenu_window.visible = false
        @playback_window.index = @imenu_window.index
        @imenu_window.index = -1
        @playback_window.active = true
      end
    end
    @imenu_window.update
  end
end


#==============================================================================
#*unlock_song
#------------------------------------------------------------------------------
#Allows you to unlock songs for the playback window
#==============================================================================
def unlock_song(number)
  if $game_system.playback_list.empty?
    $game_system.playback_list = $playback_list
  end
  unless $game_system.playback_list.include?([
    Playback::PLAYBACK[number - 1], Playback::PLAYBACK_AUTHOR[number] || "Unkown",
    Playback::PLAYBACK_GENRE[number] || "Unkown"])
    for i in 0...Playback::PLAYBACK.size
      if $game_system.playback_list[i] == nil
        $game_system.playback_list[i] = [nil,nil,nil]
        $game_system.playback_list[i][0] = Playback::PLAYBACK[number - 1]
        $game_system.playback_list[i][1] =
        (Playback::PLAYBACK_AUTHOR[number] == nil ?
        "Unkown" : Playback::PLAYBACK_AUTHOR[number])
        $game_system.playback_list[i][2] =
        (Playback::PLAYBACK_GENRE[number] == nil ?
        "Unkown" : Playback::PLAYBACK_GENRE[number])
        $game_system.unlocked_songs.push(number - 1)
        return
      end
    end
  end
end


#==============================================================================
#*bgm_changer
#------------------------------------------------------------------------------
#Changes the BGM_CHANGER option for ingame use
#==============================================================================
def bgm_changer(condition)
  if !condition
    if $game_system.bgm_changer
      $game_system.bgm_changer = condition
    end
  else
    $game_system.bgm_changer = condition
  end
end


#==============================================================================
#**Spriteset_Ipod
#------------------------------------------------------------------------------
#Creates an "Ipod" Image at the centre of the screen
#==============================================================================
class Spriteset_Ipod
  def initialize
    @viewport = Viewport.new(208,53,224,374)
    @viewport.z = 5000
    @sprite = Sprite.new(@viewport)
    @sprite2 = Sprite.new
    @sprite2.bitmap = Bitmap.new(224,374)
    @ipod = RPG::Cache.picture('IPod.png')
    @sprite.bitmap = @ipod
  end

  def dispose
    @viewport.dispose
    @sprite.dispose
    @sprite2.dispose
  end
end


#==============================================================================
#**Ipod_Dummy
#------------------------------------------------------------------------------
#Creates the selection effect over the ipod image
#==============================================================================
class Ipod_Dummy < Window_Base
 
  def initialize
    super(208,53,224,374)
    self.contents = Bitmap.new(width - 32,height - 32)
    self.opacity = 0
    self.z = 9999
    refresh
  end
 
  def refresh(index = 0)
    self.contents.clear
    case index
    when 0
      rect = Rect.new(0,52,98,52)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(47,179,@bitmap,rect)
    when 1
      rect = Rect.new(52,104,52,98)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(113,199,@bitmap,rect)
    when 2
      rect = Rect.new(0,0,98,52)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(47,266,@bitmap,rect)
    when 3
      rect = Rect.new(0,104,52,98)
      @bitmap = RPG::Cache.picture('IPod2.png')
      self.contents.blt(26,199,@bitmap,rect)
    end
  end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles data surrounding the system. Backround music, etc.
#  is managed here as well. Refer to "$game_system" for the instance of
#  this class.
#==============================================================================
class Game_System
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_accessor :playback_bgm
  attr_accessor :unlocked_songs
  attr_accessor :bgm_changer
  attr_accessor :sort_option
  attr_accessor :playback_list
 
  alias initialize_ipod_later initialize
  def initialize
    initialize_ipod_later
    @unlocked_songs = []
    @playback_list = []
  end

end

#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_accessor :playing
  attr_accessor :mute
 
end


#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
 
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :map
 
end


#==============================================================================
# ** Window_iMenu
#------------------------------------------------------------------------------
#  This class creates a dummy selectable menu to use with the iPod script
#==============================================================================
class Window_iMenu < Window_Selectable
  def initialize
    super(212,66,216,170)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.index = -1
    self.visible = false
    self.active = false
    self.z += 10
    @item_max = 4
    @column_max = 4
    refresh
  end
 
  def refresh
    self.contents.clear
    if $scene.mute
      self.contents.draw_text(0,-5,self.contents.width,32,"Unmute",1)
    else
      self.contents.draw_text(0,-5,self.contents.width,32,"Mute",1)
    end
    #change the bit in quotes below to reflect where your iPod menu's 2nd option
    #exits to i.e. "Exit to Main Menu" or "Exit to Equipment Screen"
    #be wary of long names, as they may look squashed
    self.contents.draw_text(0,27,self.contents.width,32,"Exit to Map",1)
    case $game_system.sort_option
    when 0
      sort = "Title"
    when 1
      sort = "Author"
    when 2
      sort = "Genre"
    end
    self.contents.draw_text(0,59,self.contents.width,32,"Sorted by: " + sort,1)
    self.contents.draw_text(0,91,self.contents.width,32,"Back",1)
  end
 
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      y = -5 + 32*@index
      cursor_rect.set(5,y,self.contents.width - 10,32)
    end
  end
 
end


#==============================================================================
#*Sort
#------------------------------------------------------------------------------
#Method to sort the unlocked songs array for the iPod script
#==============================================================================

def sort(choice)
  $game_system.playback_list =
  $game_system.playback_list.sort {|a, b| a[choice] <=> b[choice]}
  return $game_system.playback_list
end



Instructions

Instructions in the script


Compatibility

Warning, WILL corrupt old savegames.
Otherwise, should be compatible with just about anything, including the SDK


Credits and Thanks


  • Berans - Creating the script
  • Blizzard - Learnt a lot from his scripts in terms of general knowledge and scripting conventions
  • Sniper308 - For requesting the script and suggesting many of the great features
  • LandOfShadows - Use of one of his windowskins in the demo



Author's Notes

Feel free to ask me any questions and PLEASE tell me if you find a bug.
I'm also quite willing to make customizations and such for this, provided they are within reason, and I have the time.

Have fun with it people ^_^

Don't forget to credit me if you use this in your game :P
4
Welcome! / Hi everyone
July 24, 2008, 02:47:31 pm
Figure I'd officially-ish introduce myself here.
I go by Berans, my real name you shall never know :P
I like using RMXP to make fun games, especially if I can challenge myself in making them
I very recently introduced myself into the world of rubyscripting, so in the future you might see some work from me up here, or I might ask for help  :^_^':

Well...that's all for now I guess, feel free to ask me any questions.
5
I've recently started some basic scripting in RMXP, creating a CMS and some random menus to get some experience and inspiration.
I'm currently working on an item menu, and all but one of the features in it are working fine.
I want to swap from one menu to another when "UP" is pressed on the top row of the first menu, but there seems to be a small problem in my script. The transition to the other menu does work, but it also happens when I press up in the 2nd top row.
here's the update method for the menu I want to switch out of:
Spoiler: ShowHide
def update_item
    @item = @item_window.item
    @itemdesc_window.update(@item)
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu2.new(1)
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.buzzer_se)
    elsif @item_window.index < 2  && Input.repeat?(Input::UP)
      $game_system.se_play($data_system.cursor_se)
      @item_window.active = false
      @keyitemstitle_window.active = true
      @keyitemstitle_window.index = 0
      @item_window.index = -1
    end
  end


I've looked at some other people's menus, doing similar things, but I can't figure out why mine is not working, because it seems very similar. I've tried using Input.trigger? instead of Input.repeat? I've also changed my update_cursor_rect method to someone else's (from a menu where the feature was working) but to no avail. I was wondering if someone could help me with that.

In a nutshell: even though the menu is only supposed to change on the top row (when the index is 0 or 1) it also does it on the row below it.
I did notice, however,that it is briefly on the top row after I press up on the second row, since it very briefly shows me the top row's item description in my help window.