Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Scene Request

Hi guys. I've been trying to make this script myself but it didn't go too well. What I would like is a scene script that can be called in an event. The scene would be a window with a list of specified items that can be selected with a selector and the player can choose which item, weapon, or armor he/she wants from a chest. If you have played Oblivion, you would know what I mean. The player would click on a chest and a window would appear with a list of items that were in the chest.

One thing I would like to specify is that the scene should handle arrays when called, and should be able to handle weapon, armor, and item arrays. Keep in mind that the script would obviouslt be used more than once in the game, and I would prefer it to be called by using a code such as $scene = Scene_Chest.new([1, 2, 3]).

I have this so far:

Code:
#==============================================================================

# ** Window_Chest

#------------------------------------------------------------------------------

#  This window displays a choice of items to pick from in a chest

#==============================================================================

 

class Window_Chest < Window_Selectable

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     items       : list of items to pick from

  #--------------------------------------------------------------------------

  def initialize(items)

    super(0, 0, 640, 480)

    self.contents = Bitmap.new(width - 32, height - 32)

    @item_max = items.size

    @items = items

    self.index = 0

    refresh

  end

end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

   

It's the code for the Scene's Window (Window_Chest).

Thanks a lot to anyone who can make this for me! If you have any questions, feel free to ask.
 
Try this out....

Window_Chest

Code:
#==============================================================================

# ** Window_Chest

#------------------------------------------------------------------------------

#  This window displays items in a chest

#==============================================================================

 

class Window_Chest < Window_Selectable

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(items, weapons, armor)

    super(0, 64, 640, 416)

    @column_max = 2

    @items = items

    @weapons = weapons

    @armor = armor

    refresh

    self.index = 0

    # If in battle, move window to center of screen

    # and make it semi-transparent

    if $game_temp.in_battle

      self.y = 64

      self.height = 256

      self.back_opacity = 160

    end

  end

  #--------------------------------------------------------------------------

  # * Get Item

  #--------------------------------------------------------------------------

  def item

    return @data[self.index]

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    if self.contents != nil

      self.contents.dispose

      self.contents = nil

    end

    @data = []

    # Add item

    for i in [email=0...@items.size]0...@items.size[/email]

        @data.push($data_items[@items[i]])

    end

    # Add weapons and Armor

    for i in [email=0...@weapons.size]0...@weapons.size[/email]

        @data.push($data_weapons[@weapons[i]])

    end

    for i in [email=0...@armor.size]0...@armor.size[/email]

        @data.push($data_armors[@armor[i]])

    end

    # If item count is not 0, make a bit map and draw all items

    @item_max = @data.size

    if @item_max > 0

      self.contents = Bitmap.new(width - 32, row_max * 32)

      for i in 0...@item_max

        draw_item(i)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Draw Item

  #     index : item number

  #--------------------------------------------------------------------------

  def draw_item(index)

    item = @data[index]

    x = 4 + index % 2 * (288 + 32)

    y = index / 2 * 32

    rect = Rect.new(x, y, self.width / @column_max - 32, 32)

    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))

    bitmap = RPG::Cache.icon(item.icon_name)

    opacity = self.contents.font.color == normal_color ? 255 : 128

    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)

    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)

  end

  #--------------------------------------------------------------------------

  # * Help Text Update

  #--------------------------------------------------------------------------

  def update_help

    @help_window.set_text(self.item == nil ? "" : self.item.description)

  end

end

 

Scene_Chest

Code:
#==============================================================================

# ** Scene_Chest

#------------------------------------------------------------------------------

#  This class performs chest screen processing.

#  Call with:

#  $scene = Scene_Chest.new([items],[weapons],[armor])

#  EX:

#  $scene = Scene_Chest.new([1,2,3],[1,2,3],[1,2,3])

#  Use an empty array [] if no object of that type

#  EX:

#  $scene = Scene_Chest.new([1,2,3],[],[1,2,3])

#==============================================================================

 

class Scene_Chest

  #--------------------------------------------------------------------------

  # * Initialize

  #--------------------------------------------------------------------------

  def initialize(items, weapons, armor)

    @items = items

    @weapons = weapons

    @armor = armor

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make help window, item window

    @help_window = Window_Help.new

    @item_window = Window_Chest.new(@items, @weapons, @armor)

    # Associate help window

    @item_window.help_window = @help_window

    # Execute transition

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @help_window.dispose

    @item_window.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Update windows

    @help_window.update

    @item_window.update

    update_item

  end

  #--------------------------------------------------------------------------

  # * Frame Update (when item window is active)

  #--------------------------------------------------------------------------

  def update_item

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Play buzzer SE

      $game_system.se_play($data_system.buzzer_se)

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Get currently selected data on the item window

      @item = @item_window.item

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

      # Add the item to the inventory

      case @item

      when RPG::Item

        $game_party.gain_item(@item.id, 1)

      when RPG::Weapon

        $game_party.gain_weapon(@item.id, 1)

      when RPG::Armor

        $game_party.gain_armor(@item.id, 1)

      end

      # Switch to map screen

      $scene = Scene_Map.new

    end

  end

end

 
 
Thank you so much! Now just one question: where do I insert them? I tried putting Window_Chest under Window_Item and Scene_Chest above Main, but it came up with an error when I called the scene saying "NoMethodError occured. Undefined method for Scene_Chest for #<Interpreter..." or soemthing like that. Forgot the rest.
 
It's most likely the line break in the command in the event.
You need to make sure the line break is at a point between arguments, and use a backslash to escape the line return that RMXP inserts for you. Like:

$scene = Scene_Chest.new([1,2],[],\
[1,5])

or

$scene = Scene_Chest.new\
([1,2],[],[1,5])

make sure there is no space after the backslash

I usually put custom scripts all right above main, but it should work the way you have it.
 
just curious, i wanted to play with this, how do u stop it from letting u take the same item 100 times? cause if u just use a self switch after the scene u cant get more then one item(if the box contains more hten one item)
 
I think the point is to only allow the player to choose one item. Otherwise you could just give them everything.

You could edit the scene so when the player chooses an item, instead of exiting to the map, it removes the chosen item from the @items, @weapons or @armors array, then refreshes the item window, allowing the player to make another choice from the remaining items.

If you want the player to be able to take an item, then come back later to take another remaining item, you'll need to store the chest contents externally, but somewhere that gets saved to savefiles. (e.g. $game_system.chests - an array of chest contents)
Then when he chooses something from the first chest, you remove that item from the $game_system.chest[1] array, so the next time he opens the chest only the remaining items appear. Then you'd call the chest scene with something like...

$scene = Scene_Chest.new($game_system.chest[1])

Be Well
 

dricc

Member

I have a script called "Store items" by breadlord .
It is exactly what you need .

To use it , put 2 tabs on your event .
1 - no conditions
call script : $stores['Pantry2'] = Store.new({3 => 5, 4=>
2},{},{},5,3)
call script : $store = 'Pantry2'
$scene = Scene_Store.new
selfswitch A on
2 - condition : seflswitch A on
call script : $store = 'Pantry2'
$scene = Scene_Store.new

And it works fine !
As oblivion , you can take one or all objects . you can store if you want ...
I don't remember where i got this ...
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top