查看: 3828|回复: 16

[已经解决] 逃跑加入战斗菜单的脚本有BUG,请教

[复制链接]
梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
发表于 2016-6-26 20:47:17 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 452234679 于 2016-6-26 20:54 编辑

脚本功能:去掉战斗开始时候的 战斗/逃跑 的选择过程,并把逃跑加入到角色命令菜单当中

如果使用事件——战斗处理,不选择“可以逃跑”,则一开始战斗就会脚本报错

报错的代码是这部分

    unless $game_temp.battle_can_escape
      @actor_command_window.disable_item(commands.size - 1)
    end

我想可能是因为无法判断逃跑按钮的状态,我希望可以进入战斗后,逃跑按钮是失效状态的

希望可以得到大神的指导,谢谢!

该脚本的全部代码如下:

  1. #=======================================================================
  2. # ■ 本脚本来自 [url]www.66rpg.com[/url] 转载和使用时请保留此信息
  3. #-----------------------------------------------------------------------
  4. #   脚本功能:去掉战斗开始时候的 战斗/逃跑 的选择过程.
  5. #             并把逃跑加入到角色命令菜单当中
  6. #   脚本作者:后知后觉  2010-8-11 13:46:59
  7. #   使用方法:直接在 Main 前插入即可
  8. #=======================================================================
  9. class Window_PartyCommand < Window_Selectable
  10.   def visible=(value)
  11.     super(false)
  12.   end
  13.   def active=(value)
  14.     super(false)
  15.   end
  16. end
  17. class Scene_Battle
  18.   alias hzhj_old_start_phase1 start_phase1
  19.   def start_phase1
  20.     class << @actor_command_window
  21.       attr_reader :commands
  22.       def commands=(value)
  23.         @commands = value
  24.         @item_max = @commands.size
  25.         self.height = @item_max * 32 + 32
  26.         self.y = [self.y - 32, 0].max
  27.         self.contents.dispose
  28.         self.contents = Bitmap.new(width - 32, height - 32)
  29.         refresh
  30.       end
  31.     end

  32.     unless $game_temp.battle_can_escape
  33.       @actor_command_window.disable_item(commands.size - 1)
  34.     end
  35.     hzhj_old_start_phase1
  36.   end
  37.   alias hzhj_old_start_phase2 start_phase2
  38.   def start_phase2
  39.     hzhj_old_start_phase2
  40.     if @phase == 2
  41.       start_phase3
  42.     end
  43.   end
  44.   alias hzhj_old_update_phase3_basic_command update_phase3_basic_command
  45.   def update_phase3_basic_command
  46.     hzhj_old_update_phase3_basic_command
  47.     if Input.trigger?(13)
  48.       if @actor_command_window.index == @actor_command_window.commands.size - 1
  49.         unless $game_temp.battle_can_escape
  50.           $game_system.se_play($data_system.buzzer_se)
  51.           return
  52.         end
  53.         $game_system.se_play($data_system.decision_se)
  54.         update_phase2_escape
  55.         return
  56.       end
  57.     end
  58.   end
  59. end

  60. #=======================================================================
  61. # ■ 本脚本来自 [url]www.66rpg.com[/url] 转载和使用时请保留此信息
  62. #=======================================================================
复制代码
梦石
0
星屑
50
在线时间
76 小时
注册时间
2016-2-12
回帖
14
发表于 2016-6-26 21:32:29 | 显示全部楼层
在unless 前面加上这三行
  1. commands = @actor_command_window.commands
  2.     commands.push("撤退")
  3.     @actor_command_window.commands = commands
复制代码
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-6-26 21:50:27 | 显示全部楼层
阿短 发表于 2016-6-26 21:32
在unless 前面加上这三行

还是会报错:undefined method 'disable_item' for
回复

使用道具 举报

梦石
0
星屑
4657
在线时间
1069 小时
注册时间
2013-3-28
回帖
309

开拓者

发表于 2016-7-8 18:57:21 | 显示全部楼层
452234679 发表于 2016-6-26 21:50
还是会报错:undefined method 'disable_item' for

for 后面是什么?这个很重要
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-7-12 23:24:30 | 显示全部楼层
陈大帅帅帅哥 发表于 2016-7-8 18:57
for 后面是什么?这个很重要

undefined method 'disable_item' for #<Scene_Battle 0x22a0260>
回复

