Project1

标题: 关于物品分类的一些脚本问题! [打印本页]

作者: zl90349166    时间: 2008-7-17 19:09
提示: 作者被禁止或删除 内容自动屏蔽
作者: HзO    时间: 2008-7-17 19:17
简单物品分类
http://rpg.blue/web/htm/news126.htm
作者: HзO    时间: 2008-7-17 19:19
如果要添加材料,先在数据库中设置,比如编号第1到150的物品都是材料

大约在该脚本125行:
  def set_item(command)
    refresh
    case command
    when 0
      for i in 1...150
        if ($data_items.occasion == 0 or $data_items.occasion == 1 or $data_items.occasion == 2 or $data_items.occasion == 3) and $game_party.item_number(i) > 0
          @data.push($data_items)
        end
      end
....................
..........
.............

作者: zl90349166    时间: 2008-7-17 19:25
提示: 作者被禁止或删除 内容自动屏蔽
作者: 灯笼菜刀王    时间: 2008-7-17 19:37
用这个脚本吧,根据道具的分散度来分类。
要添加项就在这里改
def initialize
   super(0, 64, 160, 160+32)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 5
    @commands = ["药物", "食物", "特殊道具","装备","剧情道具"]
    refresh
    self.index = 0
  end
@item_max = 5 数字改成6,7,8等等,
@commands=[]里自己添。

