设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1175|回复: 1
打印 上一主题 下一主题

[已经解决] 还是关于道具限制使用的脚本

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
33 小时
注册时间
2011-1-18
帖子
16
跳转到指定楼层
1
发表于 2012-1-6 13:57:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 mugencomic 于 2012-1-6 15:01 编辑

之前弄道具使用限制不敢劳烦大家太多,结果不求甚解了=  =
琢磨了一下弄了这样一个脚本

game_party类初始化方法添加——
  1. @item_use_rule = {}
  2.     for i in 1..1000
  3.       @item_use_rule[i] = []         #初始化角色禁用道具规则
  4.     end
  5.     @item_use_rule[1] = [1,2,3]        #定义第一位角色禁用物品ID
复制代码
定义新方法(为了不与道具菜单冲突因为顺序不一样,战斗中能获取角色ID)——
  1. #--------------------------------------------------------------------------
  2.   #        ■■       增加判定是否为角色限制使用物品        ■■
  3.   #
  4.   #--------------------------------------------------------------------------
  5.   def item_can_use_for_him?(item_id,actor_id=1000)
  6.     a = item_id
  7.     b = actor_id
  8.         if @item_use_rule[b] != nil  
  9.           if @item_use_rule[b].include?(a)
  10.         return false
  11.           else return true
  12.           end
  13.          else return true
  14.         end  
  15.   end  
复制代码
Window_Item的draw_item方法
  1. if item.is_a?(RPG::Item) and
  2.        $game_party.item_can_use?(item.id) and  $game_party.item_can_use_for_him?(item.id,@actor_id)  
复制代码
Scene_Battle的start_item_select方法
  1. # 生成物品窗口
  2.     @item_window = Window_Item.new(@active_battler)
复制代码
结果没有效果,哪个环节出错了?

点评

收到通知后请处理认可  发表于 2012-1-17 00:36

Lv2.观梦者

梦石
0
星屑
275
在线时间
1373 小时
注册时间
2005-10-16
帖子
5113

贵宾

2
发表于 2012-1-7 09:48:29 | 只看该作者
本帖最后由 亿万星辰 于 2012-1-7 10:46 编辑

