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.

Separating Key Items into another window

Is it possible to do that with a script? I wanted to separate some of the items away from the Inventory windows and put it in another window. Anyone can help me with that? 8-)
 
I would help, but my name didn't make that list...



Add this in the script editor above Main.

Code:
class Window_Item
  alias_method :seph_keyitemssimple_wnitm_init, :initialize
  def initialize
    seph_keyitemssimple_wnitm_init
    if $scene.is_a?(Scene_Item)
      self.y += 64
      self.height -= 64
      self.active = false
    end
  end
  #--------------------------------------------------------------------------
  # * Filter Element Set
  #--------------------------------------------------------------------------
  def filter_element_set(element_tag = 20, call_refresh = false)
    refresh if call_refresh
    @data.each do |item|
      if item.is_a?(RPG::Item) || item.is_a?(RPG::Weapon)
        @data.delete(item) unless item.element_set.include?(element_tag)
      elsif item.is_a?(RPG::Armor)
        @data.delete(item) unless item.guard_element_set.include?(element_tag)
      end
    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
end

#==============================================================================
# ** Window_HorizCommand
#------------------------------------------------------------------------------
#  This window deals with general command choices. (Horizontal)
#==============================================================================

class Window_HorizCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :commands
  attr_accessor :c_spacing
  attr_accessor :alignment
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(width, commands, c_spacing = (width - 32) / commands.size)
    # Compute window height from command quantity
    super(0, 0, width, 64)
    @commands     = commands
    @item_max     = commands.size
    @column_max   = @item_max
    @c_spacing    = c_spacing
    @alignment    = 1
    self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Command
  #--------------------------------------------------------------------------
  def command(index = self.index)
    return @commands[index]
  end
  #--------------------------------------------------------------------------
  # * Commands
  #--------------------------------------------------------------------------
  def commands=(commands)
    # Return if Commands Are Same
    return if @commands == commands
    # Reset Commands
    @commands = commands
    # Resets Item Max
    item_max    = @item_max
    @item_max   = @commands.size
    @column_max = @item_max
    # If Item Max Changes
    unless item_max == @item_max
      # Deletes Existing Contents (If Exist)
      unless self.contents.nil?
        self.contents.dispose
        self.contents = nil
      end
      # Recreates Contents
    self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
    end
    # Refresh Window
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    command = commands[index]
    x = index * @c_spacing + 4
    self.contents.font.color = color
    self.contents.draw_text(x, 0, @c_spacing - 8, 32, command, @alignment)
  end
  #--------------------------------------------------------------------------
  # * Disable Item
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(@c_spacing * @index, 0, @c_spacing, 32)
    end
  end
end

class Scene_Item
  alias_method :seph_keyitemssimple_scnitm_main, :main
  alias_method :seph_keyitemssimple_scnitm_update, :update
  def main
    @item_kind_select = Window_HorizCommand.new(640, ['Items', 'Key Items'])
    @item_kind_select.y = 64
    seph_keyitemssimple_scnitm_main
    @item_kind_select.dispose
  end
  def update
    if @item_kind_select.active
      @item_kind_select.update
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Menu.new
        return
      end
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decison_se)
        @item_kind_select.active = false
        @item_window.active = true
      end
      if Input.repeat?(Input::RIGHT) || Input.repeat?(Input::LEFT)
        if @item_kind_select.index == 0
          @item_window.refresh
        else
          @item_window.filter_element_set
        end
      end
      return
    end
    seph_keyitemssimple_scnitm_update
  end
end


Now, on this line


def filter_element_set(element_tag = 20, call_refresh = false)

Change that 20 to the key item element you wish to have. Now any item with that element tag (items, weapons and armors), will show up.
 
You made that script in a split second? O_o

BTW, I made a mistake to the previous post I made.
Correction: You're the BEST n' Most Excellent :D

Thanks for the script. It works like the one in Final Fantasy 8-)
 
Glad you like it. Not a split second. About 10 minutes or so give or take a few minutes opening the game editor.

Flattery will get you everywhere with me. XD

