#==============================================================================#
# Single Save/Load V1.1 #
#------------------------------------------------------------------------------#
# by AABattery #
# 10/29/2011 #
# RPGMaker VX #
#------------------------------------------------------------------------------#
# This script will allow for only one save file. #
#==============================================================================#

module AAB
#==============================================================================#
# CONFIGUARTION SECTION #
#------------------------------------------------------------------------------#
# Edit this section to make it look how you want it to. #
#==============================================================================#

# This will show when the player saves their game
SAVE_MSG = "Your game has been saved!"
# This will show when the player loads their game
LOAD_MSG = "Your game has loaded!"
# Change this for the width, height, and position of the text window
X_POS = 130
Y_POS = 170
WIDTH = 300
HEIGHT = 60
# This effects the duration for the message window to stay on screen
WAIT_TIME = 100
# Change the name of the save file
SAVE_FILE = "Save"

#==============================================================================#
# END OF CONFIGUARTION SECTION #
#==============================================================================#
end

#==============================================================================#
# ** Scene_File #
#------------------------------------------------------------------------------#
# This class performs the save and load screen processing. #
#==============================================================================#

class Scene_File < Scene_Base
#--------------------------------------------------------------------------#
# * Object Initialization #
# saving : save flag (if false, load screen) #
# from_title : flag: it was called from "Continue" on the title screen #
# from_event : flag: it was called from the "Call Save Screen" event #
#--------------------------------------------------------------------------#
def initialize(saving, from_title, from_event)
@saving = saving
@from_title = from_title
@from_event = from_event
end
#--------------------------------------------------------------------------#
# * Start processing #
#--------------------------------------------------------------------------#
def start
super
create_menu_background
@msg_window = Window_Help.new
@msg_window.x = AAB::X_POS
@msg_window.width = AAB::WIDTH
@msg_window.y = AAB::Y_POS
@msg_window.height = AAB::HEIGHT
create_savefile
if @saving
@msg_window.set_text(AAB::SAVE_MSG,1)
do_save
else
@msg_window.set_text(AAB::LOAD_MSG,1)
do_load
end
end
#--------------------------------------------------------------------------#
# * Termination Processing #
#--------------------------------------------------------------------------#
def terminate
super
if @saving
Sound.play_save
else
Sound.play_load
end
Graphics.wait(AAB::WAIT_TIME)
dispose_menu_background
@msg_window.dispose
end
#--------------------------------------------------------------------------#
# * Return to Original Screen #
#--------------------------------------------------------------------------#
def return_scene
if @from_title
$scene = Scene_Title.new
elsif @from_event
$scene = Scene_Map.new
else
$scene = Scene_Menu.new(4)
end
end
#--------------------------------------------------------------------------#
# * Frame Update #
#--------------------------------------------------------------------------#
def update
super
update_menu_background
@msg_window.update
end
#--------------------------------------------------------------------------#
# * Create Save File Window #
#--------------------------------------------------------------------------#
def create_savefile
@savefile =
@savefile.push(SaveFile.new(make_filename))
@item_max = 1
end
#--------------------------------------------------------------------------#
# * Create Filename #
# file_index : save file index (0-3) #
#--------------------------------------------------------------------------#
def make_filename
return AAB::SAVE_FILE + ".rvdata"
end
#--------------------------------------------------------------------------#
# * Execute Save #
#--------------------------------------------------------------------------#
def do_save
file = File.open(@savefile.filename, "wb")
write_save_data(file)
file.close
Graphics.wait(20)
return_scene
end
#--------------------------------------------------------------------------#
# * Execute Load #
#--------------------------------------------------------------------------#
def do_load
file = File.open(@savefile.filename, "rb")
read_save_data(file)
file.close
$scene = Scene_Map.new
RPG::BGM.fade(1500)
Graphics.fadeout(50)
Graphics.wait(20)
end
#--------------------------------------------------------------------------#
# * Write Save Data #
# file : write file object (opened) #
#--------------------------------------------------------------------------#
def write_save_data(file)
characters =
for actor in $game_party.members
characters.push()
end
$game_system.save_count += 1
$game_system.version_id = $data_system.version_id
@last_bgm = RPG::BGM::last
@last_bgs = RPG::BGS::last
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
Marshal.dump(@last_bgm, file)
Marshal.dump(@last_bgs, file)
Marshal.dump($game_system, file)
Marshal.dump($game_message, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, 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
#--------------------------------------------------------------------------#
# * Read Save Data #
# file : file object for reading (opened) #
#--------------------------------------------------------------------------#
def read_save_data(file)
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
@last_bgm = Marshal.load(file)
@last_bgs = Marshal.load(file)
$game_system = Marshal.load(file)
$game_message = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
if $game_system.version_id != $data_system.version_id
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
end
end

#==============================================================================#
# ** Window_SaveFile #
#------------------------------------------------------------------------------#
# This window displays save files on the save and load screens. #
#==============================================================================#

class SaveFile
include AAB
#--------------------------------------------------------------------------#
# * Public Instance Variables #
#--------------------------------------------------------------------------#
attr_reader :filename # filename
attr_reader :file_exist # file existence flag
attr_reader :time_stamp # timestamp
attr_reader :selected # selected
#--------------------------------------------------------------------------#
# * Object Initialization #
# file_index : save file index (0-3) #
# filename : filename #
#--------------------------------------------------------------------------#
def initialize(filename)
@filename = filename
load_gamedata
end
#--------------------------------------------------------------------------#
# * Load Partial Game Data #
# By default, switches and variables are not used (for expansion use, #
# such as displaying place names) #
#--------------------------------------------------------------------------#
def load_gamedata
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
begin
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@last_bgm = Marshal.load(file)
@last_bgs = Marshal.load(file)
@game_system = Marshal.load(file)
@game_message = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
rescue
@file_exist = false
ensure
file.close
end
end
end
end