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

Project1

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

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

跳转到指定楼层
1
发表于 2014-10-15 12:51:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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


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



RUBY 代码复制
  1. def make_action_orders
  2.     # 初始化序列 @action_battlers
  3.     @action_battlers = []
  4.     # 添加敌人到 @action_battlers 序列
  5.     for enemy in $game_troop.enemies
  6.       @action_battlers.push(enemy)
  7.       if enemy.ifXianfeng
  8.         @action_battlers.push(enemy)
  9.       end
  10.     end
  11.     # 添加角色到 @action_battlers 序列
  12.     for actor in $game_party.actors
  13.       @action_battlers.push(actor)
  14.       if (actor.current_action.basic == 0 and actor.restriction == 0 and  $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")
  15.         @action_battlers.push(actor)
  16.       else
  17.         if actor.state?(Xianfengstate)
  18.           @action_battlers.push(actor)
  19.         end
  20.       end
  21.     end
  22.     # 确定全体的行动速度
  23.     for battler in @action_battlers
  24.       battler.make_action_speed
  25.     end
  26.     # 按照行动速度从大到小排列
  27.     @action_battlers.sort! {|a,b|
  28.       b.current_action.speed - a.current_action.speed }
  29.   end

点评

只有没装备武器攻击时会出错,在地图行走时没事。。。难道你战斗不带武器?那用这个脚本干嘛?  发表于 2014-10-15 13:17

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

2
发表于 2014-10-15 13:59:52 | 只看该作者
没有武器时,角色装备的武器ID设置为0,所以$data_weapons[0]为nil,因此调用$data_weapons[0].name会发生no method error。这也是写脚本的人没有注意到的吧。
问题产生原因分析完毕,解决方法如下。
14行改成:
RUBY 代码复制
  1. if actor.current_action.basic == 0 && actor.restriction == 0 && actor.weapon_id != 0 && $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")

if语句有些长,不过为了防止BUG只能如此。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

3
 楼主| 发表于 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为仙风状态。人物没拿武器时就出错。
经过您的修改后,仙风那一行没出错了。
这次群攻那一行出错了。
不过我是加的仙风状态。


RUBY 代码复制
  1. #==============================================================================
  2. # ■仿仙剑的群体攻击(鞭)、仙风云体步(仙女剑)以及敌人的双次攻击效果
  3. #------------------------------------------------------------------------------
  4. # 实现角色的攻击特点、武器的攻击特点、敌人的攻击特点  Ver 1.00
  5. #==============================================================================
  6.  
  7. #用前须知
  8. #首先请搞清楚,群攻是指林月如的鞭系那种攻击对方全体的普通攻击;
  9. #仙风云体步是指赵灵儿用双剑攻击的每回合对同一敌人的两次普通攻击;
  10. #在这个仿仙剑一的版本中,敌人的仙风云体步设置为双次攻击效果
  11.  
  12. #1.设置群体攻击的敌人,只需要在数据库敌人属性名字后面加后缀"@群攻"
  13. #2.设置仙风云体步的敌人,需要在数据库敌人属性名字后面加后缀"@@仙风"注意是两个"@"
  14. #3.如果一个敌人既是群攻又是仙风云体步,敌人属性名字后面加后缀"@群攻@仙风"
  15.  
  16. #4.设置群体攻击的武器,只需要在数据库武器属性名字后面加后缀"@群攻"
  17. #5.设置仙风云体步的武器,需要在数据库敌人属性名字后面加后缀"@@仙风"同样注意是两个"@"
  18. #6.如果一件武器既是群攻又是仙风云体术,武器属性名字后面加后缀"@群攻@仙风"
  19.  
  20. #7.如果有一个状态的效果是仙风云体术,请用下面的这个变量存储该状态的ID
  21. Xianfengstate = 37
  22.  
  23.   #--------------------------------------------------------------------------
  24.   # ● 去后缀处理
  25.   #--------------------------------------------------------------------------
  26. class Window_Base < Window
  27.   def draw_item_name(item, x, y)
  28.     if item == nil
  29.       return
  30.     end
  31.     bitmap = RPG::Cache.icon(item.icon_name)
  32.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  33.     self.contents.font.color = normal_color
  34.     self.contents.draw_text(x + 28, y, 212, 32, item.name.split("@")[0])
  35.   end
  36. end
  37.  
  38. class Game_Enemy < Game_Battler
  39.   def name
  40.     return $data_enemies[@enemy_id].name.split("@")[0]
  41.   end
  42.   def ifQungong
  43.     ###如果要改变敌人群体攻击属性的后缀,改下面
  44.     return $data_enemies[@enemy_id].name.split("@")[1] == "群攻"
  45.   end
  46.     def ifXianfeng
  47.     ###如果要改变敌人双次攻击属性的后缀,改下面
  48.     return $data_enemies[@enemy_id].name.split("@")[2] == "仙风"
  49.   end
  50. end
  51.   #--------------------------------------------------------------------------
  52.   # ● 重写攻击情况下的脚本
  53.   #--------------------------------------------------------------------------
  54.  
  55. class Scene_Battle
  56.   #--------------------------------------------------------------------------
  57.   # ● 生成行动循序
  58.   #--------------------------------------------------------------------------
  59.   def make_action_orders
  60.     # 初始化序列 @action_battlers
  61.     @action_battlers = []
  62.     # 添加敌人到 @action_battlers 序列
  63.     for enemy in $game_troop.enemies
  64.       @action_battlers.push(enemy)
  65.       if enemy.ifXianfeng
  66.         @action_battlers.push(enemy)
  67.       end
  68.     end
  69.     # 添加角色到 @action_battlers 序列
  70.     for actor in $game_party.actors
  71.       @action_battlers.push(actor)
  72.       if (actor.current_action.basic == 0 && actor.restriction == 0 && actor.weapon_id != 0 && $data_weapons[actor.weapon_id].name.split("@")[2] == "仙风")
  73.         @action_battlers.push(actor)
  74.       else
  75.         if actor.state?(Xianfengstate)
  76.           @action_battlers.push(actor)
  77.         end
  78.       end
  79.     end
  80.     # 确定全体的行动速度
  81.     for battler in @action_battlers
  82.       battler.make_action_speed
  83.     end
  84.     # 按照行动速度从大到小排列
  85.     @action_battlers.sort! {|a,b|
  86.       b.current_action.speed - a.current_action.speed }
  87.   end
  88.  
  89.   #--------------------------------------------------------------------------
  90.   # ● 生成基本行动结果
  91.   #--------------------------------------------------------------------------
  92.  
  93.   def make_basic_action_result
  94.     # 攻击的情况下
  95.     if @active_battler.current_action.basic == 0
  96.       # 设置攻击 ID
  97.       @animation1_id = @active_battler.animation1_id
  98.       @animation2_id = @active_battler.animation2_id
  99.       # 行动方的战斗者是敌人的情况下
  100.       if @active_battler.is_a?(Game_Enemy)
  101.         if @active_battler.restriction == 3
  102.           target = $game_troop.random_target_enemy
  103.         elsif @active_battler.restriction == 2
  104.           target = $game_party.random_target_actor
  105.         else
  106.           index = @active_battler.current_action.target_index
  107.           target = $game_party.smooth_target_actor(index)
  108.         end
  109.       end
  110.       # 行动方的战斗者是角色的情况下
  111.       if @active_battler.is_a?(Game_Actor)
  112.         if @active_battler.restriction == 3
  113.           target = $game_party.random_target_actor
  114.         elsif @active_battler.restriction == 2
  115.           target = $game_troop.random_target_enemy
  116.         else
  117.           index = @active_battler.current_action.target_index
  118.           target = $game_troop.smooth_target_enemy(index)
  119.         end
  120.       end
  121.       # 设置对像方的战斗者序列
  122.       @target_battlers = [target]
  123.       # 如果敌人有“群攻”标记
  124.       if @active_battler.is_a?(Game_Enemy)
  125.         if @active_battler.ifQungong
  126.           if @active_battler.restriction == 0
  127.             @target_battlers = []
  128.             for target in $game_party.actors
  129.               if target.exist?
  130.                 @target_battlers.push(target)
  131.               end
  132.             end
  133.           end
  134.         end
  135.       end
  136.       # 如果角色标有群攻或者武器含有“群攻”标记
  137.       if @active_battler.is_a?(Game_Actor)
  138.         ###如果要改变武器群体攻击属性的后缀,改下面
  139.         if $data_weapons[@active_battler.weapon_id].name.split("@")[1] == "群攻"
  140.           if @active_battler.restriction == 0
  141.             @target_battlers = []
  142.             for target in $game_troop.enemies
  143.               if target.exist?
  144.                 @target_battlers.push(target)
  145.               end
  146.             end
  147.           end
  148.         end
  149.       end
  150.       # 应用通常攻击效果
  151.       for target in @target_battlers
  152.         target.attack_effect(@active_battler)
  153.       end
  154.       return
  155.     end
  156.     # 防御的情况下
  157.     if @active_battler.current_action.basic == 1
  158.       # 帮助窗口显示"防御"
  159.       @help_window.set_text($data_system.words.guard, 1)
  160.       return
  161.     end
  162.     # 逃跑的情况下
  163.     if @active_battler.is_a?(Game_Enemy) and
  164.        @active_battler.current_action.basic == 2
  165.       #  帮助窗口显示"逃跑"
  166.       @help_window.set_text("逃跑", 1)
  167.       # 逃跑
  168.       @active_battler.escape
  169.       return
  170.     end
  171.     # 什么也不做的情况下
  172.     if @active_battler.current_action.basic == 3
  173.       # 清除强制行动对像的战斗者
  174.       $game_temp.forcing_battler = nil
  175.       # 移至步骤 1
  176.       @phase4_step = 1
  177.       return
  178.     end
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # ● 刷新画面 (主回合步骤 6 : 刷新)
  182.   #--------------------------------------------------------------------------
  183.   def update_phase4_step6
  184.     # 清除强制行动对像的战斗者
  185.     $game_temp.forcing_battler = nil
  186.     # 公共事件 ID 有效的情况下
  187.     if @common_event_id > 0
  188.       # 设置事件
  189.       common_event = $data_common_events[@common_event_id]
  190.       $game_system.battle_interpreter.setup(common_event.list, 0)
  191.     end
  192.  
  193.     ###为二次攻击者重新设置动作
  194.     if @active_battler.is_a?(Game_Enemy)
  195.       @active_battler.make_action
  196.     end
  197.  
  198.     # 移至步骤 1
  199.     @phase4_step = 1
  200.   end
  201. end
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

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


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

点评

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-22 01:26

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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