Project1

标题: 我有一个物品分类脚本的问题,求大大们解答! [打印本页]

作者: 嘉凉    时间: 2014-11-9 11:00
标题: 我有一个物品分类脚本的问题,求大大们解答!
本帖最后由 myownroc 于 2014-11-10 00:53 编辑

我有一个物品分类脚本,用了之后,分类确实分类了,但发现只有一个分类,不论装备饰品还是图鉴宝箱药剂全分类成了“药品”我是个脚本渣,请问该怎么弄好几个分类呢?这个是工程:
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================

  4. #==============================================================================
  5. # ■ Harts_Window_ItemTitle
  6. #==============================================================================

  7. class Harts_Window_ItemTitle < Window_Base
  8.   def initialize
  9.     super(0, 0, 160, 64)
  10.     self.contents = Bitmap.new(width - 32, height - 32)
  11.     self.contents.clear
  12.     self.contents.font.color = normal_color
  13.     self.contents.draw_text(4, 0, 120, 32, $data_system.words.item, 1)
  14.   end
  15. end

  16. #==============================================================================
  17. # ■ Harts_Window_ItemCommand
  18. #==============================================================================

  19. class Harts_Window_ItemCommand < Window_Selectable
  20.   attr_accessor :commands
  21.   #--------------------------------------------------------------------------
  22.   # ● 初始化,生成commands窗口
  23.   #--------------------------------------------------------------------------
  24.   def initialize
  25.     super(0, 64, 160, 352)
  26.     self.contents = Bitmap.new(width - 32, height - 32)
  27.     @commands = []
  28.     #————————生成commands窗口
  29.     for i in 1...$data_items.size
  30.       if $game_party.item_number(i) > 0
  31.         push = true
  32.         for com in @commands
  33.           if com == $data_items[i].desc
  34.             push = false
  35.           end
  36.         end
  37.         if push == true
  38.           @commands.push($data_items[i].desc)
  39.         end
  40.       end
  41.     end
  42.     for i in 1...$data_weapons.size
  43.       if $game_party.weapon_number(i) > 0
  44.         push = true
  45.         for com in @commands
  46.           if com == $data_weapons[i].desc
  47.             push = false
  48.           end
  49.         end
  50.         if push == true
  51.           @commands.push($data_weapons[i].desc)
  52.         end
  53.       end
  54.     end
  55.     for i in 1...$data_armors.size
  56.       if $game_party.armor_number(i) > 0
  57.         push = true
  58.         for com in @commands
  59.           if com == $data_armors[i].desc
  60.             push = false
  61.           end
  62.         end
  63.         if push == true
  64.           @commands.push($data_armors[i].desc)
  65.         end
  66.       end
  67.     end
  68.     if @commands == []
  69.       @commands.push("药品")
  70.     end      
  71.     @item_max = @commands.size
  72.     refresh
  73.     self.index = 0
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   #--------------------------------------------------------------------------
  77.   def refresh
  78.     self.contents.clear
  79.     for i in 0...@item_max
  80.       draw_item(i, normal_color)
  81.     end
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   #--------------------------------------------------------------------------
  85.   def draw_item(index, color)
  86.     self.contents.font.color = color
  87.     y = index * 32
  88.     self.contents.draw_text(4, y, 128, 32, @commands[index])
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # 只描绘原文字
  92.   #--------------------------------------------------------------------------
  93.   def update_help
  94.     @help_window.set_text(@commands[self.index])
  95.   end
  96. end

  97. #==============================================================================
  98. # ■ Window_Item
  99. #==============================================================================

  100. class Harts_Window_ItemList < Window_Selectable
  101.   #--------------------------------------------------------------------------
  102.   #--------------------------------------------------------------------------
  103.   def initialize
  104.     super(160, 0, 480, 416)
  105.     refresh
  106.     self.index = 0
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   #--------------------------------------------------------------------------
  110.   def item
  111.     return @data[self.index]
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   #--------------------------------------------------------------------------
  115.   def refresh
  116.     if self.contents != nil
  117.       self.contents.dispose
  118.       self.contents = nil
  119.     end
  120.     @data = []
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   #--------------------------------------------------------------------------
  124.   def set_item(command)
  125.     refresh
  126.     for i in 1...$data_items.size
  127.       if $game_party.item_number(i) > 0 and $data_items[i].desc == command
  128.         @data.push($data_items[i])
  129.       end
  130.     end
  131.     for i in 1...$data_weapons.size
  132.       if $game_party.weapon_number(i) > 0 and $data_weapons[i].desc == command
  133.         @data.push($data_weapons[i])
  134.       end
  135.     end
  136.     for i in 1...$data_armors.size
  137.       if $game_party.armor_number(i) > 0 and $data_armors[i].desc == command
  138.         @data.push($data_armors[i])
  139.       end
  140.     end
  141.     @item_max = @data.size
  142.     if @item_max > 0
  143.       self.contents = Bitmap.new(width - 32, row_max * 32)
  144.       self.contents.clear
  145.       for i in 0...@item_max
  146.         draw_item(i)
  147.       end
  148.     end
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   #--------------------------------------------------------------------------
  152.   def item_number
  153.     return @item_max
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   #--------------------------------------------------------------------------
  157.   def draw_item(index)
  158.     item = @data[index]
  159.     case item
  160.     when RPG::Item
  161.       number = $game_party.item_number(item.id)
  162.     when RPG::Weapon
  163.       number = $game_party.weapon_number(item.id)
  164.     when RPG::Armor
  165.       number = $game_party.armor_number(item.id)
  166.     end
  167.     if item.is_a?(RPG::Item) and
  168.    # 物品栏显示物品颜色-----------------------------------------------------
  169.         self.contents.font.color = text_color(item.name_color_66RPG)
  170.       else
  171.         self.contents.font.color = text_color(item.name_color_66RPG)
  172.       end
  173.    #------------------------------------------------------------------------
  174.     x = 4
  175.     y = index * 32
  176.     bitmap = RPG::Cache.icon(item.icon_name)
  177.     opacity = self.contents.font.color == normal_color ? 255 : 128
  178.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  179.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  180.     self.contents.draw_text(x + 400, y, 16, 32, ":", 1)
  181.     self.contents.draw_text(x + 416, y, 24, 32, number.to_s, 2)
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   #--------------------------------------------------------------------------
  185.   def update_help
  186.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  187.   end
  188. end

  189. #==============================================================================
  190. # ■ Harts_Scene_Item
  191. #==============================================================================

  192. class Scene_Item
  193.   #--------------------------------------------------------------------------
  194.   #--------------------------------------------------------------------------
  195.   def main
  196.     @itemtitle_window = Harts_Window_ItemTitle.new
  197.     @itemcommand_window = Harts_Window_ItemCommand.new
  198.     @command_index = @itemcommand_window.index
  199.     @itemlist_window = Harts_Window_ItemList.new
  200.     @itemlist_window.active = false
  201.     @help_window = Window_Help.new
  202.     @help_window.x = 0
  203.     @help_window.y = 416
  204.     @itemcommand_window.help_window = @help_window
  205.     @itemlist_window.help_window = @help_window
  206.     @target_window = Window_Target.new
  207.     @target_window.visible = false
  208.     @target_window.active = false
  209.     @itemlist_window.set_item(@itemcommand_window.commands[@command_index])
  210.     Graphics.transition
  211.     loop do
  212.       Graphics.update
  213.       Input.update
  214.       update
  215.       if $scene != self
  216.         break
  217.       end
  218.     end
  219.     Graphics.freeze
  220.     @itemtitle_window.dispose
  221.     @itemcommand_window.dispose
  222.     @itemlist_window.dispose
  223.     @help_window.dispose
  224.     @target_window.dispose
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   #--------------------------------------------------------------------------
  228.   def update
  229.     @itemtitle_window.update
  230.     @itemcommand_window.update
  231.     @itemlist_window.update
  232.     @help_window.update
  233.     @target_window.update
  234.     if @command_index != @itemcommand_window.index
  235.       @command_index = @itemcommand_window.index
  236.       @itemlist_window.set_item(@itemcommand_window.commands[@command_index])
  237.     end
  238.     if @itemcommand_window.active
  239.       update_itemcommand
  240.       return
  241.     end
  242.     if @itemlist_window.active
  243.       update_itemlist
  244.       return
  245.     end
  246.     if @target_window.active
  247.       update_target
  248.       return
  249.     end
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   #--------------------------------------------------------------------------
  253.   def update_itemcommand
  254.     if Input.trigger?(Input::B)
  255.       $game_system.se_play($data_system.cancel_se)
  256.       $scene = Scene_Menu.new(0)
  257.       return
  258.     end
  259.     if Input.trigger?(Input::C)
  260.       if @itemlist_window.item_number == 0
  261.         $game_system.se_play($data_system.buzzer_se)
  262.         return
  263.       end
  264.       $game_system.se_play($data_system.decision_se)
  265.       @itemcommand_window.active = false
  266.       @itemlist_window.active = true
  267.       @itemlist_window.index = 0
  268.       return
  269.     end
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   #--------------------------------------------------------------------------
  273.   def update_itemlist
  274.     if Input.trigger?(Input::B)
  275.       $game_system.se_play($data_system.cancel_se)
  276.       @itemcommand_window.active = true
  277.       @itemlist_window.active = false
  278.       @itemlist_window.index = 0
  279.       @itemcommand_window.index = @command_index
  280.       return
  281.     end
  282.     if Input.trigger?(Input::C)
  283.       @item = @itemlist_window.item
  284.       unless @item.is_a?(RPG::Item)
  285.         $game_system.se_play($data_system.buzzer_se)
  286.         return
  287.       end
  288.       unless $game_party.item_can_use?(@item.id)
  289.         $game_system.se_play($data_system.buzzer_se)
  290.         return
  291.       end
  292.       $game_system.se_play($data_system.decision_se)
  293.       if @item.scope >= 3
  294.         @itemlist_window.active = false
  295.         @target_window.x = 304
  296.         @target_window.visible = true
  297.         @target_window.active = true
  298.         if @item.scope == 4 || @item.scope == 6
  299.           @target_window.index = -1
  300.         else
  301.           @target_window.index = 0
  302.         end
  303.       else
  304.         if @item.common_event_id > 0
  305.           $game_temp.common_event_id = @item.common_event_id
  306.           $game_system.se_play(@item.menu_se)
  307.             if @item.consumable
  308.               $game_party.lose_item(@item.id, 1)
  309.               @itemlist_window.draw_item(@itemlist_window.index)
  310.             end
  311.           $scene = Scene_Map.new
  312.           return
  313.         end
  314.       end
  315.       return
  316.     end
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   #--------------------------------------------------------------------------
  320.   def update_target
  321.     if Input.trigger?(Input::B)
  322.       $game_system.se_play($data_system.cancel_se)
  323.       unless $game_party.item_can_use?(@item.id)
  324.         @itemlist_window.refresh
  325.       end
  326.       @itemlist_window.active = true
  327.       @target_window.visible = false
  328.       @target_window.active = false
  329.       @itemlist_window.set_item(@itemcommand_window.commands[@command_index])
  330.       return
  331.     end
  332.     if Input.trigger?(Input::C)
  333.       if $game_party.item_number(@item.id) == 0
  334.         $game_system.se_play($data_system.buzzer_se)
  335.         return
  336.       end
  337.       if @target_window.index == -1
  338.         used = false
  339.         for i in $game_party.actors
  340.           used |= i.item_effect(@item)
  341.         end
  342.       end
  343.       if @target_window.index >= 0
  344.         target = $game_party.actors[@target_window.index]
  345.         used = target.item_effect(@item)
  346.       end
  347.       if used
  348.         $game_system.se_play(@item.menu_se)
  349.         if @item.consumable
  350.           $game_party.lose_item(@item.id, 1)
  351.           @itemlist_window.draw_item(@itemlist_window.index)
  352.           @itemlist_window.set_item(@itemcommand_window.commands[@command_index])
  353.         end
  354.         @target_window.refresh
  355.         if $game_party.all_dead?
  356.           $scene = Scene_Gameover.new
  357.           return
  358.         end
  359.         if @item.common_event_id > 0
  360.           $game_temp.common_event_id = @item.common_event_id
  361.           $scene = Scene_Map.new
  362.           return
  363.         end
  364.       end
  365.       unless used
  366.         $game_system.se_play($data_system.buzzer_se)
  367.       end
  368.     return
  369.     end
  370.   end
  371. end

  372. #==============================================================================
  373. # ■ RPG追加定义,使用@符号分类
  374. #==============================================================================

  375. module RPG
  376.   class Weapon
  377.     def description
  378.       description = @description.split(/@/)[0]
  379.       return description != nil ? description : ''
  380.     end
  381.     def desc
  382.       desc = @description.split(/@/)[1]
  383.       return desc != nil ? desc : "药品"
  384.     end
  385.   end
  386.   class Item
  387.     def description
  388.       description = @description.split(/@/)[0]
  389.       return description != nil ? description : ‘’
  390.     end
  391.     def desc
  392.       desc = @description.split(/@/)[1]
  393.       return desc != nil ? desc : "药品"
  394.     end
  395.   end
  396.   class Armor
  397.     def description
  398.       description = @description.split(/@/)[0]
  399.       return description != nil ? description : ''
  400.     end
  401.     def desc
  402.       desc = @description.split(/@/)[1]
  403.       return desc != nil ? desc : "药品"
  404.     end
  405.   end
  406. end
  407.   

  408. #==============================================================================
  409. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  410. #==============================================================================
