查看: 3337|回复: 14

[已经过期] 写入存档的问题

[复制链接]
梦石
0
星屑
606
在线时间
797 小时
注册时间
2014-7-1
回帖
501

开拓者

发表于 2016-9-24 16:39:26 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 jiushiainilip19 于 2016-9-24 17:49 编辑

    save_data($data_weapons, "Data/Weapons.rxdata")
    save_data($data_armors, "Data/Armors.rxdata")
    save_data($data_classes, "Data/Classes.rxdata")
    save_data($data_skills, "Data/Skills.rxdata")
    save_data($data_states, "Data/States.rxdata")

用这些命令写入存档  游戏中强化等等都可以永久保存

但是只要一打开游戏的数据库就会还原,怎么回事?有什么办法解决吗?


如果仿造
    $data_weapons        = Marshal.load(file)
类来写入存档的话 就会固定死数据库原来的设定  
比如数据中 武器名字叫 A   你写入上面存档后就永远是A 无论你怎么在数据库更改都不行
只有在游戏中用事件命令去更改!好不科学啊!

其实我就是想通过一些简单事件命令来强化一些需求的东西

比如技能 防具 武器 的属性等等 $data_skills[@skill_id].str_f  等等之类的

可问题是更本没用 重启游戏就消失了  强行写入存档又会固定死数据库的设定 想改都改不了

下面我是这样来做技能升级脚本的
脚本一

  1. $C力= [54,60,61,62,66,69,71,100,104,108,109,112,115,118,124]

  2. $C元= [55,56,57,58,63,65,68,70,75,76,101,102,103,106,107,110,114,116,121,123,
  3.        125,126]

  4. $C速= [74,78,120,128]

  5. $C综= [54,64,72,73,77,111,117,119,122,127]

  6. $C奶= [59,67,105,113]


  7. $S神力 = [950,954,959,960,961,964,967,970,973,978,
  8.           900,904,908,909,912,915,918,924,927]

  9. $S神元 = [951,952,953,957,958,962,966,968,975,977,979,
  10.           901,902,903,906,907,910,914,916,921,923,925]

  11. $S神速 = [974,982,920,928]


  12. $S神综 = [963,969,971,976,980,981,911,917,919,922,926]


  13. $S神奶 = [956,965,972,905,913]


  14. module RPG
  15.   class Skill  
  16.    
  17.     def dex_f
  18.       n = @dex_f
  19.       
  20.     $C元.each do |a|
  21.       if @id == a
  22.         n+=@power * 5
  23.       end;end
  24.       
  25.     $C奶.each do |a|
  26.       if @id == a
  27.         n+=@power * 2
  28.       end;end
  29.       
  30.     $C综.each do |a|
  31.       if @id == a
  32.         n+=@power * 2
  33.       end;end
  34.       
  35.     $S神元.each do |a|
  36.       if @id == a
  37.         n+=@power * 20
  38.       end;end
  39.       
  40.     $S神综.each do |a|
  41.       if @id == a
  42.         n+=@power * 10
  43.       end;end
  44.       
  45.        return n
  46.     end
  47.    
  48.    
  49.     def str_f
  50.       n = @str_f
  51.       
  52.     $C力.each do |a|
  53.       if @id == a
  54.         n+=@power * 5
  55.       end;end
  56.       
  57.     $C综.each do |a|
  58.       if @id == a
  59.         n+=@power * 2
  60.       end;end
  61.       
  62.     $S神力.each do |a|
  63.       if @id == a
  64.         n+=@power * 20
  65.       end;end
  66.       
  67.     $S神综.each do |a|
  68.       if @id == a
  69.         n+=@power * 10
  70.       end;end
  71.       
  72.        return n
  73.     end
  74.    
  75.    
  76.    
  77.     def agi_f
  78.       n = @agi_f
  79.       
  80.     $C速.each do |a|
  81.       if @id == a
  82.         n+=@power * 5
  83.       end;end
  84.       
  85.     $C综.each do |a|
  86.       if @id == a
  87.         n+=@power * 2
  88.       end;end
  89.       
  90.     $S神速.each do |a|
  91.       if @id == a
  92.         n+=@power * 20
  93.       end;end
  94.       
  95.     $S神综.each do |a|
  96.       if @id == a
  97.         n+=@power * 10
  98.       end;end
  99.       
  100.        return n
  101.     end
  102.    
  103.    
  104.    
  105.    
  106.    
  107.    
  108.     def name
  109.       n = @name
  110.       case @id
  111.        when 54..78
  112.         if @power>=10
  113.             n = @name+"Lv:"+"Max"
  114.           else
  115.             n = @name+"Lv:"+@power.to_s
  116.           end
  117.        when 100..128
  118.         if @power>=15
  119.             n = @name+"Lv:"+"Max"
  120.           else
  121.             n = @name+"Lv:"+@power.to_s
  122.           end
  123.        when 950..982 #神
  124.         if @power>=4
  125.             n = @name+"Lv:"+"Max"
  126.           else
  127.             n = @name+"Lv:"+@power.to_s
  128.           end
  129.        when 900..928 #圣
  130.         if @power>=6
  131.             n = @name+"Lv:"+"Max"
  132.           else
  133.             n = @name+"Lv:"+@power.to_s
  134.           end
  135.          
  136.         end   
  137.        return n
  138.     end
  139.    
  140.   end
  141. end