使用道具 举报

梦石
0
星屑
4657
在线时间
1069 小时
注册时间
2013-3-28
回帖
309

开拓者

发表于 2016-7-13 10:47:37 | 显示全部楼层
452234679 发表于 2016-7-12 23:24
undefined method 'disable_item' for #


我尝试了下没有问题,有可能是你其他的脚本把这个脚本的某个方法覆盖了,能不能发一下你的整个工程
不方便的话可以私信
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-7-13 16:24:57 | 显示全部楼层
陈大帅帅帅哥 发表于 2016-7-13 10:47
我尝试了下没有问题,有可能是你其他的脚本把这个脚本的某个方法覆盖了,能不能发一下你的整个工程
不方 ...

您好,我仔细看了下,确实我的工程还修改了一个地方,我将战斗命令的排列方式改成横排了,所以冲突

但是,但是工程传不上来,文件太大了,可否告知您的联系方式

我先将涉及到的3个脚本发到这里,您新建一个工程加入这3个脚本就可以发现BUG了:


第1个改动的地方(默认脚本,替换的):

  1. #==============================================================================
  2. # ■ Scene_Battle (分割定义 1)
  3. #------------------------------------------------------------------------------
  4. #  处理战斗画面的类。
  5. #==============================================================================

  6. class Scene_Battle
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     # 初始化战斗用的各种暂时数据
  12.     $game_temp.in_battle = true
  13.     $game_temp.battle_turn = 0
  14.     $game_temp.battle_event_flags.clear
  15.     $game_temp.battle_abort = false
  16.     $game_temp.battle_main_phase = false
  17.     $game_temp.battleback_name = $game_map.battleback_name
  18.     $game_temp.forcing_battler = nil
  19.     # 初始化战斗用事件解释器
  20.     $game_system.battle_interpreter.setup(nil, 0)
  21.     # 准备队伍
  22.     @troop_id = $game_temp.battle_troop_id
  23.     $game_troop.setup(@troop_id)
  24.     # 生成角色命令窗口
  25.     @actor_command_window = Window_BattleCommand.new
  26.     @actor_command_window.y = 160
  27.     @actor_command_window.back_opacity = 160
  28.     @actor_command_window.active = false
  29.     @actor_command_window.visible = false
  30.     # 生成其它窗口
  31.     @party_command_window = Window_PartyCommand.new
  32.     @help_window = Window_Help.new
  33.     @help_window.back_opacity = 160
  34.     @help_window.visible = false
  35.     @status_window = Window_BattleStatus.new
  36.     @message_window = Window_Message.new
  37.     # 生成活动块
  38.     @spriteset = Spriteset_Battle.new
  39.     # 初始化等待计数
  40.     @wait_count = 0
  41.     # 执行过渡
  42.     if $data_system.battle_transition == ""
  43.       Graphics.transition(20)
  44.     else
  45.       Graphics.transition(40, "Graphics/Transitions/" +
  46.         $data_system.battle_transition)
  47.     end
  48.     # 开始自由战斗回合
  49.     start_phase1
  50.     # 主循环
  51.     loop do
  52.       # 刷新游戏画面
  53.       Graphics.update
  54.       # 刷新输入信息
  55.       Input.update
  56.       # 刷新画面
  57.       update
  58.       # 如果画面切换的话就中断循环
  59.       if $scene != self
  60.         break
  61.       end
  62.     end
  63.     # 刷新地图
  64.     $game_map.refresh
  65.     # 准备过渡
  66.     Graphics.freeze
  67.     # 释放窗口
  68.     @actor_command_window.dispose
  69.     @party_command_window.dispose
  70.     @help_window.dispose
  71.     @status_window.dispose
  72.     @message_window.dispose
  73.     if @skill_window != nil
  74.       @skill_window.dispose
  75.     end
  76.     if @item_window != nil
  77.       @item_window.dispose
  78.     end
  79.     if @result_window != nil
  80.       @result_window.dispose
  81.     end
  82.     # 释放活动块
  83.     @spriteset.dispose
  84.     # 标题画面切换中的情况
  85.     if $scene.is_a?(Scene_Title)
  86.       # 淡入淡出画面
  87.       Graphics.transition
  88.       Graphics.freeze
  89.     end
  90.     # 战斗测试或者游戏结束以外的画面切换中的情况
  91.     if $BTEST and not $scene.is_a?(Scene_Gameover)
  92.       $scene = nil
  93.     end
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ● 胜负判定
  97.   #--------------------------------------------------------------------------
  98.   def judge
  99.     # 全灭判定是真、并且同伴人数为 0 的情况下
  100.     if $game_party.all_dead? or $game_party.actors.size == 0
  101.       # 允许失败的情况下
  102.       if $game_temp.battle_can_lose
  103.         # 还原为战斗开始前的 BGM
  104.         $game_system.bgm_play($game_temp.map_bgm)
  105.         # 战斗结束
  106.         battle_end(2)
  107.         # 返回 true
  108.         return true
  109.       end
  110.       # 设置游戏结束标志
  111.       $game_temp.gameover = true
  112.       # 返回 true
  113.       return true
  114.     end
  115.     # 如果存在任意 1 个敌人就返回 false
  116.     for enemy in $game_troop.enemies
  117.       if enemy.exist?
  118.         return false
  119.       end
  120.     end
  121.     # 开始结束战斗回合 (胜利)
  122.     start_phase5
  123.     # 返回 true
  124.     return true
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● 战斗结束
  128.   #     result : 結果 (0:胜利 1:失败 2:逃跑)
  129.   #--------------------------------------------------------------------------
  130.   def battle_end(result)
  131.     # 清除战斗中标志
  132.     $game_temp.in_battle = false
  133.     # 清除全体同伴的行动
  134.     $game_party.clear_actions
  135.     # 解除战斗用状态
  136.     for actor in $game_party.actors
  137.       actor.remove_states_battle
  138.     end
  139.     # 清除敌人
  140.     $game_troop.enemies.clear
  141.     # 调用战斗返回调用
  142.     if $game_temp.battle_proc != nil
  143.       $game_temp.battle_proc.call(result)
  144.       $game_temp.battle_proc = nil
  145.     end
  146.     # 切换到地图画面
  147.     $scene = Scene_Map.new
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● 设置战斗事件
  151.   #--------------------------------------------------------------------------
  152.   def setup_battle_event
  153.     # 正在执行战斗事件的情况下
  154.     if $game_system.battle_interpreter.running?
  155.       return
  156.     end
  157.     # 搜索全部页的战斗事件
  158.     for index in 0...$data_troops[@troop_id].pages.size
  159.       # 获取事件页
  160.       page = $data_troops[@troop_id].pages[index]
  161.       # 事件条件可以参考 c
  162.       c = page.condition
  163.       # 没有指定任何条件的情况下转到下一页
  164.       unless c.turn_valid or c.enemy_valid or
  165.              c.actor_valid or c.switch_valid
  166.         next
  167.       end
  168.       # 执行完毕的情况下转到下一页
  169.       if $game_temp.battle_event_flags[index]
  170.         next
  171.       end
  172.       # 确认回合条件
  173.       if c.turn_valid
  174.         n = $game_temp.battle_turn
  175.         a = c.turn_a
  176.         b = c.turn_b
  177.         if (b == 0 and n != a) or
  178.            (b > 0 and (n < 1 or n < a or n % b != a % b))
  179.           next
  180.         end
  181.       end
  182.       # 确认敌人条件
  183.       if c.enemy_valid
  184.         enemy = $game_troop.enemies[c.enemy_index]
  185.         if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
  186.           next
  187.         end
  188.       end
  189.       # 确认角色条件
  190.       if c.actor_valid
  191.         actor = $game_actors[c.actor_id]
  192.         if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp
  193.           next
  194.         end
  195.       end
  196.       # 确认开关条件
  197.       if c.switch_valid
  198.         if $game_switches[c.switch_id] == false
  199.           next
  200.         end
  201.       end
  202.       # 设置事件
  203.       $game_system.battle_interpreter.setup(page.list, 0)
  204.       # 本页的范围是 [战斗] 或 [回合] 的情况下
  205.       if page.span <= 1
  206.         # 设置执行结束标志
  207.         $game_temp.battle_event_flags[index] = true
  208.       end
  209.       return
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● 刷新画面
  214.   #--------------------------------------------------------------------------
  215.   def update
  216.     # 执行战斗事件中的情况下
  217.     if $game_system.battle_interpreter.running?
  218.       # 刷新解释器
  219.       $game_system.battle_interpreter.update
  220.       # 强制行动的战斗者不存在的情况下
  221.       if $game_temp.forcing_battler == nil
  222.         # 执行战斗事件结束的情况下
  223.         unless $game_system.battle_interpreter.running?
  224.           # 继续战斗的情况下、再执行战斗事件的设置
  225.           unless judge
  226.             setup_battle_event
  227.           end
  228.         end
  229.         # 如果不是结束战斗回合的情况下
  230.         if @phase != 5
  231.           # 刷新状态窗口
  232.           @status_window.refresh
  233.         end
  234.       end
  235.     end
  236.     # 系统 (计时器)、刷新画面
  237.     $game_system.update
  238.     $game_screen.update
  239.     # 计时器为 0 的情况下
  240.     if $game_system.timer_working and $game_system.timer == 0
  241.       # 中断战斗
  242.       $game_temp.battle_abort = true
  243.     end
  244.     # 刷新窗口
  245.     @help_window.update
  246.     @party_command_window.update
  247.     @actor_command_window.update
  248.     @status_window.update
  249.     @message_window.update
  250.     # 刷新活动块
  251.     @spriteset.update
  252.     # 处理过渡中的情况下
  253.     if $game_temp.transition_processing
  254.       # 清除处理过渡中标志
  255.       $game_temp.transition_processing = false
  256.       # 执行过渡
  257.       if $game_temp.transition_name == ""
  258.         Graphics.transition(20)
  259.       else
  260.         Graphics.transition(40, "Graphics/Transitions/" +
  261.           $game_temp.transition_name)
  262.       end
  263.     end
  264.     # 显示信息窗口中的情况下
  265.     if $game_temp.message_window_showing
  266.       return
  267.     end
  268.     # 显示效果中的情况下
  269.     if @spriteset.effect?
  270.       return
  271.     end
  272.     # 游戏结束的情况下
  273.     if $game_temp.gameover
  274.       # 切换到游戏结束画面
  275.       $scene = Scene_Gameover.new
  276.       return
  277.     end
  278.     # 返回标题画面的情况下
  279.     if $game_temp.to_title
  280.       # 切换到标题画面
  281.       $scene = Scene_Title.new
  282.       return
  283.     end
  284.     # 中断战斗的情况下
  285.     if $game_temp.battle_abort
  286.       # 还原为战斗前的 BGM
  287.       $game_system.bgm_play($game_temp.map_bgm)
  288.       # 战斗结束
  289.       battle_end(1)
  290.       return
  291.     end
  292.     # 等待中的情况下
  293.     if @wait_count > 0
  294.       # 减少等待计数
  295.       @wait_count -= 1
  296.       return
  297.     end
  298.     # 强制行动的角色存在、
  299.     # 并且战斗事件正在执行的情况下
  300.     if $game_temp.forcing_battler == nil and
  301.        $game_system.battle_interpreter.running?
  302.       return
  303.     end
  304.     # 回合分支
  305.     case @phase
  306.     when 1  # 自由战斗回合
  307.       update_phase1
  308.     when 2  # 同伴命令回合
  309.       update_phase2
  310.     when 3  # 角色命令回合
  311.       update_phase3
  312.     when 4  # 主回合
  313.       update_phase4
  314.     when 5  # 战斗结束回合
  315.       update_phase5
  316.     end
  317.   end
  318. end
