- Pokémon Essentials Version
- v18.1 ➖
Here's a little something that I put together for The Last Nurse Joy, from an idea by AnonAlpaca!
Code
Paste in a new script section above Main!
Ruby:
def pbDrawer(list)
$game_variables[2]=list
scene = Drawer.new
end
ItemArrays = [
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL],
[:POTION],
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL]
]
class Drawer
def initialize
list = $game_variables[2]
@Items=ItemArrays[list]
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@itemport = Viewport.new(88,24,340,154)
@sprites = {}
@sprites["background"] = IconSprite.new(0,0,@viewport)
@sprites["background"].bitmap = Bitmap.new("Graphics/Pictures/drawerbg")
@Column=[32,100,168,236,304]
@Row=[32,100,168,236,304]
@ColumnNo=0
@RowNo=0
@SelCol=0
@SelRow=0
@SelNo=0
@sprites["cursor"] = IconSprite.new(@Column[@SelCol]-32,@Row[@SelRow]-32,@itemport)
@sprites["cursor"].bitmap = Bitmap.new("Graphics/Pictures/drawercursor")
for i in 0...@Items.length
if @ColumnNo>4
@ColumnNo=0
@RowNo+=1
end
@sprites["itemicon #{i}"] = ItemIconSprite.new(@Column[@ColumnNo],@Row[@RowNo],0,@itemport)
@sprites["itemicon #{i}"].item=getID(PBItems,@Items[i])
if i==@SelNo
@sprites["itemicon #{i}"].opacity=255
else
@sprites["itemicon #{i}"].opacity=155
end
@ColumnNo+=1
end
main
end
def main
loop do
$game_system.menu_disabled=true
Graphics.update
Input.update
if Input.trigger?(Input::LEFT)
pbPlayDecisionSE
if @SelCol==0
@SelCol=4
@SelNo+=4
else
@SelNo-=1
@SelCol-=1
end
pbRefresh
elsif Input.trigger?(Input::RIGHT)
pbPlayDecisionSE
if @SelCol==4
@SelCol=0
@SelNo-=4
else
@SelNo+=1
@SelCol+=1
end
pbRefresh
elsif Input.trigger?(Input::DOWN)
pbPlayDecisionSE
if @SelRow==1
@SelRow=0
@SelNo-=5
else
@SelNo+=5
@SelRow+=1
end
pbRefresh
elsif Input.trigger?(Input::UP)
pbPlayDecisionSE
if @SelRow==0
@SelRow=1
@SelNo+=5
else
@SelNo-=5
@SelRow-=1
end
pbRefresh
elsif Input.trigger?(Input::C)
if @Items[@SelNo]
item=getID(PBItems,@Items[@SelNo])
name=PBItems.getName(item)
if pbConfirmMessage(_INTL("Take the {1}?",name))
#pbMessage(_INTL("Took the {1}.",name))
#$game_variables[3]=@SelNo+1
#pbReceiveItem(item)
break
else
pbRefresh
end
end
elsif Input.trigger?(Input::B)
$game_variables[3]=0
pbPlayCancelSE
break
end
end
dispose
pbWait(5)
$game_system.menu_disabled=false
end
def pbRefresh
@sprites["cursor"].x=@Column[@SelCol]
@sprites["cursor"].x-=32
@sprites["cursor"].y=@Row[@SelRow]
@sprites["cursor"].y-=32
for i in 0...@Items.length
if i==@SelNo
@sprites["itemicon #{i}"].opacity=255
else
@sprites["itemicon #{i}"].opacity=155
end
end
end
def dispose
pbDisposeSpriteHash(@sprites)
@viewport.dispose
@itemport.dispose
end
end
Using the script
There are two things you'll need to do to get this working!First- there's three lines of code commented out at the end:
Ruby:
#pbMessage(_INTL("Took the {1}.",name))
#$game_variables[3]=@SelNo+1
#pbReceiveItem(item)
pbReceiveItem(item)
. You should know that this script doesn't delete an item from your list, though, so the player can easily open up the drawer again and get another. (You could have your drawer be a one-time event, a daily bonus like the lottery, or have the player pay to look in it!)For The Last Nurse Joy, rather than give the player an item, selecting an item would usually trigger a little cutscene of Aida using the item. For this, we used the lines:
Ruby:
pbMessage(_INTL("Took the {1}.",name))
$game_variables[3]=@SelNo+1
(If you don't wanna use Global Variable 3, just change the 3 in
$game_variables[3]
to whatever you want!)Secondly, at the top of the script, there's this:
Ruby:
ItemArrays = [
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL],
[:POTION],
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL]
]
And finally, you just need files in Graphics/Pictures titled drawerbg and drawercursor! If you want the ones we used, they're in the download link!
To call this script, use
pbDrawer(list)
in an event, with list being the number of your array in ItemArrays. (Remember, the first one is 0, not 1!)Future goals
- Display the item description at the bottom of the screen (I... was actually supposed to have this done for TLNJ but I forgot)
- Create a way to set multiple backgrounds, but also still let a default background be used if there's not one for the current drawer
- Create a way to set different widths/heights of the boxes
- Create a way to set multiple SFX for opening it, so you don't have to set it in the event commands
- Create a way to scroll, so you can have more than ten items in an array
- Create a way to easily set multiple common functions for the drawer, rather than needing to program it in the event.
- ...I should probably tidy up my code where it sets Global Variable 2 to the list number and references that instead of just making it a variable in the command itself.
- Credits
- TechSkylander1518 for the code
AnonAlpaca for the concept and graphic, if used