• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
Drawer/Cabinet Script

v19 Drawer/Cabinet Script N/A

This resource pertains to version 19 of Pokémon Essentials.
Pokémon Essentials Version
v18.1 ➖
1615858308894.png
To see this script in action, check out The Last Nurse Joy!​


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:
Expand Collapse Copy
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:
Expand Collapse Copy
              #pbMessage(_INTL("Took the {1}.",name))
                #$game_variables[3]=@SelNo+1
              #pbReceiveItem(item)
If you want to just give the player the item they selected, uncomment 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:
Expand Collapse Copy
              pbMessage(_INTL("Took the {1}.",name))
                $game_variables[3]=@SelNo+1
And, in the rest of the event, we used a conditional branch to set what would happen next, like so:
1615860701381.png

(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:
Expand Collapse Copy
ItemArrays = [
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL],
[:POTION],
[:POTION,:SUPERPOTION,:HYPERPOTION,:POKEBALL,:RARECANDY,:REPEL,:ULTRABALL,:REPEL]
]
These arrays are what gets called for the contents of the drawer! There's a limit of 10 items per array, but it can be anything you want in there! And there's no limit as to how many arrays you can make!

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
Author
TechSkylander1518
Downloads
811
Views
2,733
First release
Last update

Ratings

5.00 star(s) 1 ratings

More resources from TechSkylander1518

Latest updates

  1. Catch me forgetting the one part that defines the command lol

    If you're already using this script, an easy fix! Just put this at the top! def pbDrawer(list)...
Back
Top