设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 92|回复: 0

[转载发布] Sort items manually instead of by ID

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4469

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    22945
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28308

    灌水之王

    发表于 3 天前 | 显示全部楼层 |阅读模式
    Some time ago I found this post on another forum. I think it's a pretty common situation when making a game in RPG maker.

                                                            Ledai (translated) said:                                       
                            I don't know if this ever happened to you that by trying to save space in the database, specially on the items section, you try to leave some blank spaces so they get sorted by kind, but after a while there are more than you were expecting, so you have to include them at the end of the list. That causes a disorder on the menus, since by default the items are sorted by ID.               
    Click to expand...


    Trying to sort them back is inviable because that would mean you have to change every appearance they had in every event. That's why I made this script that allows to set a custom order in the windows instead. It's a pretty simple script, this time.

    Author: Wecoc
    Release Date: November 2016
    Last Version: November 2016

    Terms of Use
    - Giving credits (Wecoc) for using this script is optional, but appreciated.
    - You can repost this code.
    - You can edit this code freely, and distribute the edits as well.
    - This code can be used on commercial games.

    Code

                    Ruby:       
    #==============================================================================# ** [XP] Custom Item Sorting#------------------------------------------------------------------------------#  Author: Wecoc (no credits required)#------------------------------------------------------------------------------#  This script allows to sort the items as the creator wants instead of by ID#  as default. Even with that, they keep getting sorted like this:#     Items - Weapons - Armors#  In other words, the sorting only affects those of the same type.##  To do this, search on the start of the script these constants:#     SORTED_ITEMS, SORTED_WEAPONS, SORTED_ARMORS#  and there define the sorting you want. The ID that are not included there#  will appear in the end of the list by ID.#------------------------------------------------------------------------------# * To test this you can use this script call:#     $game_party.add_everything##  That adds each item/weapon/armor to the party.#------------------------------------------------------------------------------#  BEWARE! This script is not compatible with the IGOS system.#  The script sorts the items in:#     Scene_Item, Scene_Battle (Items), Scene_Equip, Scene_Shop#  If you use systems that modify the items, they may need to be adapted##  Modified methods:#     Window_Item       :refresh#     Window_EquipItem  :refresh#     Window_ShopBuy    :refresh#     Window_ShopSell   :refresh#==============================================================================module Custom_Sort   # Sort items  SORTED_ITEMS = [1, 3, 2, 5, 7, 9, 11, 16, 15, 13, 19]   # Sort weapons  SORTED_WEAPONS = [1, 4, 3, 2]   # Sort armors  SORTED_ARMORS = [4, 5, 6, 1, 3, 2] end#==============================================================================class Array  def sort_ids(array)    return self if self.size == 0 or array.size == 0    name = self[0].class.name    r = self.map { |item| item.id }    result = []    for i in 0...array.size      result = nil    end    for i in 0...r.size      id = r ; result[array.index(id)] = id if array.include?(id)    end    result.compact!    for i in 0...r.size      id = r ; result.push(id) if !result.include?(id)    end    case name    when "RPG::Item"      result.map! { |id| $data_items[id] }    when "RPG::Weapon"      result.map! { |id| $data_weapons[id] }    when "RPG::Armor"      result.map! { |id| $data_armors[id] }    end    return result  end  def sort_ids!(array)    self.replace(self.sort_ids(array))  endend#==============================================================================class Game_Party  def add_everything(n=1)    for i in 1...$data_items.size      gain_item(i, n)   if $data_items.name != ""    end    for i in 1...$data_weapons.size      gain_weapon(i, n) if $data_weapons.name != ""    end    for i in 1...$data_armors.size      gain_armor(i, n)  if $data_armors.name != ""    end  endend#==============================================================================# ** Window_Item#==============================================================================class Window_Item < Window_Selectable  #--------------------------------------------------------------------------  # * Refresh  #--------------------------------------------------------------------------  def refresh    if self.contents != nil      self.contents.dispose      self.contents = nil    end    @data = []    data_items   = []    data_weapons = []    data_armors  = []    # Add item    for i in 1...$data_items.size      if $game_party.item_number(i) > 0        data_items.push($data_items)      end    end    data_items.sort_ids!(Custom_Sort::SORTED_ITEMS)    # Also add weapons and items if outside of battle    unless $game_temp.in_battle      for i in 1...$data_weapons.size        if $game_party.weapon_number(i) > 0          data_weapons.push($data_weapons)        end      end      for i in 1...$data_armors.size        if $game_party.armor_number(i) > 0          data_armors.push($data_armors)        end      end      data_weapons.sort_ids!(Custom_Sort::SORTED_WEAPONS)      data_armors.sort_ids!(Custom_Sort::SORTED_ARMORS)    end    @data.concat(data_items)    @data.concat(data_weapons)    @data.concat(data_armors)    # 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  endend#==============================================================================# ** Window_EquipItem#==============================================================================class Window_EquipItem < Window_Selectable  #--------------------------------------------------------------------------  # * Refresh  #--------------------------------------------------------------------------  def refresh    if self.contents != nil      self.contents.dispose      self.contents = nil    end    @data = []    data_weapons = []    data_armors  = []    # Add equippable weapons    if @equip_type == 0      weapon_set = $data_classes[@actor.class_id].weapon_set      for i in 1...$data_weapons.size        if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)          data_weapons.push($data_weapons)        end      end    end    # Add equippable armor    if @equip_type != 0      armor_set = $data_classes[@actor.class_id].armor_set      for i in 1...$data_armors.size        if $game_party.armor_number(i) > 0 and armor_set.include?(i)          if $data_armors.kind == @equip_type-1            data_armors.push($data_armors)          end        end      end    end    data_weapons.sort_ids!(Custom_Sort::SORTED_WEAPONS)    data_armors.sort_ids!(Custom_Sort::SORTED_ARMORS)    @data.concat(data_weapons)    @data.concat(data_armors)    # Add blank page    @data.push(nil)    # Make a bit map and draw all items    @item_max = @data.size    self.contents = Bitmap.new(width - 32, row_max * 32)    for i in 0...@item_max-1      draw_item(i)    end  end  #--------------------------------------------------------------------------  # * Draw Item  #     index : item number  #--------------------------------------------------------------------------  def draw_item(index)    item = @data[index]    x = 4 + index % 2 * (288 + 32)    y = index / 2 * 32    case item    when RPG::Weapon      number = $game_party.weapon_number(item.id)    when RPG::Armor      number = $game_party.armor_number(item.id)    end    bitmap = RPG::Cache.icon(item.icon_name)    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))    self.contents.font.color = normal_color    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)  end  #--------------------------------------------------------------------------  # * Help Text Update  #--------------------------------------------------------------------------  def update_help    @help_window.set_text(self.item == nil ? "" : self.item.description)  endend#==============================================================================# ** Window_ShopBuy#==============================================================================class Window_ShopBuy < Window_Selectable  #--------------------------------------------------------------------------  # * Refresh  #--------------------------------------------------------------------------  def refresh    if self.contents != nil      self.contents.dispose      self.contents = nil    end    @data = []    data_items   = []    data_weapons = []    data_armors  = []    for goods_item in @shop_goods      case goods_item[0]      when 0 # Item        item = $data_items[goods_item[1]]        data_items.push(item) if item != nil      when 1 # Weapon        item = $data_weapons[goods_item[1]]        data_weapons.push(item) if item != nil      when 2 # Armor        item = $data_armors[goods_item[1]]        data_armors.push(item) if item != nil      end    end    data_items.sort_ids!(Custom_Sort::SORTED_ITEMS)    data_weapons.sort_ids!(Custom_Sort::SORTED_WEAPONS)    data_armors.sort_ids!(Custom_Sort::SORTED_ARMORS)    @data.concat(data_items)    @data.concat(data_weapons)    @data.concat(data_armors)    # 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  endend#==============================================================================# ** Window_ShopSell#==============================================================================class Window_ShopSell < Window_Selectable  #--------------------------------------------------------------------------  # * Refresh  #--------------------------------------------------------------------------  def refresh    if self.contents != nil      self.contents.dispose      self.contents = nil    end    @data = []    data_items   = []    data_weapons = []    data_armors  = []    for i in 1...$data_items.size      if $game_party.item_number(i) > 0        data_items.push($data_items)      end    end    for i in 1...$data_weapons.size      if $game_party.weapon_number(i) > 0        data_weapons.push($data_weapons)      end    end    for i in 1...$data_armors.size      if $game_party.armor_number(i) > 0        data_armors.push($data_armors)      end    end    data_items.sort_ids!(Custom_Sort::SORTED_ITEMS)    data_weapons.sort_ids!(Custom_Sort::SORTED_WEAPONS)    data_armors.sort_ids!(Custom_Sort::SORTED_ARMORS)    @data.concat(data_items)    @data.concat(data_weapons)    @data.concat(data_armors)    # If item count is not 0, make a bitmap 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  endend


    Spoiler: Related script - Sort items as the player wants
    I made some time ago a script that allows the players to sort the items as they want. That one is a bit rudimentary but it may interest you as well, so I include it here with the same terms of use. Since they modify the same they're not compatible, but it shouldn't be very hard to combine them.

    To use this script you must be in Scene Item (the items menu of the game) and while pressing Z, trigger the directional arrows to move the selected item arround. The new sorting gets saved. This way if the player uses the same kind of potions very often they doesn't need to search it each time.

    You can find it here:
    - Sort items as the player wants
    - Expanded version with both items and skills
    Spoiler: FAQ
    Can this be done with other lists of the Database? (skills, actors...)
    Yes, it would be basically the same, but this script only works with items. If someone needs a different type ask it here and I'll try to provide it. That being said, some lists are more compatible to change than others, it depends on other custom scripts you might be using. Feel free to take my script as a reference to make your own changes in the game.


    I never know what to say at the end, I think I need a catchphrase.



    本贴来自国际rpgmaker官方论坛作者:Wecoc处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/sort-items-manually-instead-of-by-id.138364/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-14 17:53 , Processed in 0.121038 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表