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.

Storing Excess Items in Chests

In the game I am making, there is a house-purchasing sidequest where you can buy a house in each major city. The house will give you a free bed, but I need other perks than just that. The main one I am thinking of having is putting a chest in each house that acts as a second inventory. Players could store extra items and weapons in the chest (like in Elder Scrolls: Oblivion and games like that). Unfortunately, I have absolutely no idea where to begin. Could someone help me? I would prefer a second inventory-style screen to come up alongside the actual inventory. I also want to have the items sorted by items, weapons, etc., but that can probably just be done with the KGC_CategorizeItem script.

Please help me!!
 

Hugo_S

Member

Hi Jarhead,

do you want to have a chest which is from every town accessible like in Diablo2? Or do you want to have several separated chests which all have its own inventory?

Do you use the items of the database?

If you answer these questions I may could help you :)

Cheers,

Hugo
 
do you want to have a chest which is from every town accessible like in Diablo2? Or do you want to have several separated chests which all have its own inventory?

I imagine that having a chest that is accessible from everywhere would be easier, so that would be preferable. 

Do you use the items of the database?

The items stored in the chest would be items from the database. The whole reason for the chests is so characters can stockpile weapons and items in case they are running low or have sold their equipped stuff.

Thank you Hugo. I am so happy someone is going to take a look at this.
 

Hugo_S

Member

Hmm I cannot think of a possibily without using scripts!
I think you will have to assign the items with variables, so you can determine which are in the party's inventory and which are in the chest. With this method you can also easily make several chests.

If you want to save variables, you can try the following method. An example: You have the variable "sword" which holds the number of swords which are in the party's inventory. So let's say you don't need more than 99 swords of each type, then you only need two digits from 00 to 99 swords. But each variable has up to 8 digits. So you can use the first two digits for the party's inventory, the second two digits for the chest in town A, the third two digits for the chest in town B and the last two digits for the chest in town C.

You will need one variable for each item type.

I hope that was understandable...
 
You could instead setup a class that has its own copy of the methods in Game_Party that control your inventory.  The way I would do it (for a second inventory that can be accessed from any of several events) would be a single instance, like the party.

You could then create a scene that behaved something like the Shop, giving access back and forth between the chest and the party.  What you would end up with would be something that, effectively, ended up doing calls something like this:
Code:
$game_party.lose_item(id, number)
$game_mini_storage.gain_item(id, number)
I can visualize it, although right now I don't have time to write the code.

Alternatively, if you instead build an NPC class and set it up so that any events can associate themselves with an instance of that class, which has its own inventory...  It ends up basically the same as far as the chest is concerned, since you could associate chests on 50 different maps with the same chest "NPC", but you could also have others, such as merchants and whatnot, whose inventories behaved like yours.
 

OS

Sponsor

I've written this very code so many times, I can't belive more people don't know about it.

Code:
#===============================================================================
# NPC Inventories
# By OS
#===============================================================================
# Use:
#
# All Events can be given items, but in order to do so, in the event you must
# Call Script: $scene = Scene_GiveItem.new(event_id), where event_id is the
# numerical id of the event.
#
# NEW
# In Module OS, in the Giveable array, you can put in the Item IDs of items
# that can be given to NPCs.
#
# NEW
# To check if a particular item has been given to an NPC, use
# Conditional Branch: Script: $game_map.events[id].items_include?(item_id),
# where event_id is the event's id, and item_id is the id of the particular
# item you are checking for.
#
# EDIT
# You can see how many items an NPC has by using Call Script:
# i = $game_map.events[event_id].item_count
#===============================================================================
module OS
  Giveable = [1,2,3,4,5,6,7,8,9,10]
end

class Game_Event
  attr_accessor :items
  alias os_init initialize
  def initialize(map_id, event)
    super()
    @items = []
    os_init(map_id, event)
  end
  
  def items_gained?
    return true if @items.size > 0
    return false
  end
  
  def item_count
    return @items.size
  end
  
  def items_include?(item_id)
    if @items.include?(item_id)
      return true
    end
    return false
  end
end

#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
#  This class performs item screen processing.
#==============================================================================

class Scene_GiveItem
  def initialize(npc_id)
    @npc_id = npc_id
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    @help_window = Window_Help.new
    @item_window = Window_Item.new
    # 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
    # If item window is active: call update_item
    if @item_window.active
      update_item
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If not a use item
      unless @item.is_a?(RPG::Item)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      for i in 0..OS::Giveable.size - 1
        if @item.id == OS::Giveable[i]
          $game_party.lose_item(@item.id,1)
          $game_map.events[@npc_id].items << @item.id
        end
      end
      $scene = Scene_Map.new
      return
    end
  end
end

That's an older one, but it should still work. :)

Peace!

Owesome Scriptor

EDIT: Sorry, I just the VX sign at the top, if this is for VX, go here.
 

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