Just let me know if there are errors in the future. And just wait to see my final version of that (that I really need to start). It allows a lot of sorting and filtering, presets, and customizables. In both skills, and items. ;)
 
Yeah, just discovered an error awhile ago. No matter what number I change on the statement that you asked me to change, the Key Items always display items that are on the right side of the Normal Item. I mean like this:

NORMAL ITEM WINDOW (Below are the items displayed)
Item 1 Item 2
Item 3 Item 4
Item 5 Item 6
Item 7 Item 8

KEY ITEM (The window display all items that are on the right side of the NORMAL ITEM window like this)
Item 2 Item 4
Item 6 Item 8

Hope you understand what I wrote above. :)
 
Silly errors.

Try this:

Code:
class Window_Item
  alias_method :seph_keyitemssimple_wnitm_init, :initialize
  def initialize
    seph_keyitemssimple_wnitm_init
    if $scene.is_a?(Scene_Item)
      self.y += 64
      self.height -= 64
      self.active = false
    end
  end
  #--------------------------------------------------------------------------
  # * Filter Element Set
  #--------------------------------------------------------------------------
  def filter_element_set(element_tag = 17, call_refresh = false)
    refresh if call_refresh
    redata = []
    @data.each do |item|
      if item.is_a?(RPG::Item) || item.is_a?(RPG::Weapon)
        redata << item if item.element_set.include?(element_tag)
      elsif item.is_a?(RPG::Armor)
        redata << item if item.guard_element_set.include?(element_tag)
      end
    end
    @data = redata
    # 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
end

class Scene_Item
  alias_method :seph_keyitemssimple_scnitm_main, :main
  alias_method :seph_keyitemssimple_scnitm_update, :update
  def main
    @item_kind_select = Window_HorizCommand.new(640, ['Items', 'Key Items'])
    @item_kind_select.y = 64
    seph_keyitemssimple_scnitm_main
    @item_kind_select.dispose
  end
  def update
    if @item_kind_select.active
      @item_kind_select.update
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Menu.new
        return
      end
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        @item_kind_select.active = false
        @item_window.active = true
      end
      if Input.repeat?(Input::RIGHT) || Input.repeat?(Input::LEFT)
        if @item_kind_select.index == 0
          @item_window.refresh
        else
          @item_window.filter_element_set
        end
      end
      return
    end
    seph_keyitemssimple_scnitm_update
  end
end

And the Window_HorizCommand (Its in the SDK)
Code:
#==============================================================================
# ** Window_HorizCommand
#------------------------------------------------------------------------------
#  This window deals with general command choices. (Horizontal)
#==============================================================================

class Window_HorizCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :commands
  attr_accessor :c_spacing
  attr_accessor :alignment
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(width, commands, c_spacing = (width - 32) / commands.size)
    # Compute window height from command quantity
    super(0, 0, width, 64)
    @commands     = commands
    @item_max     = commands.size
    @column_max   = @item_max
    @c_spacing    = c_spacing
    @alignment    = 1
    self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Command
  #--------------------------------------------------------------------------
  def command(index = self.index)
    return @commands[index]
  end
  #--------------------------------------------------------------------------
  # * Commands
  #--------------------------------------------------------------------------
  def commands=(commands)
    # Return if Commands Are Same
    return if @commands == commands
    # Reset Commands
    @commands = commands
    # Resets Item Max
    item_max    = @item_max
    @item_max   = @commands.size
    @column_max = @item_max
    # If Item Max Changes
    unless item_max == @item_max
      # Deletes Existing Contents (If Exist)
      unless self.contents.nil?
        self.contents.dispose
        self.contents = nil
      end
      # Recreates Contents
    self.contents = Bitmap.new(@item_max * @c_spacing, height - 32)
    end
    # Refresh Window
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    command = commands[index]
    x = index * @c_spacing + 4
    self.contents.font.color = color
    self.contents.draw_text(x, 0, @c_spacing - 8, 32, command, @alignment)
  end
  #--------------------------------------------------------------------------
  # * Disable Item
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(@c_spacing * @index, 0, @c_spacing, 32)
    end
  end
