Project1

标题: 【120929】凌的容错脚本v3[三版兼容+事件中脚本容错] [打印本页]

作者: 凌童鞋    时间: 2012-9-27 23:29
标题: 【120929】凌的容错脚本v3[三版兼容+事件中脚本容错]
本帖最后由 凌童鞋 于 2012-9-30 14:19 编辑

通用版本
  1. #==============================================================================
  2. # ■ 凌的容错脚本 v3 [120929]
  3. #------------------------------------------------------------------------------
  4. #  解决游戏因发布时缺少文件等错误而使游戏无法正常进行的问题。
  5. #   附赠功能:创建多层文件夹
  6. #==============================================================================
  7. #  [120927]:基础版,支持Bitmap及Audio容错
  8. #  [120928]:修正IOError问题,感谢orzFly和雷达喵
  9. #  [120928]:支持Graphics.transition容错及save_data自动创建目录
  10. #             修正部分BUG,感谢霜月冬音
  11. #==============================================================================
  12. File.open("errors.txt","w+"){|io|}
  13. class Dir
  14.    class << self
  15.      alias :lynn_mkdir :mkdir unless $@
  16.    end
  17.    def self.mkdir(path, mode = 0777)
  18.      last_dir = ""
  19.      path.gsub(/\w*\//) {|m|
  20.        m.gsub(/\/|\\/){}
  21.        if last_dir != ""
  22.          last_dir = "#{last_dir}/#{m}"
  23.        else
  24.          last_dir = "#{m}"
  25.        end
  26.        if !FileTest.exist?(m) && !FileTest.directory?(m)
  27.          self.lynn_mkdir(last_dir)
  28.        end
  29.      }
  30.    end
  31. end
  32. module Kernel
  33.    def write_errors(argu)
  34.      open("errors.txt","a+"){|io| io.write(argu+"\n")if !io.read.to_s.include?(argu)}
  35.    end
  36.    def save_data(obj, filename)
  37.      Dir.mkdir(filename) unless FileTest.exist?(filename)
  38.      File.open(filename, "wb") { |io|
  39.        Marshal.dump(obj, io)
  40.      }
  41.    end
  42. end
  43. class Bitmap
  44.    alias :lynn_initialize :initialize unless $@
  45.    def initialize(* argu)
  46.      begin
  47.        lynn_initialize(* argu)
  48.      rescue Errno::ENOENT
  49.        lynn_initialize(1,1)
  50.        write_errors "Error:File not found on Bitmap.new\n#{argu[0]}"
  51.      end
  52.    end
  53. end
  54. module Audio
  55.    class << self
  56.      alias_method :lynn_bgm_play, :bgm_play unless $@
  57.      alias_method :lynn_bgs_play, :bgs_play unless $@
  58.      alias_method :lynn_me_play, :me_play unless $@
  59.      alias_method :lynn_se_play, :se_play unless $@
  60.    end
  61.    def self.bgm_play(* argu)
  62.      begin
  63.        self.lynn_bgm_play(* argu)
  64.      rescue Errno::ENOENT
  65.        write_errors "Error:File not found on Audio.bgm_play\n#{argu[0]}"
  66.      end
  67.    end
  68.    def self.bgs_play(* argu)
  69.      begin
  70.        self.lynn_bgs_play(* argu)
  71.      rescue Errno::ENOENT
  72.        write_errors "Error:File not found on Audio.bgs_play\n#{argu[0]}"
  73.      end
  74.    end
  75.    def self.me_play(* argu)
  76.      begin
  77.        self.lynn_me_play(* argu)
  78.      rescue Errno::ENOENT
  79.        write_errors "Error:File not found on Audio.me_play\n#{argu[0]}"
  80.      end
  81.    end
  82.    def self.se_play(* argu)
  83.      begin
  84.        self.lynn_se_play(* argu)
  85.      rescue Errno::ENOENT
  86.        write_errors "Error:File not found on Audio.se_play\n#{argu[0]}"
  87.      end
  88.    end
  89. end
  90. module Graphics
  91.    class << self
  92.      alias_method :lynn_transition, :transition unless $@
  93.    end
  94.    def self.transition(duration = 8, filename = "", vague = 40)
  95.      if filename != ""
  96.        if !FileTest.exist?(filename)
  97.          write_errors "Error:File not found on Graphics.transition\n#{filename}"
  98.          filename = ""
  99.        end
  100.      end
  101.      self.lynn_transition(duration,filename,vague)
  102.    end
  103. end