复制代码


第2个改动的地方(自定义脚本):
  1. #==============================================================================

  2. class Window_BattleCommand < Window_Selectable
  3.   #--------------------------------------------------------------------------
  4.   def initialize
  5.     super(0, 0, 180, 60)
  6.     self.contents = Bitmap.new(width - 32, height - 32)
  7.     self.back_opacity = 160
  8.     @commands = ["攻","技","防","物","逃"]
  9.     @item_max = 5
  10.     @column_max = 5
  11.     refresh
  12.     self.active = false
  13.     self.visible = false
  14.     self.index = 0
  15.   end
  16.   #---------------------------------------------------------------------------
  17.   def refresh
  18.     self.contents.clear
  19.     for i in 0...@item_max
  20.       draw_item(i)
  21.     end
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   def draw_item(index)
  25.     x = index % 5 * 30
  26.     y = index / 5 * 30
  27.     self.contents.font.color = normal_color
  28.     self.contents.draw_text(x, y, 30, 30, @commands[index], 1)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   def update_cursor_rect
  32.     x = index % 5 * 30
  33.     y = index / 5 * 30
  34.     self.cursor_rect.set(x, y, 30, 30)
  35.   end
  36. end
  37. #===============================================================================
复制代码



第3个改动的地方(自定义脚本,逃跑脚本):
  1. #=======================================================================
  2. # ■ 本脚本来自 [url]www.66rpg.com[/url] 转载和使用时请保留此信息
  3. #-----------------------------------------------------------------------
  4. #   脚本功能:去掉战斗开始时候的 战斗/逃跑 的选择过程.
  5. #             并把逃跑加入到角色命令菜单当中
  6. #   脚本作者:后知后觉  2010-8-11 13:46:59
  7. #   使用方法:直接在 Main 前插入即可
  8. #=======================================================================
  9. class Window_PartyCommand < Window_Selectable
  10.   def visible=(value)
  11.     super(false)
  12.   end
  13.   def active=(value)
  14.     super(false)
  15.   end
  16. end
  17. class Scene_Battle
  18.   alias hzhj_old_start_phase1 start_phase1
  19.   def start_phase1
  20.     class << @actor_command_window
  21.       attr_reader :commands
  22.       def commands=(value)
  23.         @commands = value
  24.         @item_max = @commands.size
  25.         self.height = @item_max * 32 + 32
  26.         self.y = [self.y - 32, 0].max
  27.         self.contents.dispose
  28.         self.contents = Bitmap.new(width - 32, height - 32)
  29.         refresh
  30.       end
  31.     end
  32.     commands = @actor_command_window.commands
  33.     commands.push("撤退")
  34.     @actor_command_window.commands = commands
  35.     unless $game_temp.battle_can_escape
  36.       @actor_command_window.disable_item(commands.size - 1)
  37.     end
  38.     hzhj_old_start_phase1
  39.   end
  40.   alias hzhj_old_start_phase2 start_phase2
  41.   def start_phase2
  42.     hzhj_old_start_phase2
  43.     if @phase == 2
  44.       start_phase3
  45.     end
  46.   end
  47.   alias hzhj_old_update_phase3_basic_command update_phase3_basic_command
  48.   def update_phase3_basic_command
  49.     hzhj_old_update_phase3_basic_command
  50.     if Input.trigger?(13)
  51.       if @actor_command_window.index == @actor_command_window.commands.size - 1
  52.         unless $game_temp.battle_can_escape
  53.           $game_system.se_play($data_system.buzzer_se)
  54.           return
  55.         end
  56.         $game_system.se_play($data_system.decision_se)
  57.         update_phase2_escape
  58.         return
  59.       end
  60.     end
  61.   end
  62. end

  63. #=======================================================================
  64. # ■ 本脚本来自 [url]www.66rpg.com[/url] 转载和使用时请保留此信息
  65. #=======================================================================
