查看: 2093|回复: 3

[已经解决] 这个脚本,我不带武器时会出错

[复制链接]
梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2014-10-15 12:51:13 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#==============================================================================
# ■仿仙剑的群体攻击(鞭)、仙风云体步(仙女剑)以及敌人的双次攻击效果
#------------------------------------------------------------------------------
# 实现角色的攻击特点、武器的攻击特点、敌人的攻击特点  Ver 1.00
#==============================================================================


就是这个脚本。
我取了其中出错这一部分。
就是设置某状态为连击。
有装备武器时不会出错。当没拿武器时,
if (actor.current_action.basic == 0 and actor.restriction == 0 and  $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")
这一行就报错。



[pre lang="ruby" line="1"]def make_action_orders
    # 初始化序列 @action_battlers
    @action_battlers = []
    # 添加敌人到 @action_battlers 序列
    for enemy in $game_troop.enemies
      @action_battlers.push(enemy)
      if enemy.ifXianfeng
        @action_battlers.push(enemy)
      end
    end
    # 添加角色到 @action_battlers 序列
    for actor in $game_party.actors
      @action_battlers.push(actor)
      if (actor.current_action.basic == 0 and actor.restriction == 0 and  $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")
        @action_battlers.push(actor)
      else
        if actor.state?(Xianfengstate)
          @action_battlers.push(actor)
        end
      end
    end
    # 确定全体的行动速度
    for battler in @action_battlers
      battler.make_action_speed
    end
    # 按照行动速度从大到小排列
    @action_battlers.sort! {|a,b|
      b.current_action.speed - a.current_action.speed }
  end[/pre]

点评

只有没装备武器攻击时会出错,在地图行走时没事。。。难道你战斗不带武器?那用这个脚本干嘛?  发表于 2014-10-15 13:17
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2014-10-15 13:59:52 | 显示全部楼层
没有武器时,角色装备的武器ID设置为0,所以$data_weapons[0]为nil,因此调用$data_weapons[0].name会发生no method error。这也是写脚本的人没有注意到的吧。
问题产生原因分析完毕,解决方法如下。
14行改成:
[pre lang="Ruby"]if actor.current_action.basic == 0 && actor.restriction == 0 && actor.weapon_id != 0 && $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")[/pre]
if语句有些长,不过为了防止BUG只能如此。
回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

 楼主| 发表于 2014-10-15 23:06:49 | 显示全部楼层
RyanBern 发表于 2014-10-15 13:59
没有武器时,角色装备的武器ID设置为0,所以$data_weapons[0]为nil,因此调用$data_weapons[0].name会发生n ...

求救。
我用了您给出的修改后。那一行没出错了。不过第139行的群攻出错了。
这个脚本说可以设状态仙风,于是我设37为仙风状态。人物没拿武器时就出错。
经过您的修改后,仙风那一行没出错了。
这次群攻那一行出错了。
不过我是加的仙风状态。


[pre lang="ruby" line="1"]#==============================================================================
# ■仿仙剑的群体攻击(鞭)、仙风云体步(仙女剑)以及敌人的双次攻击效果
#------------------------------------------------------------------------------
# 实现角色的攻击特点、武器的攻击特点、敌人的攻击特点  Ver 1.00
#==============================================================================

#用前须知
#首先请搞清楚,群攻是指林月如的鞭系那种攻击对方全体的普通攻击;
#仙风云体步是指赵灵儿用双剑攻击的每回合对同一敌人的两次普通攻击;
#在这个仿仙剑一的版本中,敌人的仙风云体步设置为双次攻击效果

#1.设置群体攻击的敌人,只需要在数据库敌人属性名字后面加后缀"@群攻"
#2.设置仙风云体步的敌人,需要在数据库敌人属性名字后面加后缀"@@仙风"注意是两个"@"
#3.如果一个敌人既是群攻又是仙风云体步,敌人属性名字后面加后缀"@群攻@仙风"

#4.设置群体攻击的武器,只需要在数据库武器属性名字后面加后缀"@群攻"
#5.设置仙风云体步的武器,需要在数据库敌人属性名字后面加后缀"@@仙风"同样注意是两个"@"
#6.如果一件武器既是群攻又是仙风云体术,武器属性名字后面加后缀"@群攻@仙风"

#7.如果有一个状态的效果是仙风云体术,请用下面的这个变量存储该状态的ID
Xianfengstate = 37

  #--------------------------------------------------------------------------
  # ● 去后缀处理
  #--------------------------------------------------------------------------
class Window_Base < Window
  def draw_item_name(item, x, y)
    if item == nil
      return
    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.split("@")[0])
  end
end

class Game_Enemy < Game_Battler
  def name
    return $data_enemies[@enemy_id].name.split("@")[0]
  end
  def ifQungong
    ###如果要改变敌人群体攻击属性的后缀,改下面
    return $data_enemies[@enemy_id].name.split("@")[1] == "群攻"
  end
    def ifXianfeng
    ###如果要改变敌人双次攻击属性的后缀,改下面
    return $data_enemies[@enemy_id].name.split("@")[2] == "仙风"
  end
end
  #--------------------------------------------------------------------------
  # ● 重写攻击情况下的脚本
  #--------------------------------------------------------------------------

class Scene_Battle
  #--------------------------------------------------------------------------
  # ● 生成行动循序
  #--------------------------------------------------------------------------
  def make_action_orders
    # 初始化序列 @action_battlers
    @action_battlers = []
    # 添加敌人到 @action_battlers 序列
    for enemy in $game_troop.enemies
      @action_battlers.push(enemy)
      if enemy.ifXianfeng
        @action_battlers.push(enemy)
      end
    end
    # 添加角色到 @action_battlers 序列
    for actor in $game_party.actors
      @action_battlers.push(actor)
      if (actor.current_action.basic == 0 && actor.restriction == 0 && actor.weapon_id != 0 && $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")
        @action_battlers.push(actor)
      else
        if actor.state?(Xianfengstate)
          @action_battlers.push(actor)
        end
      end
    end
    # 确定全体的行动速度
    for battler in @action_battlers
      battler.make_action_speed
    end
    # 按照行动速度从大到小排列
    @action_battlers.sort! {|a,b|
      b.current_action.speed - a.current_action.speed }
  end

  #--------------------------------------------------------------------------
  # ● 生成基本行动结果
  #--------------------------------------------------------------------------

  def make_basic_action_result
    # 攻击的情况下
    if @active_battler.current_action.basic == 0
      # 设置攻击 ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # 行动方的战斗者是敌人的情况下
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)
        end
      end
      # 行动方的战斗者是角色的情况下
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          index = @active_battler.current_action.target_index
          target = $game_troop.smooth_target_enemy(index)
        end
      end
      # 设置对像方的战斗者序列
      @target_battlers = [target]
      # 如果敌人有“群攻”标记
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.ifQungong
          if @active_battler.restriction == 0
            @target_battlers = []
            for target in $game_party.actors
              if target.exist?
                @target_battlers.push(target)
              end
            end
          end
        end
      end
      # 如果角色标有群攻或者武器含有“群攻”标记
      if @active_battler.is_a?(Game_Actor)
        ###如果要改变武器群体攻击属性的后缀,改下面
        if $data_weapons[@active_battler.weapon_id].name.split("@")[1] == "群攻"
          if @active_battler.restriction == 0
            @target_battlers = []
            for target in $game_troop.enemies
              if target.exist?
                @target_battlers.push(target)
              end
            end
          end
        end
      end
      # 应用通常攻击效果
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # 防御的情况下
    if @active_battler.current_action.basic == 1
      # 帮助窗口显示"防御"
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # 逃跑的情况下
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      #  帮助窗口显示"逃跑"
      @help_window.set_text("逃跑", 1)
      # 逃跑
      @active_battler.escape
      return
    end
    # 什么也不做的情况下
    if @active_battler.current_action.basic == 3
      # 清除强制行动对像的战斗者
      $game_temp.forcing_battler = nil
      # 移至步骤 1
      @phase4_step = 1
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (主回合步骤 6 : 刷新)
  #--------------------------------------------------------------------------
  def update_phase4_step6
    # 清除强制行动对像的战斗者
    $game_temp.forcing_battler = nil
    # 公共事件 ID 有效的情况下
    if @common_event_id > 0
      # 设置事件
      common_event = $data_common_events[@common_event_id]
      $game_system.battle_interpreter.setup(common_event.list, 0)
    end
   
    ###为二次攻击者重新设置动作
    if @active_battler.is_a?(Game_Enemy)
      @active_battler.make_action
    end
   
    # 移至步骤 1
    @phase4_step = 1
  end
end[/pre]
回复

使用道具 举报

梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2014-10-16 08:56:38 | 显示全部楼层
本帖最后由 RyanBern 于 2014-10-16 13:12 编辑
yang1zhi 发表于 2014-10-15 23:06
求救。
我用了您给出的修改后。那一行没出错了。不过第139行的群攻出错了。
这个脚本说可以设状态仙风, ...


问题产出原因同上,写脚本的时候没有考虑不带武器的情况。
139行改成:
[pre lang="Ruby"]if @active_battler.weapon_id != 0 && $data_weapons[@active_battler.weapon_id].name.split("@")[1] == "群攻"[/pre]

点评

可以了,没报错了。谢谢你  发表于 2014-10-16 13:39
不好意思手抖多了个']',这回呢  发表于 2014-10-16 13:13
不行,直接打开就报错。syntaxerror  发表于 2014-10-16 12:28
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部