Item categorize in menu for VX

Discussion in 'RGSS2 Script Requests' started by castor_online, Jun 13, 2018.

    Tags:
  1. castor_online

    castor_online Villager Member

    Messages:
    13
    Likes Received:
    8
    Location:
    México.
    First Language:
    Espanish
    Primarily Uses:
    RMVX
    Hello!

    I'm wondering if there is a script capable to categorize items on the menu screen, I mean, in the item screen there are all items including armors, weapons and others, and it looks like a mess because is not possible even sort it by type. I'm not looking for a script to change all the menu, just the part where the items are displayed, even if it's a "sort" option.

    I have searched on the internet but I didn't find one. Any help will be appreciate!
     
    #1
  2. gstv87

    gstv87 Veteran Veteran

    Messages:
    834
    Likes Received:
    278
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    [collection].sort {|item| item.property}

    where collection is the lot of items (which you'll have to collect) and property is name, or range of IDs, or whatever your criteria.
     
    #2
  3. castor_online

    castor_online Villager Member

    Messages:
    13
    Likes Received:
    8
    Location:
    México.
    First Language:
    Espanish
    Primarily Uses:
    RMVX
    Thank you, you are so kind!

    Sounds like the thing I'm looking for but forgive me but where do I paste that code?
     
    #3
  4. gstv87

    gstv87 Veteran Veteran

    Messages:
    834
    Likes Received:
    278
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    I don't know what you're trying to make, but if it is the standard item window,...

    Code:
    def make_item_list
     @data = $game_party.all_items.select {|item| include?(item) }
    end
    
    def make_item_list
     @data = $game_party.all_items.select {|item| include?(item) }.sort_by {|item| item.property}
    end
    
    that would be the quickest solution.
    if you want to sort backwards, -item.property.
     
    Last edited: Jun 13, 2018
    #4
  5. Kes

    Kes Global Moderators Global Mod

    Messages:
    16,862
    Likes Received:
    8,763
    First Language:
    English
    Primarily Uses:
    RMVXA
    @gstv87 Just double checking - is that code RGSS2, i.e. for VX, not VX Ace, as that is what the OP has asked for.
     
    #5
  6. gstv87

    gstv87 Veteran Veteran

    Messages:
    834
    Likes Received:
    278
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    I took that from Ace's own help files.
    RGSS library, built-in modules, Enumerable.

    why. is it. that nobody. reads. the help files! sigh
     
    #6
  7. Kes

    Kes Global Moderators Global Mod

    Messages:
    16,862
    Likes Received:
    8,763
    First Language:
    English
    Primarily Uses:
    RMVXA
    @gstv87 Which confirms that you have given an answer written in RGSS3 (VX Ace) to a query which requires an answer written in RGSS2 (VX).

    Ace Help files are of no use in this instance, and as e.g. Yanfly's Ace scripts stress that they will not work in VX, I can only assume that the differences are significant.
     
    #7
  8. castor_online

    castor_online Villager Member

    Messages:
    13
    Likes Received:
    8
    Location:
    México.
    First Language:
    Espanish
    Primarily Uses:
    RMVX
    That explains why I saw no changes haha, I thought it was because I was doing something wrong.
     
    #8
  9. castor_online

    castor_online Villager Member

    Messages:
    13
    Likes Received:
    8
    Location:
    México.
    First Language:
    Espanish
    Primarily Uses:
    RMVX
    Update

    I find one! It's called "Cozziekuns Simple Sort Inventory". I hope not to break a rule by sharing the script here but maybe this could help someone in the future.

    Code:
    #===============================================================================
    # 
    # Cozziekuns Simple Sort Inventory
    # Last Date Updated: 08/07/11
    #
    # Like in Tales of Phantasia, this inventory allows you to sort your items in
    # the categories: All, Items, Weapons and Armours.
    #
    #===============================================================================
    # Updates
    # -----------------------------------------------------------------------------
    # o 06/01/10 - Created Script.
    # o 06/01/10 - Updated with Modern Algebra's recommendations.
    # o 06/01/10 - Once again updated with Modern Algebra's recommendations.
    # o 08/27/10 - Updated with Scrolling support. Thanks kawagiri for the idea, and
    #              Modern Algebra for some help.
    # o 09/06/10 - Updated with some bugfixing. Thanks Fizzly for finding that out.
    # o 07/08/11 - Fixed the special prime categories; now you can take out item,
    #              weapon, all and armours. Also added an addon for Modern Algebra's
    #              Item Instances Base; if you are using it, category 4 will contain
    #              all instance items. If you are using it and you do not want this,
    #              simply do not have a category 4.
    #===============================================================================
    # What's to come?
    # -----------------------------------------------------------------------------
    # o Nothing! Suggest something.
    #===============================================================================
    # Instructions
    # -----------------------------------------------------------------------------
    # To install this script, open up your script editor and copy/paste this script
    # to an open slot below ? Materials but above ? Main. Remember to save.
    #
    # Change the modules to your liking. The "hard" parts have instructions of their
    # own.
    #===============================================================================
    
    $imported = {} if $imported == nil
    $imported["CozSimplSortInvent"] = true
    
    module COZZIEKUNS
      module SSI
        CATEGORY_TEXT = "Category:"
        
    #===============================================================================
    # Extra Item Categories (Inspired by Modern Algebra)
    # ------------------------------------------------------------------------------
    # How should I go about explaining something like this? Well, basically, each
    # item in the hash represents a certain category. For example, the first hash we
    # see here is:
    #
    # 0 => [144, "All", false]
    #
    # The syntax of this is:
    #
    # Category ID => [Icon Number, Text, Prime]
    #
    # Probably the most important part, the category ID is the number you want to
    # put into the notebox that the item contains. For example, if you wanted to
    # make the item "World Map" into a key item, simply add the text:
    #
    # \item_category[4]
    #
    # into the notebox. Note that numbers 0, 1, 2, and 3 are special. They're prime
    # categories. Sound special right? They correspond to the categories: All,
    # Items, Weapons and Armours respectively.
    #
    # Last, but not least, is the "Prime" function (inspired by Kyraiki). Setting
    # this to "true" means that anything in the prime category will not show up in
    # the item, weapon armour or instance (if you have MA's Item Instances Base {try
    # saying that five times fast}) categories. You can set if you want it to show
    # up in all.
    #===============================================================================
        MOD_ALG_ITEM_CATEGORIES = {  # Make sure they are in order!!!
        
          0 => [144, "All", false],
          1 => [64, "Items", false],
          2 => [26, "Weapons", false],
          3 => [40, "Armours", false],
          4 => [90, "Instance", true],
          5 => [80, "Key Items", false],
          6 => [92, "Filler", false],
          7 => [32, "Scrolling", false],
        }
        
        MOD_ALG_ITEM_CATEGORY_WIDTH = 220 # How wide you want your text window.
        KYRIAKI_ALL_CATEOGRY_PRIME = false # If you want prime key items to show up in the all window.
        MAX_NUMBER = (544 - MOD_ALG_ITEM_CATEGORY_WIDTH) / 54 # The maximum number of icons that will fit.
        
      end
    end
    
    #==============================================================================
    # ** RPG::BaseItem
    #==============================================================================
    
    class RPG::BaseItem
      #--------------------------------------------------------------------------
      # * Cozziekuns Category Index
      #--------------------------------------------------------------------------
      def coz_modalg_category_index
        @coz_modalg_category_index = 0
        if self.note[/\\item_category\[(\d+)]/i] != nil
          @coz_modalg_category_index = $1.to_i
        end
      return @coz_modalg_category_index
      end
    end
    
    #==============================================================================
    # ** Window_Item
    #==============================================================================
    
    class Window_Item < Window_Selectable
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      alias coz_modalg_ssi_refresh refresh
      def refresh(sort_index = 0)
       @sort_index = sort_index
       coz_modalg_ssi_refresh
     end
      #--------------------------------------------------------------------------
      # * Whether or not to include in item list
      #--------------------------------------------------------------------------
      alias coz_modalg_ssi_include? include?
      def include?(item)
        val = coz_modalg_ssi_include?(item)
        return false if !val
        case @sort_index
        when 0
          unless COZZIEKUNS::SSI::KYRIAKI_ALL_CATEOGRY_PRIME
            return !COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES[item.coz_modalg_category_index][2]
          else
            return true
          end
        when 1
          if COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES[item.coz_modalg_category_index][2]
            return false
          else
            return item.is_a?(RPG::Item)
          end
        when 2
          if COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES[item.coz_modalg_category_index][2]
            return false
          else
            return item.is_a?(RPG::Weapon)
          end
        when 3
          if COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES[item.coz_modalg_category_index][2]
            return false
          else
            return item.is_a?(RPG::Armor)
          end
        when 4
          if not $imported["MAInstanceItemsBase"]
            return item.coz_modalg_category_index == @sort_index
          else
            if COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES[item.coz_modalg_category_index][2]
              return false
            else
              return item.instance_based?
            end
          end
        when 5..999
          return item.coz_modalg_category_index == @sort_index
        end
      end
    end
     
    #==============================================================================
    # ** Window_ItemCategory
    #==============================================================================
    
    class Window_ItemCategory < Window_Base
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize(x, y, width)
        super(x, y, width, WLH + 32)
        refresh
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh(sort_index = 0)
        @sort_index = sort_index
        @item_categories = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES
        @item_categories_width = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORY_WIDTH
        @category_string = COZZIEKUNS::SSI::CATEGORY_TEXT
        self.contents.clear
        self.contents.font.color = system_color
        self.contents.draw_text(4, 0, @item_categories_width - 40, WLH, @category_string, 0)
        self.contents.font.color = normal_color
        for key in @item_categories.keys.sort
          if @sort_index == key
            self.contents.draw_text(4, 0, @item_categories_width - 40, WLH, @item_categories[key][1], 2)
            break
          end
        end
      end
    end
    
    #==============================================================================
    # ** Window_ItemSort
    #==============================================================================
    
    class Window_ItemSort < Window_Base
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize(x, y, width)
        super(x, y, width, WLH + 32)
        @ox = 0
        if COZZIEKUNS::SSI::MAX_NUMBER < COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES.size
          self.contents = Bitmap.new(self.width - 32 + ((COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES.size - COZZIEKUNS::SSI::MAX_NUMBER) * 54), self.height - 32)
        end
        refresh
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh(sort_index = 0)
        @sort_index = sort_index
        @item_categories = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES
        @item_categories_width = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORY_WIDTH
        self.contents.clear
        for i in 0...@item_categories.size
          key = @item_categories.keys.sort[i]
          @icon_x = 0 + (i * ((544 - @item_categories_width) / @item_categories.size))
          if @item_categories.size < COZZIEKUNS::SSI::MAX_NUMBER
            draw_item(key, i)
          else
            draw_items(key, i)
          end
          if @sort_index == key
            if @item_categories.size < COZZIEKUNS::SSI::MAX_NUMBER
              draw_icon(@item_categories[key][0], @icon_x, 0, true)
            else
              draw_icon(@item_categories[key][0], i * 54, 0, true)
            end
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Draw Item
      #--------------------------------------------------------------------------
      def draw_item(index, id)
        icons_x = (544 - @item_categories_width) / @item_categories.size
        draw_icon(@item_categories[index][0], id * icons_x, 0, false)
      end
      #--------------------------------------------------------------------------
      # * Draw Items
      #--------------------------------------------------------------------------
      def draw_items(index, id)
        draw_icon(@item_categories[index][0], id * 54, 0, false)
      end
    end
    
    #==============================================================================
    # ** Scene_Item
    #==============================================================================
    
    class Scene_Item < Scene_Base
      #--------------------------------------------------------------------------
      # * Start processing
      #--------------------------------------------------------------------------
      def start
        super
        create_menu_background
        @viewport = Viewport.new(0, 0, 544, 416)
        @help_window = Window_Help.new
        @help_window.viewport = @viewport
        @item_window = Window_Item.new(0, 112, 544, 304)
        @item_window.viewport = @viewport
        @item_window.help_window = @help_window
        @item_window.active = false
        @category_width = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORY_WIDTH
        @category_window = Window_ItemCategory.new(544 - @category_width, 56, @category_width)
        @sort_window = Window_ItemSort.new(0, 56, 544 - @category_width)
        @target_window = Window_MenuStatus.new(0, 0)
        @sort_index = 0
        @item_categories = COZZIEKUNS::SSI::MOD_ALG_ITEM_CATEGORIES
        hide_target_window
      end
      #--------------------------------------------------------------------------
      # * Termination Processing
      #--------------------------------------------------------------------------
      alias coz_ssi_terminate terminate
      def terminate
        super
        coz_ssi_terminate
        @sort_window.dispose
        @category_window.dispose
      end
      #--------------------------------------------------------------------------
      # * Update Frame
      #--------------------------------------------------------------------------
      alias coz_ssi_update update
      def update
        super
        coz_ssi_update
        @sort_window.update
        @category_window.update
      end
      #--------------------------------------------------------------------------
      # * Update Item Selection
      #--------------------------------------------------------------------------
      def update_item_selection
        if Input.trigger?(Input::B)
          Sound.play_cancel
          return_scene
        elsif Input.trigger?(Input::C)
          @item = @item_window.item
          if @item != nil
            $game_party.last_item_id = @item.id
          end
          if $game_party.item_can_use?(@item)
            Sound.play_decision
            determine_item
          else
            Sound.play_buzzer
          end
        elsif Input.trigger?(Input::Y)
          @sort_index += 1
          @sort_index %= @item_categories.size
          if @sort_index != 0
            if @item_categories.size > COZZIEKUNS::SSI::MAX_NUMBER and @sort_index > COZZIEKUNS::SSI::MAX_NUMBER - 1
              @sort_window.ox += 54
            end
          else
            @sort_window.ox = 0
          end
          @category_window.refresh(@item_categories.keys.sort[@sort_index])
          @sort_window.refresh(@item_categories.keys.sort[@sort_index])
          @item_window.refresh(@item_categories.keys.sort[@sort_index])
          @item_window.index = 0
          Sound.play_cursor
        elsif Input.trigger?(Input::X)
          @sort_index -= 1
          @sort_index %= @item_categories.size
          if @sort_index + 1 == @item_categories.size
            @sort_window.ox += 54 * (@item_categories.size - COZZIEKUNS::SSI::MAX_NUMBER)
          else
            if @item_categories.size > COZZIEKUNS::SSI::MAX_NUMBER and @sort_index > COZZIEKUNS::SSI::MAX_NUMBER - 2
              @sort_window.ox -= 54
            end
          end
          @category_window.refresh(@item_categories.keys.sort[@sort_index])
          @sort_window.refresh(@item_categories.keys.sort[@sort_index])
          @item_window.refresh(@item_categories.keys.sort[@sort_index])
          @item_window.index = 0
          Sound.play_cursor
        end
      end
    end
    
     
    #9
  10. gstv87

    gstv87 Veteran Veteran

    Messages:
    834
    Likes Received:
    278
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    sort_by {} doesn't appear as RGSS3 exclusive.
    neither does Enumerable.....

    either way, it should be listed in the help files.
     
    #10

Share This Page