然后改下面的when,按照上面的画下葫芦,把分散度改下,就可以自定义分类了。
建议,恢复类的物品分类为0,因为分散度会影响恢复效果。


  1. # ————————————————————————————————————
  2. # 本脚本来自www.66rpg.com,转载请保留此信息
  3. # ————————————————————————————————————

  4. #==============================================================================
  5. # ■ Harts_Window_ItemTitle
  6. #------------------------------------------------------------------------------
  7. #  アイテム画面で、タイトルを表示するウィンドウ。
  8. #==============================================================================

  9. class Harts_Window_ItemTitle < Window_Base
  10.   #--------------------------------------------------------------------------
  11.   # ● オブジェクト初期化
  12.   #--------------------------------------------------------------------------
  13.   def initialize
  14.     super(0, 0, 160, 64)
  15.     self.contents = Bitmap.new(width - 32, height - 32)
  16.     self.contents.clear
  17.     #self.contents.blt(x,y,@bitmap1,@src_rect1)
  18.     self.contents.font.color = normal_color
  19.     self.contents.draw_text(4, 0, 120, 32, $data_system.words.item, 1)
  20.   end
  21. end

  22. #==============================================================================
  23. # ■ Harts_Window_ItemCommand
  24. #------------------------------------------------------------------------------
  25. #  アイテムの種別選択を行うウィンドウです。
  26. #==============================================================================

  27. class Harts_Window_ItemCommand < Window_Selectable
  28.   #--------------------------------------------------------------------------
  29.   # ● オブジェクト初期化
  30.   #--------------------------------------------------------------------------
  31.   def initialize
  32.    super(0, 64, 160, 160+32)
  33.     self.contents = Bitmap.new(width - 32, height - 32)
  34.     @item_max = 5
  35.     @commands = ["药物", "食物", "特殊道具","装备","剧情道具"]
  36.     refresh
  37.     self.index = 0
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● リフレッシュ
  41.   #--------------------------------------------------------------------------
  42.   def refresh
  43.     self.contents.clear
  44.     for i in 0...@item_max
  45.     draw_item(i, normal_color)
  46.     end
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # ● 項目の描画
  50.   # index : 項目番号
  51.   # color : 文字色
  52.   #--------------------------------------------------------------------------
  53.   def draw_item(index, color)
  54.     self.contents.font.color = color
  55.     y = index * 32
  56.     self.contents.draw_text(4, y, 128, 32, @commands[index])
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● ヘルプテキスト更新
  60.   #--------------------------------------------------------------------------
  61.   def update_help
  62.     case self.index
  63.     when 0
  64.       @text = @commands[0]
  65.     when 1
  66.       @text = @commands[1]
  67.     when 2
  68.       @text = @commands[2]
  69.     when 3
  70.       @text = @commands[3]
  71.     when 4
  72.       @text = @commands[4]
  73.     when 5
  74.       @text = @commands[5]
  75.     when 6
  76.       @text = @commands[6]
  77.     when 7
  78.       @text = @commands[7]
  79.     when 8
  80.       @text = @commands[8]
  81.     end
  82.     @help_window.set_text(@text)
  83.   end
  84. end

  85. #==============================================================================
  86. # ■ Window_Item
  87. #------------------------------------------------------------------------------
  88. #  アイテム画面で、所持アイテムの一覧を表示するウィンドウです。
  89. #==============================================================================

  90. class Harts_Window_ItemList < Window_Selectable
  91.   #--------------------------------------------------------------------------
  92.   # ● オブジェクト初期化
  93.   #--------------------------------------------------------------------------
  94.   def initialize
  95.     super(160, 0, 480, 416)
  96.    
  97.     refresh
  98.     self.index = 0
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● アイテムの取得
  102.   #--------------------------------------------------------------------------
  103.   def item
  104.     return @data[self.index]
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● リフレッシュ
  108.   #--------------------------------------------------------------------------
  109.   def refresh
  110.     if self.contents != nil
  111.       self.contents.dispose
  112.       self.contents = nil
  113.     end
  114.     @data = []
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● アイテム一覧設定
  118.   # command : 選択中のコマンド
  119.   #--------------------------------------------------------------------------
  120.   def set_item(command)
  121.     refresh
  122.     case command  
  123.     when 0            #药品,特点是分散度为0
  124.       for i in 1...$data_items.size
  125.         if ($data_items[i].variance == 0 and $game_party.item_number(i) > 0)
  126.           @data.push($data_items[i])
  127.         end
  128.       end
  129.     when 1            #食物类,特点是分散度为1  
  130.       for i in 1...$data_items.size
  131.         if ($data_items[i].variance == 1 and $game_party.item_number(i) > 0)
  132.           @data.push($data_items[i])
  133.         end
  134.       end
  135.     when 2            #杂货类,特点是分散度为2
  136.       for i in 1...$data_items.size
  137.         if ($data_items[i].variance == 2 and $game_party.item_number(i) > 0)
  138.           @data.push($data_items[i])
  139.         end
  140.       end
  141.     when 3            #各种装备:根据原本类push
  142.       for i in 1...$data_weapons.size
  143.         if $game_party.weapon_number(i) > 0
  144.           @data.push($data_weapons[i])
  145.         end
  146.       end
  147.       for i in 1...$data_armors.size
  148.         if $game_party.armor_number(i) > 0
  149.           @data.push($data_armors[i])
  150.         end
  151.       end
  152.     when 4            #剧情:特点是分散度为3
  153.       for i in 1...$data_items.size
  154.         if ($data_items[i].variance == 3 and $game_party.item_number(i) > 0)
  155.           @data.push($data_items[i])
  156.         end
  157.       end
  158.    
  159.     end
  160.     # 項目数が 0 でなければビットマップを作成し、全項目を描画
  161.     @item_max = @data.size
  162.     if @item_max > 0
  163.       self.contents = Bitmap.new(width - 32, row_max * 32)
  164.       self.contents.clear
  165.       for i in 0...@item_max
  166.         draw_item(i)
  167.       end
  168.     end
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # ● 種類別アイテム数の取得
  172.   #--------------------------------------------------------------------------
  173.   def item_number
  174.     return @item_max
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 項目の描画
  178.   # index : 項目番号
  179.   #--------------------------------------------------------------------------
  180.   def draw_item(index)
  181.     item = @data[index]
  182.     case item
  183.     when RPG::Item
  184.       number = $game_party.item_number(item.id)
  185.     when RPG::Weapon
  186.       number = $game_party.weapon_number(item.id)
  187.     when RPG::Armor
  188.       number = $game_party.armor_number(item.id)
  189.     end
  190.     if item.is_a?(RPG::Item) and
  191.       $game_party.item_can_use?(item.id)
  192.       self.contents.font.color = normal_color
  193.     else
  194.       self.contents.font.color = disabled_color
  195.     end
  196.     x = 4
  197.     y = index * 32
  198.     bitmap = RPG::Cache.icon(item.icon_name)
  199.     opacity = self.contents.font.color == normal_color ? 255 : 128
  200.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  201.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  202.     self.contents.draw_text(x + 400, y, 16, 32, ":", 1)
  203.     self.contents.draw_text(x + 416, y, 24, 32, number.to_s, 2)
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● ヘルプテキスト更新
  207.   #--------------------------------------------------------------------------
  208.   def update_help
  209.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  210.   end
  211. end

  212. #==============================================================================
  213. # ■ Harts_Scene_Item
  214. #------------------------------------------------------------------------------
  215. #  アイテム画面の処理を行うクラスです。再定義
  216. #==============================================================================

  217. class Scene_Item
  218.   #--------------------------------------------------------------------------
  219.   # ● メイン処理
  220.   #--------------------------------------------------------------------------
  221.   def main
  222.    picture = "Graphics/Battlebacks/北惧.jpg"
  223.    @sprite = Sprite.new
  224.    @sprite.bitmap = Bitmap.new(picture)

  225.     # タイトルウィンドウを作成
  226.     @itemtitle_window = Harts_Window_ItemTitle.new
  227.     #コマンドウィンドウを作成
  228.     @itemcommand_window = Harts_Window_ItemCommand.new
  229.     @command_index = @itemcommand_window.index
  230.     #アイテムウィンドウを作成
  231.     @itemlist_window = Harts_Window_ItemList.new
  232.     @itemlist_window.active = false
  233.     #ヘルプウィンドウを作成
  234.     @help_window = Window_Help.new
  235.     @help_window.x = 0
  236.     @help_window.y = 416
  237.     # ヘルプウィンドウを関連付け
  238.     @itemcommand_window.help_window = @help_window
  239.     @itemlist_window.help_window = @help_window
  240.     # ターゲットウィンドウを作成 (不可視?非アクティブに設定)
  241.     @target_window = Window_Target.new
  242.     @target_window.visible = false
  243.     @target_window.active = false
  244.     # アイテムウィンドウ内容表示
  245.     @itemlist_window.set_item(@command_index)
  246.     # トランジション実行
  247.     Graphics.transition
  248.     # メインループ
  249.     loop do
  250.       # ゲーム画面を更新
  251.       Graphics.update
  252.       # 入力情報を更新
  253.       Input.update
  254.       # フレーム更新
  255.       update
  256.       # 画面が切り替わったらループを中断
  257.       if $scene != self
  258.         break
  259.       end
  260.     end
  261.     # トランジション準備
  262.     Graphics.freeze
  263.     # ウィンドウを解放
  264.      @sprite.dispose
  265.    @sprite.bitmap.dispose unless @sprite.bitmap.disposed?
  266.    @itemtitle_window.dispose
  267.     @itemcommand_window.dispose
  268.     @itemlist_window.dispose
  269.     @help_window.dispose
  270.     @target_window.dispose
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # ● フレーム更新
  274.   #--------------------------------------------------------------------------
  275.   def update
  276.     # ウィンドウを更新
  277.     @itemtitle_window.update
  278.     @itemcommand_window.update
  279.     @itemlist_window.update
  280.     @help_window.update
  281.     @target_window.update
  282.     if @command_index != @itemcommand_window.index
  283.       @command_index = @itemcommand_window.index
  284.       @itemlist_window.set_item(@command_index)
  285.     end
  286.     # コマンドウィンドウがアクティブの場合: update_itemcommand を呼ぶ
  287.     if @itemcommand_window.active
  288.       update_itemcommand
  289.       return
  290.     end
  291.     # アイテムウィンドウがアクティブの場合: update_itemlist を呼ぶ
  292.     if @itemlist_window.active
  293.       update_itemlist
  294.       return
  295.     end
  296.     # ターゲットウィンドウがアクティブの場合: update_target を呼ぶ
  297.     if @target_window.active
  298.       update_target
  299.       return
  300.     end
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● フレーム更新 (コマンドウィンドウがアクティブの場合)
  304.   #--------------------------------------------------------------------------
  305.   def update_itemcommand
  306.   # B ボタンが押された場合
  307.   if Input.trigger?(Input::B)
  308.   # キャンセル SE を演奏
  309.   $game_system.se_play($data_system.cancel_se)
  310.   # メニュー画面に切り替え
  311.   $scene = Scene_Map.new
  312.   return
  313.   end
  314.   # C ボタンが押された場合
  315.   if Input.trigger?(Input::C)
  316.   # 選択中のコマンドのアイテムがない場合
  317.   if @itemlist_window.item_number == 0
  318.   # ブザー SE を演奏
  319.   $game_system.se_play($data_system.buzzer_se)
  320.   return
  321.   end
  322.   # 決定 SE を演奏
  323.   $game_system.se_play($data_system.decision_se)
  324.   # アイテムウィンドウをアクティブにする
  325.   @itemcommand_window.active = false
  326.   @itemlist_window.active = true
  327.   @itemlist_window.index = 0
  328.   return
  329.   end
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # ● フレーム更新 (アイテムウィンドウがアクティブの場合)
  333.   #--------------------------------------------------------------------------
  334.   def update_itemlist
  335.     # B ボタンが押された場合
  336.     if Input.trigger?(Input::B)
  337.       # キャンセル SE を演奏
  338.       $game_system.se_play($data_system.cancel_se)
  339.       # アイテムウィンドウをアクティブにする
  340.       @itemcommand_window.active = true
  341.       @itemlist_window.active = false
  342.       @itemlist_window.index = 0
  343.       @itemcommand_window.index = @command_index
  344.       return
  345.     end
  346.     # C ボタンが押された場合
  347.     if Input.trigger?(Input::C)
  348.       # アイテムウィンドウで現在選択されているデータを取得
  349.       @item = @itemlist_window.item
  350.       # 使用アイテムではない場合
  351.       unless @item.is_a?(RPG::Item)
  352.         # ブザー SE を演奏
  353.         $game_system.se_play($data_system.buzzer_se)
  354.         return
  355.       end
  356.       # 使用できない場合
  357.       unless $game_party.item_can_use?(@item.id)
  358.         # ブザー SE を演奏
  359.         $game_system.se_play($data_system.buzzer_se)
  360.         return
  361.       end
  362.       # 決定 SE を演奏
  363.       $game_system.se_play($data_system.decision_se)
  364.       # 効果範囲が味方の場合
  365.       if @item.scope >= 3
  366.         # ターゲットウィンドウをアクティブ化
  367.         @itemlist_window.active = false
  368.         @target_window.x = 304
  369.         @target_window.visible = true
  370.         @target_window.active = true
  371.         # 効果範囲 (単体/全体) に応じてカーソル位置を設定
  372.         if @item.scope == 4 || @item.scope == 6
  373.           @target_window.index = -1
  374.         else
  375.           @target_window.index = 0
  376.         end
  377.         # 効果範囲が味方以外の場合
  378.       else
  379.         # コモンイベント ID が有効の場合
  380.         if @item.common_event_id > 0
  381.           # コモンイベント呼び出し予約
  382.           $game_temp.common_event_id = @item.common_event_id
  383.           # アイテムの使用時 SE を演奏
  384.           $game_system.se_play(@item.menu_se)
  385.           # 消耗品の場合
  386.             if @item.consumable
  387.               # 使用したアイテムを 1 減らす
  388.               $game_party.lose_item(@item.id, 1)
  389.               # アイテムウィンドウの項目を再描画
  390.               @itemlist_window.draw_item(@itemlist_window.index)
  391.             end
  392.           # マップ画面に切り替え
  393.           $scene = Scene_Map.new
  394.           return
  395.         end
  396.       end
  397.       return
  398.     end
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # ● フレーム更新 (ターゲットウィンドウがアクティブの場合)
  402.   #--------------------------------------------------------------------------
  403.   def update_target
  404.     # B ボタンが押された場合
  405.     if Input.trigger?(Input::B)
  406.       # キャンセル SE を演奏
  407.       $game_system.se_play($data_system.cancel_se)
  408.       # アイテム切れなどで使用できなくなった場合
  409.       unless $game_party.item_can_use?(@item.id)
  410.         # アイテムウィンドウの内容を再作成
  411.         @itemlist_window.refresh
  412.       end
  413.       # ターゲットウィンドウを消去
  414.       @itemlist_window.active = true
  415.       @target_window.visible = false
  416.       @target_window.active = false
  417.       @itemlist_window.set_item(@command_index)
  418.       return
  419.     end
  420.     # C ボタンが押された場合
  421.     if Input.trigger?(Input::C)
  422.       # アイテムを使い切った場合
  423.       if $game_party.item_number(@item.id) == 0
  424.         # ブザー SE を演奏
  425.         $game_system.se_play($data_system.buzzer_se)
  426.         return
  427.       end
  428.       # ターゲットが全体の場合
  429.       if @target_window.index == -1
  430.         # パーティ全体にアイテムの使用効果を適用
  431.         used = false
  432.         for i in $game_party.actors
  433.           used |= i.item_effect(@item)
  434.         end
  435.       end
  436.       # ターゲットが単体の場合
  437.       if @target_window.index >= 0
  438.         # ターゲットのアクターにアイテムの使用効果を適用
  439.         target = $game_party.actors[@target_window.index]
  440.         used = target.item_effect(@item)
  441.       end
  442.       # アイテムを使った場合
  443.       if used
  444.         # アイテムの使用時 SE を演奏
  445.         $game_system.se_play(@item.menu_se)
  446.         # 消耗品の場合
  447.         if @item.consumable
  448.           # 使用したアイテムを 1 減らす
  449.           $game_party.lose_item(@item.id, 1)
  450.           # アイテムウィンドウの項目を再描画
  451.           @itemlist_window.draw_item(@itemlist_window.index)
  452.           @itemlist_window.set_item(@command_index)
  453.         end
  454.         # ターゲットウィンドウの内容を再作成
  455.         @target_window.refresh
  456.         # 全滅の場合
  457.         if $game_party.all_dead?
  458.           # ゲームオーバー画面に切り替え
  459.           $scene = Scene_Gameover.new
  460.           return
  461.         end
  462.         # コモンイベント ID が有効の場合
  463.         if @item.common_event_id > 0
  464.           # コモンイベント呼び出し予約
  465.           $game_temp.common_event_id = @item.common_event_id
  466.           # マップ画面に切り替え
  467.           $scene = Scene_Map.new
  468.           return
  469.         end
  470.       end
  471.       # アイテムを使わなかった場合
  472.       unless used
  473.         # ブザー SE を演奏
  474.         $game_system.se_play($data_system.buzzer_se)
  475.       end
  476.     return
  477.     end
  478.   end
  479. end
