Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #== Szyu Scripts presents =====================================================
- # * Szyu Scripts' Autosave
- # Version 1.0
- # by Szyu
- #
- #== Download ==================================================================
- # * pastebin:
- # http://adf.ly/4920670/autosave
- #
- #== About =====================================================================
- # * This script will keep track of the time played and save your game
- # automatically in custom defined intervals. You can also force an autosave or
- # load an autosaved game from the title screen.
- #
- #== How to Use ================================================================
- # * All customizable options are kept in the module "SZS_Autosave" with their
- # representive functionality.
- #
- # * To force an autosave, use a script call with following line:
- # DataManager.autosave_game
- #
- # * To load the autosaved file, use a script call with following line:
- # DataManager.load_autosave
- #
- #== Terms of Use ==============================================================
- # * You are free to use this script for commercial and non-commercial projects.
- # However I'd like you to inform me of the projects you are planning to use it
- # in, so I can keep track of where my scripts are used.
- #
- #== Import ====================================================================
- $imported = {} if $imported.nil?
- $imported["SZ-AUTOSAVE"] = true
- #==============================================================================
- module SZS_Autosave
- # Name of autosave file
- Filename = "Autosave"
- # Interval in minutes used for autosaves
- Interval = 10
- # Term used in Scene_Title
- Term = "Autoload"
- # Define, if this script automatically saves the game
- Enabled = true
- end
- #==============================================================================
- # ** DataManager
- #==============================================================================
- class << DataManager
- #--------------------------------------------------------------------------
- # * Execute Autosave
- #--------------------------------------------------------------------------
- def autosave_game
- begin
- autosave_game_without_rescue
- rescue
- delete_temp_autosave_file
- false
- end
- apply_autosave
- end
- #--------------------------------------------------------------------------
- # * Execute Load Autosave
- #--------------------------------------------------------------------------
- def load_autosave
- load_autosave_without_rescue rescue false
- end
- #--------------------------------------------------------------------------
- # * Load Save Header
- #--------------------------------------------------------------------------
- def load_autosave_header
- load_autosave_header_without_rescue rescue nil
- end
- #--------------------------------------------------------------------------
- # * Execute Save (No Exception Processing)
- #--------------------------------------------------------------------------
- def autosave_game_without_rescue
- File.open(sprintf("%s.tmp", SZS_Autosave::Filename), "wb") do |file|
- $game_system.on_before_save
- Marshal.dump(make_save_header, file)
- Marshal.dump(make_save_contents, file)
- end
- return true
- end
- #--------------------------------------------------------------------------
- # * Execute Load (No Exception Processing)
- #--------------------------------------------------------------------------
- def load_autosave_without_rescue
- File.open(sprintf("%s.rvdata2", SZS_Autosave::Filename), "rb") do |file|
- Marshal.load(file)
- extract_save_contents(Marshal.load(file))
- reload_map_if_updated
- end
- return true
- end
- #--------------------------------------------------------------------------
- # * Load Save Header (No Exception Processing)
- #--------------------------------------------------------------------------
- def load_autosave_header_without_rescue
- File.open(sprintf("%s.rvdata2", SZS_Autosave::Filename), "rb") do |file|
- return Marshal.load(file)
- end
- return nil
- end
- #--------------------------------------------------------------------------
- # * Delete Save File
- #--------------------------------------------------------------------------
- def delete_temp_autosave_file
- File.delete(sprintf("%s.tmp", SZS_Autosave::Filename)) rescue nil
- end
- #--------------------------------------------------------------------------
- # * Apply temporary Autosave
- #--------------------------------------------------------------------------
- def apply_autosave
- File.rename(sprintf("%s.tmp", SZS_Autosave::Filename),
- sprintf("%s.rvdata2", SZS_Autosave::Filename)) rescue false
- end
- #--------------------------------------------------------------------------
- # * Determine Existence of Autosave File
- #--------------------------------------------------------------------------
- def autosave_file_exists?
- !Dir.glob(sprintf("%s.rvdata2", SZS_Autosave::Filename)).empty?
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs the map screen processing.
- #==============================================================================
- class Scene_Map
- alias :szs_asave_update :update
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- szs_asave_update
- update_autosave if SZS_Autosave::Enabled && SZS_Autosave::Interval > 0
- end
- #--------------------------------------------------------------------------
- # * Update Autosave
- #--------------------------------------------------------------------------
- def update_autosave
- min = $game_system.playtime / 60.0
- if min-$game_system.last_autosave >= SZS_Autosave::Interval
- DataManager.autosave_game
- $game_system.last_autosave = min
- end
- end
- end
- #==============================================================================
- # ** Game_System
- #------------------------------------------------------------------------------
- # This class handles system data. It saves the disable state of saving and
- # menus. Instances of this class are referenced by $game_system.
- #==============================================================================
- class Game_System
- alias :szs_asave_initialize :initialize
- attr_accessor :last_autosave
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize
- szs_asave_initialize
- @last_autosave = 0
- end
- end
- #==============================================================================
- # ** Scene_Title
- #------------------------------------------------------------------------------
- # This class performs the title screen processing.
- #==============================================================================
- class Scene_Title < Scene_Base
- alias :szs_asave_create_command_window :create_command_window
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- def create_command_window
- szs_asave_create_command_window
- @command_window.set_handler(:autosave, method(:command_load_autosave))
- end
- #--------------------------------------------------------------------------
- # * Load Autosave
- #--------------------------------------------------------------------------
- def command_load_autosave
- if DataManager.load_autosave
- on_load_success
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # * Processing When Load Is Successful
- #--------------------------------------------------------------------------
- def on_load_success
- Sound.play_load
- fadeout_all
- $game_system.on_after_load
- SceneManager.goto(Scene_Map)
- end
- end
- #==============================================================================
- # ** Window_TitleCommand
- #------------------------------------------------------------------------------
- # This window is for selecting New Game/Continue on the title screen.
- #==============================================================================
- class Window_TitleCommand < Window_Command
- alias :szs_asave_make_command_list :make_command_list
- alias :sts_asave_process_ok :process_ok
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_command(SZS_Autosave::Term, :autosave) if autosave_enabled
- szs_asave_make_command_list
- end
- #--------------------------------------------------------------------------
- # * Checks if an autosave file exists
- #--------------------------------------------------------------------------
- def autosave_enabled
- DataManager.autosave_file_exists?
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- if current_symbol == :autosave
- Input.update
- call_ok_handler
- else
- sts_asave_process_ok
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment