- 累计送礼:
 - 0 个
 
 - 累计收礼:
 - 0 个
 
 TA的每日心情  | 开心 2025-10-18 22:41 | 
|---|
 
  签到天数: 165 天 连续签到: 1 天 [LV.7]常住居民III 
  
管理员 
    
    
        - VIP
 
        - 6 
 
     
    
        - 卡币
 
        - 14829 
 
     
    
        - OK点
 
        - 16 
 
     
    
    - 推广点
 
    - 0 
 
     
	
    - 同能卷
 
    - 0 
 
     
  
	- 积分
 - 17954
 
 
  
 
  
 | 
 
现在站上的物品分类脚本主要有自动分类(根据能否使用等物品特性分类)和手动分类(通过在物品说明、物品名称后加后缀实现分类) 
这两种分类方式各有千秋。 
学习了一些脚本之后,我也自己尝试编写了一个物品分类脚本, 
它通过物品的属性进行分类(具体见截图和范例) 
因此一个物品可以同时被分到多个类中 
由于是第一次发布脚本,难免有BUG,望大家及时指正。
 
鸣谢: @癫狂侠客 的《脚本不是高手的专利》系列教程,如果有人想要学习脚本,可以去看看
 
现在发脚本的人越来越少了,是大家都会了,还是。。
 
截图:
 