复制代码


脚本二

  1. class Window_C_Level < Window_Selectable
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化对像
  4.   #     actor : 角色
  5.   #--------------------------------------------------------------------------
  6.   def initialize(actor)
  7.     super(300, 100, 260, 250)
  8.     @actor = actor
  9.     @column_max = 1
  10.     refresh
  11.     self.index = 0
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● 获取特技
  15.   #--------------------------------------------------------------------------
  16.   def skill
  17.     return @data[self.index]
  18.   end
  19.   #--------------------------------------------------------------------------
  20.   # ● 刷新
  21.   #--------------------------------------------------------------------------
  22.   def refresh
  23.     if self.contents != nil
  24.       self.contents.dispose
  25.       self.contents = nil
  26.     end
  27.     @data = []
  28.     for i in [email]0...@actor.skills.size[/email]
  29.       skill = $data_skills[@actor.skills[i]]
  30.       if skill != nil
  31.         case skill.id
  32.          when 54..200  #小
  33.           @data.push(skill)
  34.          when 950..982 #神
  35.           @data.push(skill)
  36.          when 900..928 #圣
  37.           @data.push(skill)
  38.         end
  39.       end
  40.     end
  41.     # 如果项目数不是 0 就生成位图、重新描绘全部项目
  42.     @item_max = @data.size
  43.     if @item_max > 0
  44.       self.contents = Bitmap.new(width - 32, row_max * 32)
  45.       for i in 0...@item_max
  46.         draw_item(i)
  47.       end
  48.     end
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 描绘项目
  52.   #     index : 项目编号
  53.   #--------------------------------------------------------------------------
  54.   def draw_item(index)
  55.     skill = @data[index]
  56.     x = 4 + index % 1 * (288 + 32)
  57.     y = index / 1 * 32
  58.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  59.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  60.     bitmap = RPG::Cache.icon(skill.icon_name)
  61.     opacity = self.contents.font.color == normal_color ? 255 : 128
  62.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  63.     self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
  64.     self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● 刷新帮助文本
  68.   #--------------------------------------------------------------------------
  69.   def update_help
  70.     @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  71.   end
  72. end
复制代码


脚本三

  1. class Window_Status_Level < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化对像
  4.   #     actor : 角色
  5.   #--------------------------------------------------------------------------
  6.   def initialize(actor)
  7.     super(40, 100, 260, 250)
  8.     self.contents = Bitmap.new(width - 32, height - 32)
  9.     @actor = actor
  10.     refresh
  11.   end
  12.   #--------------------------------------------------------------------------
  13.   # ● 刷新
  14.   #--------------------------------------------------------------------------
  15.   def refresh
  16.     self.contents.clear
  17.     draw_actor_name(@actor, 100, 0)
  18.     draw_actor_fas(@actor, 5, 10)
  19.     text =  "消耗角色魂力来提升当前技能,"
  20.     text1 = "的等级.每个级别的技能等级"
  21.     text2 = "上限都有所不同。品质越高"
  22.     text3 = "可以提升的等级就越高哦!"
  23.     self.contents.draw_text(x-30, y, 260, 32,text)
  24.     self.contents.draw_text(x-30, y+20, 260, 32,text1)
  25.     self.contents.draw_text(x-30, y+40, 260, 32,text2)
  26.     self.contents.draw_text(x-30, y+60, 260, 32,text3)
  27.   end
  28. end
复制代码


