Berans' Interactive Drumkit script
Authors: Berans, Sniper308
Version: 1.11
Type: Interactive music player
Key Term: Misc System
IntroductionAnother 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(http://img396.imageshack.us/img396/7174/drumdemoscreenshotbb5.png)
DemoBerans' Interactive Drumkit demo v1.00 (http://www.mediafire.com/?gam9hhzpzhc)
Script
#==============================================================================
#==============================================================================
#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.
InstructionsInstructions in script.
NOTE: Audiofiles and images can be obtained in the demo, this script won't function properly without them
CompatibilityThis 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 NotesPlease 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
As being the rhythmatic person I am, I had some fun with the drum beats. Though this seems more like a fun gimmick to keep your mind off the game rather than a useful tool to continue on a game or something...Is there a way to script this to incorperate a secret code? And how creative, Rock Band Drums...
cool!! though I don't see how it could be useful other than fun but there is nothing wrong with fun!
PS: i love Rock Band
This was never meant to be useful lol...I scripted this in under an hour. The thing that took the longest was positioning all the graphics right :P
I'll see if I can cook something up for a "rythm code" though, that could be fun. I'm not sure how easy it would be...hmmmm
lol! Great work Berans :clap: *powers up*
I'm downloading it now.
Hey Berans, apply the new template from now on. It has the "Key Term" in the header. :)
Will do. Gotto keep up with the times I guess :P
Quote from: Blizzard on January 07, 2008, 08:51:26 pm
3.
The Key Terms mentioned in the header of the topics are:
*LIST*
These Key Terms allow that your script is listed on the homepage appropriately. If you leave it out or don't use it at all, your script will not be listed in the script index. Do not edit any Key Term, they have to be written exactly as here. More than one term is not allowed.
You want that to happen, don't you? :naughty:
EDIT: BTW, have you though about making a Piano script using all keys? You can use my Custom Controls add-on from Tons of Add-ons for that. :)
EDIT: Oh, and use spoilers for images. xD
im a fan of the drum kit and iv played it for some years so im defintly going to add it to my prodject just becuase i like it.
great script
I HAVE thought about making a piano script actually...it won't be any harder than making this, I just need to figure out a relatively intuitive way to do it, which is challenging with a keyboard.
Who knows, within the next few days you might see one coming your way ;)
You could use each row of keys for one octave.
1. the number row
2. the qwerty row
3. the asdfgh row
4. he zxcvbn row
True, it would only have only 4 octaves, but it might still be better than just one octave on a more piano like keyboard (z-s-x-d-c-f-g-b-h-n-j-m letters as c-c#-d-d#-e-f-f#-g-g#-a-a#-h).
That's not a bad idea at all. Gives a whole new meaning to the word "keyboard" when referring to an instrument lol...Who knows maybe it'll be the next instrument o.O
Quick question though, does your input module differentiate between the 2 separate shift keys? Because, including the black keys, an octave will have 12 keys.
Yes, it does. One LShift is 160 and RShift 161 I think. Just check the key definitions.
I tried making this long ago and the game crashed -_-
But good luck Berans, I'd really like to see a Piano script, because I'm also a Pianist ;)
Well waddaya know, so am I XD
I actually had a crash as well, because I tried to create a lot of bitmaps at once lol...for some reason the bug seems to have stopped now, but we'll see what happens when it's finished
If I remember right, the game crashed because something was wrong with the Audio module. I think I tried to play too many keys at once, or... I don't know. btw, I checked out the demo, good job on it. Though:
1) The event is invisible, I talked to the guy first and had to search for the drumkit XD
2) Instead of the function keys, can you probably use the L, R, X, Y, Z keys? Or maybe just let the player decide it (through script config or even a scene if you feel like it).
I know the event is invisible lol...I did it as something of a joke :P
He IS called "Invisible man" after all.
I thought the function keys were handy due to the fact that they're nicely positioned next to eachother. But I could probably add in a simple module or something to allow the user to set it.
It shouldn't crash playing too many sounds at once though, because it's got a filter that's supposed to stop it from playing if too many sounds are played. Or maybe that's just if the same sound is played over and over very quickly...I can't quite remember. Either way, I'm not seemingly having any problems with that
@FTS: Did you use PKE back then? Then the crash makes perfect sense if you used a keyboard script.
@Berans: Were you trying to create a bitmap with width = 0 and/or height = 0? xD
Quote@FTS: Did you use PKE back then? Then the crash makes perfect sense if you used a keyboard script.
A
HA! That must be it!
@Berans: Yeah, I DID chuckle a bit :D
I'm not trying to create any such bitmaps, it was actually my graphics card that gave me an error o.O
It creates 48 bitmaps at once...which I probably shouldn't be doing. I just used the exact same system as the drums where it creates a bitmap for each separate lighting effect so that I can easily animate it. When I now open the "piano" and close it several times in quick succession, my computer has a great deal of trouble with things XD.
I'll probably have it only create the bitmaps when I actually need them.
UPDATED to version 1.11, now with "Rythm codes"
O.o; Yes, that's a weird problem. At least you don't have it anymore. xD
I've created a workaround for it now. It only creates the bitmap when a key is pressed the first time. That way it doesn't have to make them all at the same time, seems to fix the lag/hanging issue pretty much completely, but we'll see what happens when I have alll 48 keys set up lol...I might have to also dispose of the bitmap every time the animations finished. I'm not sure.
EDIT: So far so good, except for one rather annoying issue. The forward slash key doesn't seem to be registering with your input module. I've set it up like
but when I ask for Input::SLASH it doesn't register at all...any ideas?
All the other keys seem to be working correctly
EDIT2: It appears I've managed to fix it through sheer accident. I'm not sure if this is unique to my computer, but the backslash and forward slash characters were swapped. i.e. If a a key up as forward slash, the input command would only register with a backslash and vice versa.
I'm gonna post up my script in a second, once I put the finishing touches on the demo :P
Try this: Cache all bitmaps. This will not cause lag during execution. Only using a bitmap in a sprite causes lag. Dispose the sprites you don't need, not the bitmaps. :)
The way I'm doing now seems to cause virtually no lag actually XD so I'm happy
Any reason why the forward and backslash characters were swapped in your Custom Game Controls by the way?
Maybe I messed up or something else is wrong.
I hope it's not just my computer lol...because otherwise everyone else will have a discrepancy in their keys.
Hey, i'm just a bit of a n00b when it comes to this stuff :^_^': so could you provide an example of what I should type in the "CALL SCRIPT" command?
I got the first bit "$scene = Scene_Drums.new" right. But i'm still kinda unsure with what to do with the input codes and the mode thingo, how do I put it? i.e '$scene = Scene_Drums.new (122141B)" (the 12214B being the drums, Ijustdon't know where or how to putthem in the call script...):ninja:
Thanks in advance
Since you're going to make a rhythm code, we're going to call the script a little differently.
$scene = Scene_Drums.new(switch,code,mode)
Here's where I got it from. XD
#------------------------------------------------------------------------------
#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
So here's an example code:
$scene = Scene_Drums.new(1,14232B23B1,2)
This basically says if I hit the rhythm code as 14232B23B1, then switch 1 will turn on. Otherwise, if I get it wrong, then there'll be a sound and I'll return to the map. :x