RUBY 代码 - #==============================================================================
 - # ■ 物品手动分类 By gonglinyuan
 - #==============================================================================
 - #==============================================================================
 - # 以下是用户设定区
 - #==============================================================================
 - # 物品分类表;最后两个分别是武器和防具,不要动
 - $Item_Sort_Table = ["道具类","剧情类","武器类","防具类"]
 - # 设定用于物品分类的第一个属性,默认是从17号属性开始
 - $Item_Sort_Start = 17
 - #==============================================================================
 - # 物品的类别数目(不要动)
 - $Item_Sort_Size = $Item_Sort_Table.size - 2
 - #==============================================================================
 - # ■ Scene_Item
 - #------------------------------------------------------------------------------
 - #  处理物品画面的类。
 - #==============================================================================
 - class Scene_Item
 -   #--------------------------------------------------------------------------
 -   # ● 主处理
 -   #--------------------------------------------------------------------------
 -   def main
 -     # 生成帮助窗口、物品窗口
 -     @help_window = Window_Help.new
 -     @item_window = Window_MenuItem.new
 -     @item_window.active = false
 -     @item_window.index = -1
 -     # 生成分类窗口
 -     @sort_window = Window_Command.new(160,$Item_Sort_Table)
 -     @sort_window.y = 64
 -     @sort_window.active = true
 -     # 生成金钱窗口
 -     @gold_window = Window_Gold.new
 -     @gold_window.x = 0
 -     @gold_window.y = 416
 -     # 关联帮助窗口
 -     @item_window.help_window = @help_window
 -     # 生成目标窗口 (设置为不可见・不活动)
 -     @target_window = Window_Target.new
 -     @target_window.visible = false
 -     @target_window.active = false
 -     # 执行过度
 -     Graphics.transition
 -     # 主循环
 -     loopdo
 -       # 刷新游戏画面
 -       Graphics.update
 -       # 刷新输入信息
 -       Input.update
 -       # 刷新画面
 -       update
 -       # 如果画面切换就中断循环
 -       if$scene != self
 -         break
 -       end
 -     end
 -     # 装备过渡
 -     Graphics.freeze
 -     # 释放窗口
 -     @help_window.dispose
 -     @item_window.dispose
 -     @target_window.dispose
 -     @sort_window.dispose
 -     @gold_window.dispose
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 刷新画面
 -   #--------------------------------------------------------------------------
 -   def update
 -     # 刷新窗口
 -     @help_window.update
 -     @item_window.update
 -     @target_window.update
 -     @sort_window.update
 -     @gold_window.update
 -     # 分类窗口被激活的情况下: 调用 update_sort
 -     if@sort_window.active
 -       update_sort
 -       return
 -     end
 -     # 物品窗口被激活的情况下: 调用 update_item
 -     if@item_window.active
 -       update_item
 -       return
 -     end
 -     # 目标窗口被激活的情况下: 调用 update_target
 -     if@target_window.active
 -       update_target
 -       return
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 刷新画面 (分类窗口被激活的情况下)
 -   #--------------------------------------------------------------------------
 -   def update_sort
 -     if Input.trigger?(Input::B)
 -       # 演奏取消 SE
 -       $game_system.se_play($data_system.cancel_se)
 -       # 切换到菜单画面
 -       $scene = Scene_Menu.new(0)
 -       return
 -     end
 -     if Input.trigger?(Input::C)
 -       # 演奏确定 SE
 -       $game_system.se_play($data_system.decision_se)
 -       # 激活物品窗口
 -       @sort_window.active = false
 -       @item_window.active = true
 -       @item_window.index = 0
 -       @item_window.set_kind(@sort_window.index)
 -       @item_window.refresh
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 刷新画面 (物品窗口被激活的情况下)
 -   #--------------------------------------------------------------------------
 -   def update_item
 -     # 按下 B 键的情况下
 -     if Input.trigger?(Input::B)
 -       # 演奏取消 SE
 -       $game_system.se_play($data_system.cancel_se)
 -       # 清空物品窗口
 -       if@item_window.contents != nil
 -         @item_window.contents.dispose
 -         @item_window.contents = nil
 -       end
 -       # 激活分类窗口
 -       @item_window.active = false
 -       @item_window.index = -1
 -       @item_window.set_kind(-1)
 -       @sort_window.active = true
 -       return
 -     end
 -     # 按下 C 键的情况下
 -     if Input.trigger?(Input::C)
 -       # 获取物品窗口当前选中的物品数据
 -       @item = @item_window.item
 -       # 不使用物品的情况下
 -       unless@item.is_a?(RPG::Item)
 -         # 演奏冻结 SE
 -         $game_system.se_play($data_system.buzzer_se)
 -         return
 -       end
 -       # 不能使用的情况下
 -       unless$game_party.item_can_use?(@item.id)
 -         # 演奏冻结 SE
 -         $game_system.se_play($data_system.buzzer_se)
 -         return
 -       end
 -       # 演奏确定 SE
 -       $game_system.se_play($data_system.decision_se)
 -       # 效果范围是我方的情况下
 -       if@item.scope >= 3
 -         # 激活目标窗口
 -         @item_window.active = false
 -         @target_window.x = (@item_window.index + 1) % 2 * 304
 -         @target_window.visible = true
 -         @target_window.active = true
 -         # 设置效果范围 (单体/全体) 的对应光标位置
 -         if@item.scope == 4 || @item.scope == 6
 -           @target_window.index = -1
 -         else
 -           @target_window.index = 0
 -         end
 -       # 效果在我方以外的情况下
 -       else
 -         # 公共事件 ID 有效的情况下
 -         if@item.common_event_id > 0
 -           # 预约调用公共事件
 -           $game_temp.common_event_id = @item.common_event_id
 -           # 演奏物品使用时的 SE
 -           $game_system.se_play(@item.menu_se)
 -           # 消耗品的情况下
 -           if@item.consumable
 -             # 使用的物品数减 1
 -             $game_party.lose_item(@item.id, 1)
 -             # 再描绘物品窗口的项目
 -             @item_window.draw_item(@item_window.index)
 -           end
 -           # 切换到地图画面
 -           $scene = Scene_Map.new
 -           return
 -         end
 -       end
 -       return
 -     end
 -   end
 - end
 - #==============================================================================
 - # ■ Window_MenuItem
 - #------------------------------------------------------------------------------
 - #  物品画面显示浏览物品的窗口。
 - #==============================================================================
 - class Window_MenuItem < Window_Selectable
 -   #--------------------------------------------------------------------------
 -   # ● 初始化对像
 -   #--------------------------------------------------------------------------
 -   def initialize
 -     super(160, 64, 480, 416)
 -     @column_max = 2
 -     self.index = 0
 -     @data = []
 -     @kind = -1# 0 = 物品;1 = 武器;2 = 防具
 -     refresh
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 设置物品种类
 -   #--------------------------------------------------------------------------
 -   def set_kind(item_kind)
 -     @kind = item_kind
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 获取物品
 -   #--------------------------------------------------------------------------
 -   def item
 -     return@data[self.index]
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 刷新
 -   #--------------------------------------------------------------------------
 -   def refresh
 -     ifself.contents != nil
 -       self.contents.dispose
 -       self.contents = nil
 -     end
 -     @data = []
 -     # 添加物品
 -     case@kind
 -     when0...$Item_Sort_Size
 -       for i in1...$data_items.size
 -         if$data_items[i].element_set.include?($Item_Sort_Start + @kind)
 -           if$game_party.item_number(i) > 0
 -             @data.push($data_items[i])
 -           end
 -         end
 -       end
 -     when$Item_Sort_Size
 -       for i in1...$data_weapons.size
 -         if$game_party.weapon_number(i) > 0
 -           @data.push($data_weapons[i])
 -         end
 -       end
 -     when$Item_Sort_Size + 1
 -       for i in1...$data_armors.size
 -         if$game_party.armor_number(i) > 0
 -           @data.push($data_armors[i])
 -         end
 -       end
 -     end
 -     # 如果项目数不是 0 就生成位图、重新描绘全部项目
 -     @item_max = @data.size
 -     if@item_max > 0
 -       self.contents = Bitmap.new(width - 32, row_max * 32)
 -       for i in0...@item_max
 -         draw_item(i)
 -       end
 -     end
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 描绘项目
 -   #     index : 项目编号
 -   #--------------------------------------------------------------------------
 -   def draw_item(index)
 -     item = @data[index]
 -     case item
 -     whenRPG::Item
 -       number = $game_party.item_number(item.id)
 -     whenRPG::Weapon
 -       number = $game_party.weapon_number(item.id)
 -     whenRPG::Armor
 -       number = $game_party.armor_number(item.id)
 -     end
 -     if item.is_a?(RPG::Item)and
 -        $game_party.item_can_use?(item.id)
 -       self.contents.font.color = normal_color
 -     else
 -       self.contents.font.color = disabled_color
 -     end
 -     x = 4 + index % 2 * 240
 -     y = index / 2 * 32
 -     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
 -     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
 -     bitmap = RPG::Cache.icon(item.icon_name)
 -     opacity = self.contents.font.color == normal_color ? 255 : 128
 -     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
 -     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
 -     self.contents.draw_text(x + 160, y, 16, 32, ":", 1)
 -     self.contents.draw_text(x + 176, y, 24, 32, number.to_s, 2)
 -   end
 -   #--------------------------------------------------------------------------
 -   # ● 刷新帮助文本
 -   #--------------------------------------------------------------------------
 -   def update_help
 -     @help_window.set_text(self.item == nil ? "" : self.item.description)
 -   end
 - end
 
  复制代码
             本帖来自P1论坛作者gonglinyuan,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址: https://rpg.blue/forum.php?mod=viewthread&tid=328345  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。  |   
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 
		
		
		 
 
 |