脚本四

  1. #$scene =Scene_Skill_Level.new
  2. class Scene_Skill_Level
  3.   #--------------------------------------------------------------------------
  4.   # ● 初始化对像
  5.   #     actor_index : 角色索引
  6.   #--------------------------------------------------------------------------
  7.   def initialize(actor_index = 0, equip_index = 0)
  8.     @actor_index = actor_index
  9.   end
  10.   #--------------------------------------------------------------------------
  11.   # ● 主处理
  12.   #--------------------------------------------------------------------------
  13.   def main
  14.     # 获取角色
  15.     @actor = $game_party.actors[@actor_index]
  16.    
  17.     # 生成帮助窗口、状态窗口、特技窗口
  18.     @help_window = Window_Skill_Help.new
  19.    
  20.     @help_window.y = 100
  21.    
  22.     @status_window = Window_Status_Level.new(@actor)
  23.    
  24.     @skill_window = Window_C_Level.new(@actor)
  25.    
  26.    
  27.     # 执行过渡
  28.     Graphics.transition
  29.     # 主循环
  30.     loop do
  31.       # 刷新游戏画面
  32.       Graphics.update
  33.       # 刷新输入信息
  34.       Input.update
  35.       # 刷新画面
  36.       update
  37.       # 如果画面切换的话就中断循环
  38.       if $scene != self
  39.         break
  40.       end
  41.     end
  42.     # 准备过渡
  43.     Graphics.freeze
  44.     # 释放窗口
  45.     @help_window.dispose
  46.     @status_window.dispose
  47.     @skill_window.dispose
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # ● 刷新画面
  51.   #--------------------------------------------------------------------------
  52.   def update
  53.     # 刷新窗口
  54.     @help_window.update
  55.     @status_window.update
  56.     @skill_window.update
  57.    
  58.     if @skill_window.active
  59.       update_skill
  60.       return
  61.     end
  62.    
  63.     if @skilla_window.active
  64.       update_skilla
  65.       return
  66.     end
  67.   
  68.   end
  69.   
  70.   
  71.   def update_skill
  72.     if Input.trigger?(Input::B)
  73.       $game_system.se_play($data_system.cancel_se)
  74.       $scene = Scene_Menu.new(1)
  75.       return
  76.     end
  77.     if Input.trigger?(Input::C)
  78.       @skill = @skill_window.skill
  79.   case @skill.id
  80.     when 54..78  #C
  81.       if @skill.power==10
  82.          p "满了,满了,不要溢出来了"
  83.        else
  84.       if $game_variables[27]>=$技能经验C[@skill.power]
  85.           Audio.se_play("Audio/SE/Y_se_streng")
  86.           $game_variables[27]-=$技能经验C[@skill.power]
  87.           @skill.power+=1
  88.           @skill_window.refresh
  89.         else
  90.           $game_system.se_play($data_system.cancel_se)
  91.         end
  92.       end
  93.     when 100..128  #B
  94.       if @skill.power==15
  95.          p "满了,满了,不要溢出来了"
  96.        else
  97.       if $game_variables[27]>=$技能经验B[@skill.power]
  98.           Audio.se_play("Audio/SE/Y_se_streng")
  99.           $game_variables[27]-=$技能经验B[@skill.power]
  100.           @skill.power+=1
  101.           @skill_window.refresh
  102.         else
  103.           $game_system.se_play($data_system.cancel_se)
  104.         end
  105.       end
  106.       
  107.     #神技定义升级
  108.     when 950..982
  109.       if @skill.power==4
  110.          p "满了,满了,不要溢出来了"
  111.        else
  112.       if $game_variables[27]>=$神技经验[@skill.power]
  113.           Audio.se_play("Audio/SE/Y_se_streng")
  114.           $game_variables[27]-=$神技经验[@skill.power]
  115.           @skill.power+=1
  116.           @skill_window.refresh
  117.         else
  118.           $game_system.se_play($data_system.cancel_se)
  119.         end
  120.       end
  121.       
  122.       
  123.     #圣技定义升级
  124.     when 900..928
  125.       if @skill.power==5
  126.          p "满了,满了,不要溢出来了"
  127.        else
  128.       if $game_variables[27]>=$圣技经验[@skill.power]
  129.           Audio.se_play("Audio/SE/Y_se_streng")
  130.           $game_variables[27]-=$圣技经验[@skill.power]
  131.           @skill.power+=1
  132.           @skill_window.refresh
  133.         else
  134.           $game_system.se_play($data_system.cancel_se)
  135.         end
  136.       end
  137.       
  138.     end
  139.       return
  140.     end
  141.     if Input.trigger?(Input::R)
  142.       $game_system.se_play($data_system.cursor_se)
  143.       @actor_index += 1
  144.       @actor_index %= $game_party.actors.size
  145.       $scene = Scene_Skill_Level.new(@actor_index)
  146.       return
  147.     end
  148.     if Input.trigger?(Input::L)
  149.       $game_system.se_play($data_system.cursor_se)
  150.       @actor_index += $game_party.actors.size - 1
  151.       @actor_index %= $game_party.actors.size
  152.       $scene = Scene_Skill_Level.new(@actor_index)
  153.       return
  154.     end
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   alias add_update_skill_mohuaiyuan update_skill
  158.   def update_skill
  159.     @help_window.x = (@skill_window.index + 1) % 2 * 342 + 4
  160.     @help_window.set_skill(@skill_window.skill.id, @actor.id)
  161.     @help_window.visible = true
  162.     add_update_skill_mohuaiyuan
  163.   end
  164.   #--------------------------------------------------------------------------
  165. end