@item_window = Window_Item.new(@active_battler.id)
  1. class Game_Party
  2.   ITEM_FORBID4class = {}
  3.   # 1号职业禁止使用的物品
  4.   ITEM_FORBID4class[1] = [1]
  5.   # --------------------
  6.   ITEM_FORBID4actor = {}
  7.   # 1号角色禁止使用的物品
  8.   ITEM_FORBID4actor[1] = [2]
  9.   # --------------------
  10.   
  11.   #--------------------------------------------------------------------------
  12.   # ● 判断物品可以使用
  13.   #     item_id : 物品 ID
  14.   #--------------------------------------------------------------------------
  15.   alias old_icu? item_can_use?
  16.   def item_can_use?(item_id, actor_id = 0)
  17.     # 如果当前物品在对应角色和职业的禁止使用物品列表里
  18.     if actor_id != 0 and ITEM_FORBID4actor.key?(actor_id) and
  19.       ITEM_FORBID4class.key?($game_actors[actor_id].class_id)
  20.       if ITEM_FORBID4actor[actor_id].include?(item_id) or
  21.         ITEM_FORBID4class[$game_actors[actor_id].class_id].include?(item_id)
  22.         return false
  23.       end
  24.     end
  25.     old_icu?(item_id)
  26.   end
  27. end

  28. class Window_Item < Window_Selectable
  29.   #--------------------------------------------------------------------------
  30.   # ● 初始化对像
  31.   #--------------------------------------------------------------------------
  32.   alias old_ini initialize
  33.   def initialize(actor_id = 0)
  34.     @actor_id = actor_id
  35.     old_ini
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 描绘项目
  39.   #     index : 项目编号
  40.   #--------------------------------------------------------------------------
  41.   def draw_item(index)
  42.     item = @data[index]
  43.     case item
  44.     when RPG::Item
  45.       number = $game_party.item_number(item.id)
  46.     when RPG::Weapon
  47.       number = $game_party.weapon_number(item.id)
  48.     when RPG::Armor
  49.       number = $game_party.armor_number(item.id)
  50.     end
  51.     if item.is_a?(RPG::Item) and
  52.        $game_party.item_can_use?(item.id, @actor_id)
  53.       self.contents.font.color = normal_color
  54.     else
  55.       self.contents.font.color = disabled_color
  56.     end
  57.     x = 4 + index % 2 * (288 + 32)
  58.     y = index / 2 * 32
  59.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  60.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  61.     bitmap = RPG::Cache.icon(item.icon_name)
  62.     opacity = self.contents.font.color == normal_color ? 255 : 128
  63.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  64.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  65.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  66.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  67.   end
  68. end

  69. class Scene_Battle
  70.   #--------------------------------------------------------------------------
  71.   # ● 开始选择物品
  72.   #--------------------------------------------------------------------------
  73.   def start_item_select
  74.     # 生成物品窗口
  75.     @item_window = Window_Item.new(@active_battler.id)
  76.     # 关联帮助窗口
  77.     @item_window.help_window = @help_window
  78.     # 无效化角色指令窗口
  79.     @actor_command_window.active = false
  80.     @actor_command_window.visible = false
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● 刷新画面 (角色命令回合 : 选择物品)
  84.   #--------------------------------------------------------------------------
  85.   def update_phase3_item_select
  86.     # 设置物品窗口为可视状态
  87.     @item_window.visible = true
  88.     # 刷新物品窗口
  89.     @item_window.update
  90.     # 按下 B 键的情况下
  91.     if Input.trigger?(Input::B)
  92.       # 演奏取消 SE
  93.       $game_system.se_play($data_system.cancel_se)
  94.       # 选择物品结束
  95.       end_item_select
  96.       return
  97.     end
  98.     # 按下 C 键的情况下
  99.     if Input.trigger?(Input::C)
  100.       # 获取物品窗口现在选择的物品资料
  101.       @item = @item_window.item
  102.       # 无法使用的情况下
  103.       unless $game_party.item_can_use?(@item.id, @active_battler.id)
  104.         # 演奏冻结 SE
  105.         $game_system.se_play($data_system.buzzer_se)
  106.         return
  107.       end
  108.       # 演奏确定 SE
  109.       $game_system.se_play($data_system.decision_se)
  110.       # 设置行动
  111.       @active_battler.current_action.item_id = @item.id
  112.       # 设置物品窗口为不可见状态
  113.       @item_window.visible = false
  114.       # 效果范围是敌单体的情况下
  115.       if @item.scope == 1
  116.         # 开始选择敌人
  117.         start_enemy_select
  118.       # 效果范围是我方单体的情况下
  119.       elsif @item.scope == 3 or @item.scope == 5
  120.         # 开始选择角色
  121.         start_actor_select
  122.       # 效果范围不是单体的情况下
  123.       else
  124.         # 物品选择结束
  125.         end_item_select
  126.         # 转到下一位角色的指令输入
  127.         phase3_next_actor
  128.       end
  129.       return
  130.     end
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ● 生成物品行动结果
  134.   #--------------------------------------------------------------------------
  135.   def make_item_action_result
  136.     # 获取物品
  137.     @item = $data_items[@active_battler.current_action.item_id]
  138.     # 因为物品耗尽而无法使用的情况下
  139.     unless $game_party.item_can_use?(@item.id, @active_battler.id)
  140.       # 移至步骤 1
  141.       @phase4_step = 1
  142.       return
  143.     end
  144.     # 消耗品的情况下
  145.     if @item.consumable
  146.       # 使用的物品减 1
  147.       $game_party.lose_item(@item.id, 1)
  148.     end
  149.     # 在帮助窗口显示物品名
  150.     @help_window.set_text(@item.name, 1)
  151.     # 设置动画 ID
  152.     @animation1_id = @item.animation1_id
  153.     @animation2_id = @item.animation2_id
  154.     # 设置公共事件 ID
  155.     @common_event_id = @item.common_event_id
  156.     # 确定对像
  157.     index = @active_battler.current_action.target_index
  158.     target = $game_party.smooth_target_actor(index)
  159.     # 设置对像侧战斗者
  160.     set_target_battlers(@item.scope)
  161.     # 应用物品效果
  162.     for target in @target_battlers
  163.       target.item_effect(@item)
  164.     end
  165.   end
  166. end
复制代码
我只个搬答案的
叔叔我已经当爹了~
婚后闪人了……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-10-1 06:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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