end
 

Rare

Member

Kinnison;309484 said:
Yeah, I forgot about you. Sorry about that :D. Your scripting abilities are good too, I checked them. Are you Trickster or somebody else? :)

LOL Good? xD Seph can be described as a scripting god.

Glad you got some help >=]
 
Kinda hate to say this, but the second one is no better than the first one. This time, it displays ALL the items that are available in the Normal Item window (Regardless of what number I put in the Element tag). Sorry if I caused you trouble :(
 
Yeah I forgot to change that one.It works now, although the Key items is displayed in the Normal Item as well. Thanks anyway. :)

Since you're an expert (Elias said that you are the scripting god :D), I think you can fix the script a little so that Items with the Key item element tag will not be displayed on the Normal Item window :)
 
Hehe. Alter the first code with this:

Code:
class Window_Item
  alias_method :seph_keyitemssimple_wnitm_init, :initialize
  def initialize
    seph_keyitemssimple_wnitm_init
    if $scene.is_a?(Scene_Item)
      self.y += 64
      self.height -= 64
      self.active = false
    end
  end
  #--------------------------------------------------------------------------
  # * Filter Element Set
  #--------------------------------------------------------------------------
  def filter_element_set(element_tag = 17, call_refresh = false)
    refresh if call_refresh
    redata = []
    @data.each do |item|
      if item.is_a?(RPG::Item) || item.is_a?(RPG::Weapon)
        redata << item if item.element_set.include?(element_tag)
      elsif item.is_a?(RPG::Armor)
        redata << item if item.guard_element_set.include?(element_tag)
      end
    end
    @data = redata
    # 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
#--------------------------------------------------------------------------
  # * Reverse Filter Element Set
  #--------------------------------------------------------------------------
  def reverse_filter_element_set(element_tag = 17, call_refresh = false)
    refresh if call_refresh
    redata = []
    @data.each do |item|
      if item.is_a?(RPG::Item) || item.is_a?(RPG::Weapon)
        redata << item unless item.element_set.include?(element_tag)
      elsif item.is_a?(RPG::Armor)
        redata << item unless item.guard_element_set.include?(element_tag)
      end
    end
    @data = redata
    # 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
end

class Scene_Item
  alias_method :seph_keyitemssimple_scnitm_main, :main
  alias_method :seph_keyitemssimple_scnitm_update, :update
  def main
    @item_kind_select = Window_HorizCommand.new(640, ['Items', 'Key Items'])
    @item_kind_select.y = 64
    seph_keyitemssimple_scnitm_main
    @item_kind_select.dispose
  end
  def update
    if @item_kind_select.active
      @item_kind_select.update
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        $scene = Scene_Menu.new
        return
      end
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        @item_kind_select.active = false
        @item_window.active = true
      end
      if Input.repeat?(Input::RIGHT) || Input.repeat?(Input::LEFT)
        if @item_kind_select.index == 0
          @item_window.reverse_filter_element_set(17, true)
        else
          @item_window.filter_element_set(17, true)
        end
      end
      return
    end
    seph_keyitemssimple_scnitm_update
  end
end

Let me know if that works.
 
I have to change the element tag number "17" in line 14, 37, 83 and 85 right? I change all of them and nuh-uh, it still displays the key item in Normal item window.
Or is it that I missed something else?
 
Sure, go ahead and take a break :D
I can imagine how tired a scripter can be when they make scripts.

By the way, may I suggest something to the script. I hope it will be useful to the script :)

- I was thinking if you can remove the quantity number in the Key Item window, Key Items look better without the number next to its name
- Shops will still display whatever Key Item I had in the Sell list. Possible to remove the Key Items from that list?
 
Sorry for bumping an old post, but this is exactly the issue I'm trying to work out.  I figured it would be easier just to update this one, than to create a new thread and go through everything again.  I did a search, and this is almost exactly what I need.

The only thing is, as Kinnison stated, is that the key items show up in both the key items screen, and the regular items screen.  Can anyone help me out?
 

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