复制代码
回复

使用道具 举报

梦石
0
星屑
4657
在线时间
1069 小时
注册时间
2013-3-28
回帖
309

开拓者

发表于 2016-7-13 17:52:17 | 显示全部楼层
452234679 发表于 2016-7-13 16:24
您好,我仔细看了下,确实我的工程还修改了一个地方,我将战斗命令的排列方式改成横排了,所以冲突

但是 ...


还是没有问题,可不可以把Data文件夹里的Scripts.rxdata文件发给我
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-7-15 00:05:50 | 显示全部楼层
陈大帅帅帅哥 发表于 2016-7-13 17:52
还是没有问题,可不可以把Data文件夹里的Scripts.rxdata文件发给我

您好,这是Scripts.rxdata,非常感谢您愿意帮我。

Scripts.rar

119.66 KB, 下载次数: 46

回复

使用道具 举报

梦石
0
星屑
4657
在线时间
1069 小时
注册时间
2013-3-28
回帖
309

开拓者

发表于 2016-7-15 11:19:49 | 显示全部楼层
本帖最后由 陈大帅帅帅哥 于 2016-7-15 11:20 编辑

在*Plugin_BattleCommand的末尾(end之前)添加
  1. #--------------------------------------------------------------------------
  2.   # ● 项目无效化
  3.   #     index : 项目编号
  4.   #--------------------------------------------------------------------------
  5.   def disable_item(index)
  6.     draw_item(index)
  7.   end
复制代码
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部