复制代码

作者: HзO    时间: 2008-7-17 19:59

自己先在数据库里划分,比如编号第1到150的物品都是材料,编号第151到200的是都是重要物品
大概在脚本39行按自己要求命名,比如:  @commands = ["材料", "重要物品", "各种武器", "盾牌防具", "头部防具.........




然后脚本125行:
  def set_item(command)
    refresh
    case command
    when 0
      for i in 1...150
        # 材料
        if ($data_items.occasion == 0 or $data_items.occasion == 1 or $data_items.occasion == 2 or $data_items.occasion == 3) and $game_party.item_number(i) > 0
          @data.push($data_items)
        end
      end
    when 1
      for i in 151...200
        # 重要物品
        if ($data_items.occasion == 0 or $data_items.occasion == 1 or $data_items.occasion == 2 or $data_items.occasion == 3) and $game_party.item_number(i) > 0
          @data.push($data_items)
        end
      end
作者: zl90349166    时间: 2008-7-17 20:22
提示: 作者被禁止或删除 内容自动屏蔽
作者: zl90349166    时间: 2008-7-17 20:24
提示: 作者被禁止或删除 内容自动屏蔽
作者: yuscvscv    时间: 2008-7-17 20:56
提示: 作者被禁止或删除 内容自动屏蔽
作者: zl90349166    时间: 2008-7-17 21:10
提示: 作者被禁止或删除 内容自动屏蔽
作者: zl90349166    时间: 2008-7-17 21:17
提示: 作者被禁止或删除 内容自动屏蔽
作者: 灯笼菜刀王    时间: 2008-7-17 21:21
在刷新光标矩形那里,

把光标self.cursor_rect.set(x,y,width,height)里 y加上或者减去一些数字调整下就行了。
作者: yuscvscv    时间: 2008-7-17 21:23
提示: 作者被禁止或删除 内容自动屏蔽
作者: zl90349166    时间: 2008-7-17 21:35
提示: 作者被禁止或删除 内容自动屏蔽
作者: 灯笼菜刀王    时间: 2008-7-17 21:42
当然搜不到...

这个是我写的例子

脚本里的括号里都写着具体数字和变量的。

你找看看那个脚本有没有类似这样的句子,如果没有,就到它的父类Window_Selectable里找
刷新光标举行那行,从def到end那段全挖下来,然后塞进脚本的最后一个end前,在挖下来的那段里改坐标。

作者: zl90349166    时间: 2008-7-17 22:41
提示: 作者被禁止或删除 内容自动屏蔽
作者: zl90349166    时间: 2008-7-17 23:17
提示: 作者被禁止或删除 内容自动屏蔽
作者: 灯笼菜刀王    时间: 2008-7-17 23:24
#--------------------------------------------------------------------------
# ● 項目の描画
# index : 項目番号
# color : 文字色
#--------------------------------------------------------------------------
def draw_item(index, color)
   self.contents.font.color = color
   y = index * 35
   self.contents.draw_text(4, y, 128, 32, @commands[index])
end


改成

#--------------------------------------------------------------------------
# ● 項目の描画
# index : 項目番号
# color : 文字色
#--------------------------------------------------------------------------
def draw_item(index, color)
   self.contents.font.color = color
   y = index * 32
   self.contents.draw_text(4, y, 128, 32, @commands[index])
end

作者: zl90349166    时间: 2008-7-17 23:30
提示: 作者被禁止或删除 内容自动屏蔽




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