复制代码
附加包
  1. #==============================================================================
  2. # ■ 凌的容错脚本 v3 附加包 [120929] [RMVA版本]
  3. #------------------------------------------------------------------------------
  4. #  解决游戏因发布时缺少文件等错误而使游戏无法正常进行的问题。
  5. #==============================================================================
  6. #  [120929]:支援在事件中执行脚本的容错功能,同时输出所在地图与事件ID
  7. #==============================================================================
  8. #  * 注意本脚本只能用于标准事件解释器结构的工程
  9. #==============================================================================
  10. class Game_Interpreter
  11.    #--------------------------------------------------------------------------
  12.    # ● 脚本
  13.    #--------------------------------------------------------------------------
  14.    def command_355
  15.      script = @list[@index].parameters[0] + "\n"
  16.      while next_event_code == 655
  17.        @index += 1
  18.        script += @list[@index].parameters[0] + "\n"
  19.      end
  20.      begin
  21.        eval(script)
  22.      rescue
  23.        write_errors "Error on eval script\nMapID:#{@map_id}\nEventID:#{@event_id}"
  24.        write_errors "Script:\n#{script}ErrorMessage:\n#{$!.message}"
  25.        return
  26.      end
  27.    end
  28. end
复制代码
  1. #==============================================================================
  2. # ■ 凌的容错脚本 v3 附加包 [120929] [RMVX版本]
  3. #------------------------------------------------------------------------------
  4. #  解决游戏因发布时缺少文件等错误而使游戏无法正常进行的问题。
  5. #==============================================================================
  6. #  [120929]:支援在事件中执行脚本的容错功能,同时输出所在地图与事件ID
  7. #==============================================================================
  8. #  * 注意本脚本只能用于标准事件解释器结构的工程
  9. #==============================================================================
  10. class Game_Interpreter
  11.    #--------------------------------------------------------------------------
  12.    # ● 脚本
  13.    #--------------------------------------------------------------------------
  14.    def command_355
  15.      script = @list[@index].parameters[0] + "\n"
  16.      loop do
  17.        if @list[@index+1].code == 655        # 下一个事件指令在脚本2行以上的情况下
  18.          script += @list[@index+1].parameters[0] + "\n"
  19.        else
  20.          break
  21.        end
  22.        @index += 1
  23.      end
  24.      begin
  25.        eval(script)
  26.      rescue
  27.        write_errors "Error on eval script\nMapID:#{@map_id}\nEventID:#{@event_id}"
  28.        write_errors "Script:\n#{script}ErrorMessage:\n#{$!.message}"
  29.        return
  30.      end
  31.      return true
  32.    end
  33. end
复制代码
  1. #==============================================================================
  2. # ■ 凌的容错脚本 v3 附加包 [120929] [RMXP版本]
  3. #------------------------------------------------------------------------------
  4. #  解决游戏因发布时缺少文件等错误而使游戏无法正常进行的问题。
  5. #==============================================================================
  6. #  [120929]:支援在事件中执行脚本的容错功能,同时输出所在地图与事件ID
  7. #==============================================================================
  8. #  * 注意本脚本只能用于标准事件解释器结构的工程
  9. #==============================================================================
  10. class Interpreter
  11.    #--------------------------------------------------------------------------
  12.    # ● 脚本
  13.    #--------------------------------------------------------------------------
  14.    def command_355
  15.      # script 设置第一行
  16.      script = @list[@index].parameters[0] + "\n"
  17.      # 循环
  18.      loop do
  19.        # 下一个事件指令在脚本 2 行以上的情况下
  20.        if @list[@index+1].code == 655
  21.          # 添加到 script 2 行以后
  22.          script += @list[@index+1].parameters[0] + "\n"
  23.        # 事件指令不在脚本 2 行以上的情况下
  24.        else
  25.          # 中断循环
  26.          break
  27.        end
  28.        # 推进索引
  29.        @index += 1
  30.      end
  31.      # 评价
  32.      result = eval(script)
  33.      # 返回值为 false 的情况下
  34.      if result == false
  35.        # 结束
  36.        return false
  37.      end
  38.      # 继续
  39.      return true
  40.    end
  41. end
复制代码

作者: Luciffer    时间: 2012-9-27 23:32
嗯,好东西,塞个糖~
作者: 越前リョーマ    时间: 2012-9-30 11:19
还支持输出已经开挂了囧,话说VA容错终于呼之欲出了啊
作者: Luciffer    时间: 2012-10-3 14:17
正好拿来在草莓塔(大雾)里测试一下。。。
作者: 和风一人    时间: 2012-11-24 11:04
好东西谢谢楼主。
作者: tim315121    时间: 2013-3-4 17:59
挖出来问一下

VA要如何让他略过错误却不输出ERRORS.TXT出来?
作者: 凌童鞋    时间: 2013-3-6 06:11
标题: RE: 【120929】凌的容错脚本v3
tim315121 发表于 2013-3-4 17:59
挖出来问一下

VA要如何让他略过错误却不输出ERRORS.TXT出来?

把12行和34行注释掉
作者: 命真苦    时间: 2013-5-19 09:00
顶一个!继续努力哦!
作者: mileo    时间: 2014-5-11 13:40
感谢凌童鞋写的容错脚本
先前游戏报错,因为用了这个脚本而解决问题~~

因为还用了http://cacaosoft.webcrow.jp/script/rgss3/ 的 图像保存和スクリーンショット 功能

只是一按Print Screen就显示不能保存图片

请问这个该怎么解决呢? THX




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