复制代码


然后裁图脚本写入

  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],转载和使用请保留此信息
  3. #===============================================================================

  4. BBS_66RPG_DIR = "Save/"  # 储存文件夹名,请制作游戏时自行建立此文件夹

  5. # 若想使用自定义背景图,脚本62行的井号去掉,并放置一张相应图形。

  6. # 在你的Scene_Title中找到这一段(如果使用其他插件脚本,在插件中找):
  7. #    for i in 0..3
  8. #      if FileTest.exist?("Save#{i+1}.rxdata")
  9. # 请自行把0..3改为0..最大进度号,比如0..9
  10. # "Save#{i+1}.rxdata" 改为"Save/Save#{i}.rxdata"

  11. # 增加进度的方法:138,258行,继续添加。你也可以改“进度X”为“回忆X”或者“红/绿/蓝笔记本”

  12. #===============================================================================
  13. module Screen  
  14.   @screen = Win32API.new 'screenshot', 'Screenshot', %w(l l l l p l l), ''
  15.   @readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
  16.   @findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
  17.   module_function
  18.   #-----------------------------------------------------------------------------
  19.   def shot(file = "shot", typ = 1)
  20.     # to add the right extension...
  21.     if typ == 0
  22.       typname = ".bmp"
  23.     elsif typ == 1
  24.       typname = ".jpg"
  25.     elsif typ == 2
  26.       typname = ".png"
  27.     end   
  28.     file_index = 0   
  29.     dir = "Save/"   
  30.     # make the filename....
  31.     file_name = dir + file.to_s + typname.to_s   
  32.     # make the screenshot.... Attention dont change anything from here on....
  33.     @screen.call(0,0,640,480,file_name,handel,typ)
  34.   end
  35.   # find the game window...
  36.   def handel
  37.     game_name = "\0" * 256
  38.     @readini.call('Game','Title','',game_name,255,".\\Game.ini")
  39.     game_name.delete!("\0")
  40.     return @findwindow.call('RGSS Player',game_name)
  41.   end
  42. end

  43. class Window_File < Window_Base
  44.   attr_accessor :index
  45.   def initialize(index = 0)
  46.     @backsp = Sprite.new
  47.     #@backsp.bitmap = Bitmap.new("Graphics/Pictures/存盘背景.jpg")
  48.     @backsp.z = 99
  49.     super(160,0,480,480)
  50.     #这行可以不用
  51.     self.contents = Bitmap.new(width - 32, height - 32)
  52.     @index = index
  53.     #这里我要说明一句,之所以用sprite是为了放缩图片
  54.     @sprite = Sprite.new
  55.     @sprite.visible = false
  56.     @sprite.z = 100
  57.     @sp_ch = []
  58.     @sp_ch[0] = Sprite.new
  59.     refresh
  60.   end
  61.   def refresh
  62.     self.contents.clear
  63.     for i in @sp_ch
  64.       i.visible = false
  65.     end
  66.     @sprite.visible = false
  67.     if FileTest.exist?(BBS_66RPG_DIR+"Save#{@index}.rxdata")
  68.       @sprite.visible = true
  69.       if FileTest.exist?(BBS_66RPG_DIR+"Save#{@index}.jpg")
  70.         @sprite.bitmap = Bitmap.new(BBS_66RPG_DIR+"Save#{@index}.jpg")
  71.       else
  72.         self.contents.draw_text(32,64,400,32,"截图似乎有点问题……您搞什么了您?")
  73.       end
  74.       @sprite.x = 176
  75.       @sprite.y = 16
  76.       @sprite.zoom_x = 0.7
  77.       @sprite.zoom_y = 0.7
  78.       file = File.open(BBS_66RPG_DIR+"Save#{@index}.rxdata", "r")
  79.       @time_stamp = file.mtime
  80.       @characters = Marshal.load(file)
  81.       @frame_count = Marshal.load(file)
  82.       @game_system = Marshal.load(file)
  83.       @game_switches = Marshal.load(file)
  84.       @game_variables = Marshal.load(file)
  85.       @total_sec = @frame_count / Graphics.frame_rate
  86.       file.close
  87.       for i in [email]0...@characters.size[/email]
  88.         @sp_ch[i] = Sprite.new
  89.         @sp_ch[i].visible = true
  90.         @sp_ch[i].bitmap = RPG::Cache.battler(@characters[i][3], @characters[i][4])
  91.         @sp_ch[i].x = 180 + i*80      
  92.         @sp_ch[i].y = 440 - @sp_ch[i].bitmap.height
  93.         @sp_ch[i].z = 101
  94.       end
  95.       self.contents.font.color = normal_color
  96.       self.contents.draw_text(324, 360, 420, 32,"风云III残破的世界")

  97.       # 描绘游戏时间
  98.       hour = @total_sec / 60 / 60
  99.       min = @total_sec / 60 % 60
  100.       sec = @total_sec % 60
  101.       time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  102.       self.contents.font.color = normal_color
  103.       self.contents.draw_text(4, 390, 420, 32, time_string, 2)
  104.       # 描绘时间标记
  105.       self.contents.font.color = normal_color
  106.       time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
  107.       self.contents.draw_text(4, 420, 420, 32, time_string, 2)
  108.     else
  109.       self.contents.draw_text(32,32,420,32,"这个存档是空的")
  110.     end
  111.   end
  112.   def dispose
  113.     super
  114.     @sprite.dispose
  115.     @backsp.dispose
  116.     for i in @sp_ch
  117.       i.dispose
  118.     end
  119.   end
  120. end


  121. class Scene_Save
  122.   def main
  123.     @command_window = Window_Command.new(160,["记录一","记录二","记录三","记录四","记录五","记录六"])
  124.     @command_window.y = 96
  125.     @command_window.index = $game_temp.last_file_index
  126.     @content_window = Window_File.new($game_temp.last_file_index)
  127.     # 执行过渡
  128.     Graphics.transition
  129.     # 主循环
  130.     loop do
  131.       # 刷新游戏画面
  132.       Graphics.update
  133.       # 刷新输入信息
  134.       Input.update
  135.       # 刷新画面
  136.       update
  137.       # 如果画面被切换的话就中断循环
  138.       if $scene != self
  139.         break
  140.       end
  141.     end
  142.     # 准备过渡
  143.     Graphics.freeze
  144.     @command_window.dispose
  145.     @content_window.dispose
  146.   end
  147.   def update
  148.     @command_window.update   
  149.     if @command_window.index != @content_window.index
  150.       @content_window.index = @command_window.index
  151.       @content_window.refresh
  152.     end   
  153.     #——————下面这一部分是原装脚本——————#
  154.     if Input.trigger?(Input::B)  
  155.       $game_system.se_play($data_system.cancel_se)
  156.       if $game_temp.save_calling
  157.         $game_temp.save_calling = false
  158.         $scene = Scene_Map.new
  159.         return
  160.       end
  161.       $scene = Scene_Menu.new(4)
  162.     end   
  163.     #———————————————————————#   
  164.     if Input.trigger?(Input::C)
  165.       # 演奏存档 SE
  166.       $game_system.se_play($data_system.save_se)
  167.       # 写入存档数据
  168.       file = File.open(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata", "wb")
  169.       write_save_data(file)
  170.       if FileTest.exist?(BBS_66RPG_DIR+"shot.jpg")
  171.         File.rename(BBS_66RPG_DIR+"shot.jpg", BBS_66RPG_DIR+"Save#{@command_window.index}.jpg")
  172.       end
  173.       file.close
  174.       $game_temp.last_file_index = @command_window.index
  175.       # 如果被事件调用
  176.       if $game_temp.save_calling
  177.         # 清除存档调用标志
  178.         $game_temp.save_calling = false
  179.         # 切换到地图画面
  180.         $scene = Scene_Map.new
  181.         return
  182.       end
  183.       # 切换到菜单画面
  184.       $scene = Scene_Map.new
  185.     end
  186.     #———————————————————————#
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # ● 写入存档数据
  190.   #     file : 写入用文件对像 (已经打开)
  191.   #--------------------------------------------------------------------------
  192.   def write_save_data(file)
  193.     # 生成描绘存档文件用的角色图形
  194.     characters = []
  195.     for i in 0...$game_party.actors.size
  196.       actor = $game_party.actors[i]
  197.       characters.push([actor.character_name, actor.character_hue, actor.id, actor.battler_name, actor.battler_hue])
  198.     end
  199.     # 写入描绘存档文件用的角色数据
  200.     Marshal.dump(characters, file)
  201.     # 写入测量游戏时间用画面计数
  202.     Marshal.dump(Graphics.frame_count, file)
  203.     # 增加 1 次存档次数
  204.     $game_system.save_count += 1
  205.     # 保存魔法编号
  206.     # (将编辑器保存的值以随机值替换)
  207.     $game_system.magic_number = $data_system.magic_number
  208.     # 写入各种游戏对像
  209.     Marshal.dump($game_system, file)
  210.     Marshal.dump($game_switches, file)
  211.     Marshal.dump($game_variables, file)
  212.     Marshal.dump($game_self_switches, file)
  213.     Marshal.dump($game_screen, file)
  214.     Marshal.dump($game_actors, file)
  215.     Marshal.dump($game_party, file)
  216.     Marshal.dump($game_troop, file)
  217.     Marshal.dump($game_map, file)
  218.     Marshal.dump($game_player, file)
  219.    
  220.     save_data($data_weapons, "Data/Weapons.rxdata")
  221.     save_data($data_armors, "Data/Armors.rxdata")
  222.     save_data($data_classes, "Data/Classes.rxdata")
  223.     save_data($data_skills, "Data/Skills.rxdata")
  224.    
  225.     save_data($data_states, "Data/States.rxdata")
  226.    
  227.    
  228.       
  229.    
  230.    
  231.   end
  232. end


  233. class Scene_Load
  234.   def initialize
  235.     # 再生成临时对像
  236.     $game_temp = Game_Temp.new
  237.     # 选择存档时间最新的文件
  238.     $game_temp.last_file_index = 0
  239.     latest_time = Time.at(0)
  240.     for i in 0..6
  241.       filename = BBS_66RPG_DIR+"Save#{i}.rxdata"
  242.       if FileTest.exist?(filename)
  243.         file = File.open(filename, "r")
  244.         if file.mtime > latest_time
  245.           latest_time = file.mtime
  246.           $game_temp.last_file_index = i
  247.         end
  248.         file.close
  249.       end
  250.     end
  251.   end  
  252.   def main
  253.     @command_window = Window_Command.new(160,["进度一","进度二","进度三","进度四","进度五","进度六"])
  254.     @command_window.y = 96
  255.     @command_window.index = $game_temp.last_file_index
  256.     @content_window = Window_File.new($game_temp.last_file_index)
  257.     # 执行过渡
  258.     Graphics.transition
  259.     # 主循环
  260.     loop do
  261.       # 刷新游戏画面
  262.       Graphics.update
  263.       # 刷新输入信息
  264.       Input.update
  265.       # 刷新画面
  266.       update
  267.       # 如果画面被切换的话就中断循环
  268.       if $scene != self
  269.         break
  270.       end
  271.     end
  272.     # 准备过渡
  273.     Graphics.freeze
  274.     @command_window.dispose
  275.     @content_window.dispose
  276.   end
  277.   def update
  278.     @command_window.update   
  279.     if @command_window.index != @content_window.index
  280.       @content_window.index = @command_window.index
  281.       @content_window.refresh
  282.     end   
  283.     #——————下面这一部分是原装脚本——————#
  284.     if Input.trigger?(Input::B)  
  285.     # 演奏取消 SE
  286.     $game_system.se_play($data_system.cancel_se)
  287.     # 切换到标题画面
  288.     $scene = Scene_Title.new
  289.     end   
  290.     #———————————————————————#   
  291.     if Input.trigger?(Input::C)
  292.       # 文件不存在的情况下
  293.       unless FileTest.exist?(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata")
  294.         # 演奏冻结 SE
  295.         $game_system.se_play($data_system.buzzer_se)
  296.         return
  297.       end
  298.       # 演奏读档 SE
  299.       $game_system.se_play($data_system.load_se)
  300.       # 写入存档数据
  301.       file = File.open(BBS_66RPG_DIR+"Save#{@command_window.index}.rxdata", "rb")
  302.       read_save_data(file)
  303.       file.close
  304.       # 还原 BGM、BGS
  305.       $game_system.bgm_play($game_system.playing_bgm)
  306.       $game_system.bgs_play($game_system.playing_bgs)
  307.       # 刷新地图 (执行并行事件)
  308.       $game_map.update
  309.       # 切换到地图画面
  310.       $scene = Scene_Map.new
  311.     end
  312.     #———————————————————————#
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # ● 写入存档数据
  316.   #     file : 写入用文件对像 (已经打开)
  317.   #--------------------------------------------------------------------------
  318.   def read_save_data(file)
  319.     # 读取描绘存档文件用的角色数据
  320.     characters = Marshal.load(file)
  321.     # 读取测量游戏时间用画面计数
  322.     Graphics.frame_count = Marshal.load(file)
  323.     # 读取各种游戏对像
  324.     $game_system        = Marshal.load(file)
  325.     $game_switches      = Marshal.load(file)
  326.     $game_variables     = Marshal.load(file)
  327.     $game_self_switches = Marshal.load(file)
  328.     $game_screen        = Marshal.load(file)
  329.     $game_actors        = Marshal.load(file)
  330.     $game_party         = Marshal.load(file)
  331.     $game_troop         = Marshal.load(file)
  332.     $game_map           = Marshal.load(file)
  333.     $game_player        = Marshal.load(file)
  334.    
  335.     save_data($data_weapons, "Data/Weapons.rxdata")
  336.     save_data($data_armors, "Data/Armors.rxdata")
  337.     save_data($data_classes, "Data/Classes.rxdata")
  338.     save_data($data_skills, "Data/Skills.rxdata")
  339.    
  340.     # 魔法编号与保存时有差异的情况下
  341.     # (加入编辑器的编辑过的数据)
  342.     if $game_system.magic_number != $data_system.magic_number
  343.       # 重新装载地图
  344.       $game_map.setup($game_map.map_id)
  345.       $game_player.center($game_player.x, $game_player.y)
  346.     end
  347.     # 刷新同伴成员
  348.     $game_party.refresh
  349.   end
  350. end

  351. class Scene_Menu
  352.   alias bbs_66rpg_shotsave_main main
  353.   def main
  354.     if @menu_index == 0
  355.       Screen::shot
  356.     end   
  357.     bbs_66rpg_shotsave_main
  358.   end
  359. end

  360. class Interpreter
  361.   #--------------------------------------------------------------------------
  362.   # ● 调用存档画面
  363.   #--------------------------------------------------------------------------
  364.   def command_352
  365.     # 设置战斗中断标志
  366.     $game_temp.battle_abort = true
  367.     # 设置调用存档标志
  368.     $game_temp.save_calling = true
  369.     # 推进索引
  370.     @index += 1
  371.     # 结束
  372.     Screen::shot
  373.     return false
  374.   end
  375. end
复制代码


学习使我疲劳,打工使我疲惫,恋爱使我伤身,吸烟伤我肺腑,饮酒损我形象,旅游使我破费,月底不见铜板,只有在论坛里面看看各种大佬才能使我进去

梦石
1
星屑
23371
在线时间
9572 小时
注册时间
2012-6-19
回帖
7021

开拓者短篇九导演组冠军

发表于 2016-9-24 17:37:59 | 显示全部楼层
因为数据库做的事情就是这个……你要强化装备就不要动data开头的那些全局变量

点评

。。。那要怎么去做升级效果啊不动这些  发表于 2016-9-24 17:40

评分

参与人数 1星屑 +90 收起 理由
RyanBern + 90 我很赞同

查看全部评分

回复 1 0

使用道具 举报

梦石
0
星屑
9726
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-9-24 17:39:48 | 显示全部楼层
也许可以这么干……
强化之类的需要保存文件的操作可以另存不同名的数据文件,
然后开始游戏初始化数据的时候,
把记录这类数据的全局变量拐带去读另存的文件,
如果另存的文件不存在再读原数据库的文件。
(这样做的后果就是数据库有更新相关数据的时候运行游戏不会更新,必须先删掉(或改名)记录强化数据的文件才行。

点评

我把主楼我自己写的技能升级放进去了 结果就是我说的问题  发表于 2016-9-24 17:50
回复 1 0

使用道具 举报

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

开拓者

发表于 2016-9-24 21:42:20 | 显示全部楼层
另外加个变量。需要用到的地方都相加或者想成这个新的变量。

点评

好像除了建立新的ID在保存,否则都会被数据库灭了,我还是用写入存档的方式吧,只不过是写入要强化的属性其他的就不保存就好了  发表于 2016-9-27 07:55
用自带的变量可以被保存。$game_variables[1]  发表于 2016-9-26 13:48
应该换个说法。其实这并不是用这些命令,强化的问题。是XP的SAVE不能保存变量造成的。一起求个能保存变量的SAVE吧。我也需要  发表于 2016-9-26 12:44
加了也没用 一切都会还原 就算实例定义新的也没用!  发表于 2016-9-26 08:27
不是动数据库啊,是动自己加的新变量  发表于 2016-9-25 22:00
回复

使用道具 举报

梦石
0
星屑
606
在线时间
797 小时
注册时间
2014-7-1
回帖
501

开拓者

 楼主| 发表于 2016-9-27 08:12:52 | 显示全部楼层
yang1zhi 发表于 2016-9-24 21:42
另外加个变量。需要用到的地方都相加或者想成这个新的变量。
  1.    
  2.    $game_system        = Marshal.load(file)
  3.     $game_switches      = Marshal.load(file)
  4.     $game_variables     = Marshal.load(file
  5.     $game_self_switches = Marshal.load(file)
  6.     $game_screen        = Marshal.load(file)
  7.     $game_actors        = Marshal.load(file)
  8.     $game_party         = Marshal.load(file)
  9.     $game_troop         = Marshal.load(file)
  10.     $game_map           = Marshal.load(file)
  11.     $game_player        = Marshal.load(file)
复制代码

存档就保存这些 在这些里面定义实例会被保存 而且也可以在事件中直接用$命令调取
例如:


  1. class Game_Actor < Game_Battler
  2.   attr_accessor :crt     # 暴击几率
  3.   alias mohuaiyuan2016927_setup setup
  4.   def setup(actor_id)
  5.     mohuaiyuan2016927_setup(actor_id)
  6.    @crt_z = 0
  7. end
  8.   def crt # 暴击几率
  9.       @crt_z = [[@crt_z, 1].max,9999].min
  10.       n = @crt_z
  11.       return [[n, 1].max, 9999].min
  12.     end
  13.    
  14.   def crt=(crt)
  15.     @crt_z += crt - self.crt
  16.     @crt_z = [[@crt_z, 1].max,9999].min
  17.   end  
  18. end
复制代码
[/pre]
这样就成功了 这里对应了 $game_actors        = Marshal.load(file)

其他的例如防具 武器 技能 等等上面存档没有  
按照上面方法来定义的话 也不会被接受 可能是少了那个步骤
想要直接采用$的命令来强化防具武器等等只能用 $data_skills       = Marshal.load(file) 类的命令来存档了 或者分开一些
$data_skills.name       = Marshal.load(file) 只保存名字。
学习使我疲劳,打工使我疲惫,恋爱使我伤身,吸烟伤我肺腑,饮酒损我形象,旅游使我破费,月底不见铜板,只有在论坛里面看看各种大佬才能使我进去
回复

使用道具 举报

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

开拓者贵宾剧作品鉴家

发表于 2016-9-27 12:07:43 | 显示全部楼层
本帖最后由 RyanBern 于 2016-9-27 12:53 编辑

稍微看了一下你的代码,里面有几个非常严重的问题。
用这些命令写入存档  游戏中强化等等都可以永久保存

但是只要一打开游戏的数据库就会还原,怎么回事?有什么办法解决吗?

1. 我试了一下,其实并没有。在你的代码中,你只对技能中的@power变量做出了更改,所以其他变量是根本没有变化的。改变的只是@power而已。所以使用RM打开时,是能看到“威力”一栏发生了变化,其他的项目是不动的。

2. 对于技能来说,@power是表示技能“威力”,现在你把它改成了“技能等级”,不知道是不是你故意这样设置的。

3. 正如喵呜所说,数据库的作用就是写死了某些设定,而并非可以随着游戏进度的变化而变化,这不是数据库该做的事情。正如,数据库中的“角色RPG::Actor”是写死的,里面包含了升级相关的能力值(例如每一级的MAXHP),升级所需经验等不会发生改变的数据。而并非游戏运行中的“Game_Actor”。所以,直接去改数据库文件是非常不明智的做法,除非你确定你在做什么,否则会有很多问题。例如,假如一把武器所有人都可以买(装备),那么按照你的思路去更改数据库,一把武器强化之后,是不是其他所有的武器都一起强化了呢?这一般不是我们要的效果,当然除非你就是要这么做。退一步讲,就算你真的要这么做,那么当玩家想重新开一个档玩的时候,这些被强化的数据由于存在数据库里了,那么新档下这些装备也都是强化过了的!那么这是否也是你需要的效果呢?

4. 滥用全局变量。这点已经说过很多次了,有些人搞不清变量之间的区别,然后就开始滥用全局变量,反正全局变量是永远都可以用的,这是非常不好的习惯。同样的,表示写死了的常量也不应该使用全局变量表示,应该用常量+命名空间的形式。

所以,你要明白游戏中应该存什么,不应该存什么。至于如何实现,希望你忘掉当前的代码,重新思考一下。首先你弄清楚我在(3)中提到的问题,确定你是否真的这么做。然后重新实现这个效果。

至于存储额外的变量,我已经写过非常详细的教程,你可以看看。
https://rpg.blue/forum.php?mod=viewthread&tid=375515

点评

好的,我要好好考虑一下这些问题!谢谢了!  发表于 2016-9-27 14:14
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部