复制代码

作者: yang1zhi    时间: 2014-11-9 11:55
最后那几行,三个药品看到了吗。自己改一下名字。
作者: chd114    时间: 2014-11-9 11:56
  1. if @commands == []
  2. @commands.push("药品")
  3. end
复制代码
是你背包什么都没有的时候(或者背包里的东西没设置分类的时候)依然会显示一个药品的分类
  1. #==============================================================================
  2. # ■ RPG追加定义,使用@符号分类
  3. #==============================================================================

  4. module RPG
  5.   class Weapon
  6.     def description
  7.       description = @description.split(/@/)[0]
  8.       return description != nil ? description : ''
  9.     end
  10.     def desc
  11.       desc = @description.split(/@/)[1]
  12.       return desc != nil ? desc : "药品"
  13.     end
  14.   end
  15.   class Item
  16.     def description
  17.       description = @description.split(/@/)[0]
  18.       return description != nil ? description : ‘’
  19.     end
  20.     def desc
  21.       desc = @description.split(/@/)[1]
  22.       return desc != nil ? desc : "药品"
  23.     end
  24.   end
  25.   class Armor
  26.     def description
  27.       description = @description.split(/@/)[0]
  28.       return description != nil ? description : ''
  29.     end
  30.     def desc
  31.       desc = @description.split(/@/)[1]
  32.       return desc != nil ? desc : "药品"
  33.     end
  34.   end
  35. end
复制代码
把这里的药品改了
作者: 1491968808    时间: 2014-11-9 14:28
以後發腳本記得用代碼框哦親。
作者: OCTSJimmy    时间: 2014-11-9 20:22
猜测应该是在物品的注释中加上 @武器、@防具等等你想分类的类名。应该就可以分类了。
楼主先测试下看看




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1