Project1
标题:
自动存档,如何改自动为事件调用?
[打印本页]
作者:
白鬼
时间:
2009-7-29 10:42
标题:
自动存档,如何改自动为事件调用?
本帖最后由 白鬼 于 2009-7-29 13:29 编辑
美兽的自动存档脚本。如何修改成非自动,而是事件调用来存档?
module Kernel
alias origin_exit exit unless method_defined? :exit
def exit(*args)
case $scene
when Scene_Map
AutoSave.common_save unless $game_system.map_interpreter.running?
when Scene_Battle
AutoSave.common_save unless $game_system.battle_interpreter.running?
else
if $scene.type != NilClass and $scene.type != Scene_Title
AutoSave.common_save
end
end
origin_exit(*args)
end
end
module AutoSave
if @scene_proc.nil?
@last_scene = nil.class
@scene_proc = proc do |value|
if value.nil? or value.is_a?(Scene_Title)
if @last_scene != NilClass and @last_scene != Scene_Title
AutoSave.common_save
end
end
@last_scene = value.type
end
trace_var(:$scene,@scene_proc)
end
module_function
def common_save
filename = "Save#{$game_temp.last_file_index + 1}.rxdata"
file = File.open(filename, "wb")
write_save_data(file)
file.close
end
#--------------------------------------------------------------------------
# ● 写入存档数据
# file : 写入用文件对像 (已经打开)
#--------------------------------------------------------------------------
def write_save_data(file)
# 生成描绘存档文件用的角色图形
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
# 写入描绘存档文件用的角色数据
Marshal.dump(characters, file)
# 写入测量游戏时间用画面计数
Marshal.dump(Graphics.frame_count, file)
# 增加 1 次存档次数
$game_system.save_count += 1
# 保存魔法编号
# (将编辑器保存的值以随机值替换)
$game_system.magic_number = $data_system.magic_number
# 写入各种游戏对像
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
end
end
复制代码
作者:
Goldencolor
时间:
2009-7-29 10:45
事件。脚本调用你要执行代码块或者类
作者:
白鬼
时间:
2009-7-29 10:51
我修改的:
#==============================================================================
# ■ Scene_AutoSave
#------------------------------------------------------------------------------
# 处理自动存档画面的类。
#==============================================================================
class Scene_AutoSave < Scene_File
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize
filename = "System.rxdata" #byakki
file = File.open(filename, "wb")
write_save_data(file)
file.close
end
#--------------------------------------------------------------------------
# ● 写入存档数据
# file : 写入用文件对像 (已经打开)
#--------------------------------------------------------------------------
def write_save_data(file)
# 生成描绘存档文件用的角色图形
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue])
end
# 写入描绘存档文件用的角色数据
Marshal.dump(characters, file)
# 写入测量游戏时间用画面计数
Marshal.dump(Graphics.frame_count, file)
# 增加 1 次存档次数
$game_system.save_count += 1
# 保存魔法编号
# (将编辑器保存的值以随机值替换)
$game_system.magic_number = $data_system.magic_number
# 写入各种游戏对像
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
end
end
复制代码
然后事件脚本:
$scene = Scene_AutoSave.new
复制代码
【存档的时候Window_Help报错】
26 self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
复制代码
发生了 TypeErro。
cannot convert nil into String
复制代码
但是貌似生成了存档文件。
【读取的时候,也是这个错误】
作者:
后知后觉
时间:
2009-7-29 11:29
这个脚本先是定义了 退出
就是说窗口在关闭的时候就会自动存档
不想要这个效果就把这一段删除
module Kernel
alias origin_exit exit unless method_defined? :exit
def exit(*args)
case $scene
when Scene_Map
AutoSave.common_save unless $game_system.map_interpreter.running?
when Scene_Battle
AutoSave.common_save unless $game_system.battle_interpreter.running?
else
if $scene.type != NilClass and $scene.type != Scene_Title
AutoSave.common_save
end
end
origin_exit(*args)
end
end
然后要存档的时候在事件-脚本里输入
AutoSave.common_save
作者:
玄月
时间:
2009-7-29 14:19
美兽的个人觉得不是很好用。
你可以把这段脚本插入Interpreter 7
###########################################################################
#--------------------------------------------------------------------------
# ● 写入存档数据
#--------------------------------------------------------------------------
def save(i=1)
file = File.open("Save/Save#{i}.rxdata", "wb")
# 生成描绘存档文件用的角色图形
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue, actor.id, actor.battler_name, actor.battler_hue])
end
# 写入描绘存档文件用的角色数据
Marshal.dump(characters, file)
# 写入测量游戏时间用画面计数
Marshal.dump(Graphics.frame_count, file)
# 增加 1 次存档次数
$game_system.save_count += 1
# 保存魔法编号
# (将编辑器保存的值以随机值替换)
$game_system.magic_number = $data_system.magic_number
# 写入各种游戏对像
Marshal.dump($data_skills, file)
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
file.close
end
###########################################################################
复制代码
然后事件中执行脚本“save(x)”x = 脚本编号
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1