Project1
标题:
想做个快速保存的脚本
[打印本页]
作者:
b200077
时间:
2020-3-11 22:45
标题:
想做个快速保存的脚本
本帖最后由 b200077 于 2020-3-11 22:46 编辑
目前知道怎么在对话匡和大地图呼叫存挡画面,可是翻了翻脚本,我实在看不懂怎么存的,有没有大佬可以讲解一下Datamanager吗?
然后讲解一下要怎么跳过存檔画面存檔
作者:
Nil2018
时间:
2020-3-11 22:45
# =============================================================================
# TheoAllen - 快速存储和读取
# Version : 1.1
# Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
# (This script documentation is written in informal indonesian language)
# =============================================================================
($imported ||= {})[:Theo_Quick] = true
# =============================================================================
# CHANGE LOGS:
# -----------------------------------------------------------------------------
# - 2013.05.11 - Nambahin switch id
# - 2013.05.04 - Script selesai
# =============================================================================
=begin
介绍:
该脚本可以让玩家在游戏中按某个键来进行快速存/读档
存档文件也可以存在指定存档文件下
使用方法:
插入到插件脚本之下,Main之上
编辑下面的设置。
使用条款 :
署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
=end
# =============================================================================
# 设定部分:
# =============================================================================
module THEO
module SAVE
SAVE_BUTTON = :F5 # 快速存档的按键
LOAD_BUTTON = :F6 # 快速读档的按键
INDEX = 0 # 快速存/读档时保存到哪个文件(默认为0)
SHOW_COUNT = 150 # 通知窗口的宽度 (默认:150)
FADEIN = 16 # 淡入速度 (默认:16)
FADEOUT = 16 # 淡出速度 (默认:16)
SAVE_NOTIFY = "游戏已保存"
# 显示快速存档时的信息
LOAD_NOTIFY = "游戏已读取"
# 显示快速读档时的信息
SAVE_SWITCH_ID = 1
LOAD_SWITCH_ID = 1
# 对应的开关打开时,才会启用快速存/读档功能(*新)
end
end
# =============================================================================
# 设定结束
# =============================================================================
class Window_Notify < Window_Base
def initialize
super(Graphics.width - window_width, 0, window_width, fitting_height(1))
self.opacity = 0
self.contents_opacity = 0
@show_count = 0
refresh
end
def update_fadein
self.contents_opacity += THEO::SAVE::FADEIN
end
def update_fadeout
self.contents_opacity -= THEO::SAVE::FADEOUT
end
def refresh
contents.clear
draw_background(contents.rect)
draw_text(0,0,contents.width,contents.height,@notify,1)
end
def show=(text)
@notify = text
open
end
def window_width
return 240
end
def update
super
if @show_count > 0
update_fadein
@show_count -= 1
else
update_fadeout
end
end
def open
refresh
@show_count = THEO::SAVE::SHOW_COUNT
self.contents_opacity = 0
self
end
def close
@show_count = 0
self
end
def draw_background(rect)
temp_rect = rect.clone
temp_rect.width /= 2
contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
temp_rect.x = temp_rect.width
contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
end
def back_color1
Color.new(0, 0, 0, 192)
end
def back_color2
Color.new(0, 0, 0, 0)
end
end
class Scene_Map < Scene_Base
alias start_quick_save_load start
def start
start_quick_save_load
create_notify
show_load_notify if $game_system.quick_load
end
def create_notify
@notify_window = Window_Notify.new
@notify_window.viewport = @viewport
end
alias quick_save_load_update update
def update
quick_save_load_update
save_file if input_save?
load_file if input_load?
end
def save_file
@notify_window.close
$game_system.on_before_save
DataManager.save_game(THEO::SAVE::INDEX)
show_save_notify
end
def load_file
@notify_window.close
DataManager.load_game(THEO::SAVE::INDEX)
$game_system.on_after_load
SceneManager.goto(Scene_Map)
$game_system.quick_load = true
end
def show_save_notify
@notify_window.show = THEO::SAVE::SAVE_NOTIFY
end
def show_load_notify
@notify_window.show = THEO::SAVE::LOAD_NOTIFY
$game_system.quick_load = false
end
def input_save?
id = THEO::SAVE::SAVE_SWITCH_ID
Input.trigger?(THEO::SAVE::SAVE_BUTTON) && (id > 0 ? $game_switches[id] : true)
end
def input_load?
id = THEO::SAVE::LOAD_SWITCH_ID
Input.trigger?(THEO::SAVE::LOAD_BUTTON) && (id > 0 ? $game_switches[id] : true)
end
end
class Game_System
attr_accessor :quick_load
alias pre_quick_init initialize
def initialize
pre_quick_init
@quick_load = false
end
end
复制代码
作者:
MCCF
时间:
2020-3-12 10:05
本帖最后由 MCCF 于 2020-3-12 10:09 编辑
如果LZ是自己在尝试的话……我觉得善用脚本编辑器的“全局搜索”吧,可以很方便地找到需要查看的方法。
存档的基本方法是DataManager.save_game(index),index是存档编号。
内部实现很简单,把当前$game_variables和$game_player这些
游戏实例
用Marshal.dump塞进存档。然后外面再包装一个异常处理,防止无法写入导致脚本崩溃。
读档是DataManager.load_game(index)。就是把当前的游戏实例设置成存档中所存储的。
以前写过一个自动存档脚本,这种脚本的套路是,点击后不进入Scene_Save,直接操作DataManager存档。读档也一样。
另外,如果要调整存档的内容的话,VA也提供了方法。比如:
[pre lang="ruby"]
class << DataManager
#--------------------------------------------------------------------------
# ● 生成存档内容
#--------------------------------------------------------------------------
alias orig_make_save_contents make_save_contents
def make_save_contents
orig_make_save_contents
contents[:something] = $game_something
end
#--------------------------------------------------------------------------
# ● 展开存档内容
#--------------------------------------------------------------------------
alias orig_extract_save_contents extract_save_contents
def extract_save_contents(contents)
orig_extract_save_contents(contents)
$game_something = contents[:something]
end
end[/pre]
这两个方法用于生成和获取存档的具体内容(contents)。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X5.0