The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: DoctorTodd on June 22, 2012, 07:17:57 AM

Title: DT's Autosave
Post by: DoctorTodd on June 22, 2012, 07:17:57 AM
DT's Autosave
Version: 1.0.0
Author: DoctorTodd
Date: 6/22/2012

Version History



Planned Future Versions


Description


Saves the game when transferring the map, before battle, and opening the menu (all optional).

Features



Instructions

Paste above main.

Script


Code: [Select]
#===============================================================================
#
# DT's Autosave
# Author: DoctorTodd
# Date (06/22/2012)
# Edited by: ArkLennard
# Date (01/13/2013)
# Version: (1.0.0) (VXA)
# Level: (Simple)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#
#===============================================================================
#
# Description: Saves the game when transferring the map, before battle,
# and opening the menu (all optional).
#
# Credits: Me (DoctorTodd), ArkLennard
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 37 and ends on 50.
#
#===============================================================================
module ToddAutoSaveAce
     
      #Max files (without autosave).
      MAXFILES = 16
     
      #Autosave file name.
      AUTOSAVEFILENAME = "Autosave"
     
      #Switch to activate autosave before battle?
      AUTOSAVEBB = 1
     
      #Switch to activate autosave when menu opened?
      AUTOSAVEM =  2
     
      #Switch to activate autosave when changing map?
      AUTOSAVETM =  3
     
      #Variable ID that contains the number where the sutosave file will be saved.
      VARIABLE = 1
     
    end

#==============================================================================
# ** Autosave
#------------------------------------------------------------------------------
# This module contains the autosave method. This allows you to use the
# "Autosave.call" ans "Autosave.load" commands.
#==============================================================================

module Autosave

  #--------------------------------------------------------------------------
  # * Save header writer
  #--------------------------------------------------------------------------
  def self.make_save_header
    header = {}
    header[:characters] = $game_party.characters_for_savefile
    header[:playtime_s] = $game_system.playtime_s
    header
  end
  #--------------------------------------------------------------------------
  # * Save contents writer
  #--------------------------------------------------------------------------
  def self.make_save_contents
    contents = {}
    contents[:system]        = $game_system
    contents[:timer]         = $game_timer
    contents[:message]       = $game_message
    contents[:switches]      = $game_switches
    contents[:variables]     = $game_variables
    contents[:self_switches] = $game_self_switches
    contents[:actors]        = $game_actors
    contents[:party]         = $game_party
    contents[:troop]         = $game_troop
    contents[:map]           = $game_map
    contents[:player]        = $game_player
    contents
  end
 
  #--------------------------------------------------------------------------
  # * Save contents extractor
  #--------------------------------------------------------------------------
  def self.extract_save_contents(contents)
    $game_system        = contents[:system]
    $game_timer         = contents[:timer]
    $game_message       = contents[:message]
    $game_switches      = contents[:switches]
    $game_variables     = contents[:variables]
    $game_self_switches = contents[:self_switches]
    $game_actors        = contents[:actors]
    $game_party         = contents[:party]
    $game_troop         = contents[:troop]
    $game_map           = contents[:map]
    $game_player        = contents[:player]
  end
 
  #--------------------------------------------------------------------------
  # * Map reloader
  #--------------------------------------------------------------------------
  def self.reload_map_if_updated
    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)
      $game_player.make_encounter_count
    end
  end
 
  #--------------------------------------------------------------------------
  # * Total fade out
  #     time : duration (milliseconds)
  #--------------------------------------------------------------------------
  def self.fadeout_all(time = 1000)
    RPG::BGM.fade(time)
    RPG::BGS.fade(time)
    RPG::ME.fade(time)
    Graphics.fadeout(time * Graphics.frame_rate / 1000)
    RPG::BGM.stop
    RPG::BGS.stop
    RPG::ME.stop
  end
 
  #--------------------------------------------------------------------------
  # * Call method
  #--------------------------------------------------------------------------
 
  def self.call
  File.open('Autosave.rvdata2', "wb") do |file|
      $game_system.on_before_save
      Marshal.dump(make_save_header, file)
      Marshal.dump(make_save_contents, file)
    end
    end
         
  def self.load
    fadeout_all
    File.open('Autosave.rvdata2', "rb") do |file|
    Marshal.load(file)
    extract_save_contents(Marshal.load(file))
    reload_map_if_updated
    end
    $game_system.on_after_load
    SceneManager.goto(Scene_Map)       
    end

 
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================

module DataManager
  #--------------------------------------------------------------------------
  # * Maximum Number of Save Files
  #--------------------------------------------------------------------------
  def self.savefile_max
    return ToddAutoSaveAce::MAXFILES + 1
  end 
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Preprocessing for Battle Screen Transition
  #--------------------------------------------------------------------------
  def pre_battle_scene
    Graphics.update
    Graphics.freeze
    @spriteset.dispose_characters
    BattleManager.save_bgm_and_bgs
    BattleManager.play_battle_bgm
    Sound.play_battle_start
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEBB] == true
end
  #--------------------------------------------------------------------------
  # * Call Menu Screen
  #--------------------------------------------------------------------------
  def call_menu
    Sound.play_ok
    SceneManager.call(Scene_Menu)
    Window_MenuCommand::init_command_position
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEM] == true
end
  #--------------------------------------------------------------------------
  # * Preprocessing for Transferring Player
  #--------------------------------------------------------------------------
  def pre_transfer
    @map_name_window.close
    case $game_temp.fade_type
    when 0
      fadeout(fadeout_speed)
    when 1
      white_fadeout(fadeout_speed)
    end
  #--------------------------------------------------------------------------
  # * Post Processing for Transferring Player
  #--------------------------------------------------------------------------
  def post_transfer
    case $game_temp.fade_type
    when 0
      Graphics.wait(fadein_speed / 2)
      fadein(fadein_speed)
    when 1
      Graphics.wait(fadein_speed / 2)
      white_fadein(fadein_speed)
    end
    @map_name_window.open
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVETM] == true
  end
 end
end

Credit



Support


Post here for quickest support, or send an email to Todd@beacongames.com.

Known Compatibility Issues

None known of.

Author's Notes


I hope nothing explodes.

Restrictions

Check the header of the script.
Title: Re: DT's Autosave
Post by: pacdiggity on June 22, 2012, 07:24:47 AM
GOOD IDEA.

What would be cool is adding in commands that could alter the settings in-game (as an option to the player), and eventually implementing those commands into a menu.
Title: Re: DT's Autosave
Post by: DoctorTodd on June 22, 2012, 07:26:58 AM
Thanks, I'll look into that after I complete the next version.
Title: Re: DT's Autosave
Post by: Wiimeiser on June 22, 2012, 07:44:35 AM
Maybe make it activated by a switch. That way it'd work with Yanfly's System Options
Title: Re: DT's Autosave
Post by: DoctorTodd on June 22, 2012, 07:47:46 AM
I was actually thinking that when I posted the script.  :lol:
I'll remove the true and false options and use switches instead on my next version.
Title: Re: DT's Autosave
Post by: DoctorTodd on June 22, 2012, 09:21:31 PM
Here's a version that uses switches. I'll upload a new version when I figure out how to change the autosave file to say autosave, I still have to figure out how to do that.
Code: [Select]
#===============================================================================
#
# DT's Autosave
# Author: DoctorTodd
# Date (06/22/2012)
# Version: (1.0.0) (VXA)
# Level: (Simple)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#
#===============================================================================
#
# Description: Saves the game when transferring the map, before battle,
# and opening the menu (all optional).
#
# Credits: Me (DoctorTodd)
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 37 and ends on 50.
#
#===============================================================================
module ToddAutoSaveAce
     
      #Max files (without autosave).
      MAXFILES = 16
     
      #Autosave file name.
      AUTOSAVEFILENAME = "Autosave"
     
      #Switch to activate autosave before battle?
      AUTOSAVEBB = 1
     
      #Switch to activate autosave when menu opened?
      AUTOSAVEM =  2
     
      #Switch to activate autosave when changing map?
      AUTOSAVETM =  3
     
      #Variable ID that contains the number where the sutosave file will be saved.
      VARIABLE = 1
     
    end

#==============================================================================
# ** Autosave
#------------------------------------------------------------------------------
# This module contains the autosave method. This is allows you to use the
# "Autosave.call" command.
#==============================================================================

module Autosave
  #--------------------------------------------------------------------------
  # * Call method
  #--------------------------------------------------------------------------
  def self.call
  DataManager.save_game_without_rescue($game_variables[ToddAutoSaveAce::VARIABLE])
end
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================

module DataManager
  #--------------------------------------------------------------------------
  # * Maximum Number of Save Files
  #--------------------------------------------------------------------------
  def self.savefile_max
    return ToddAutoSaveAce::MAXFILES + 1
  end 
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Preprocessing for Battle Screen Transition
  #--------------------------------------------------------------------------
  def pre_battle_scene
    Graphics.update
    Graphics.freeze
    @spriteset.dispose_characters
    BattleManager.save_bgm_and_bgs
    BattleManager.play_battle_bgm
    Sound.play_battle_start
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEBB] == true
end
  #--------------------------------------------------------------------------
  # * Call Menu Screen
  #--------------------------------------------------------------------------
  def call_menu
    Sound.play_ok
    SceneManager.call(Scene_Menu)
    Window_MenuCommand::init_command_position
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEM] == true
end
  #--------------------------------------------------------------------------
  # * Preprocessing for Transferring Player
  #--------------------------------------------------------------------------
  def pre_transfer
    @map_name_window.close
    case $game_temp.fade_type
    when 0
      fadeout(fadeout_speed)
    when 1
      white_fadeout(fadeout_speed)
    end
  #--------------------------------------------------------------------------
  # * Post Processing for Transferring Player
  #--------------------------------------------------------------------------
  def post_transfer
    case $game_temp.fade_type
    when 0
      Graphics.wait(fadein_speed / 2)
      fadein(fadein_speed)
    when 1
      Graphics.wait(fadein_speed / 2)
      white_fadein(fadein_speed)
    end
    @map_name_window.open
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVETM] == true
  end
 end
end
Title: Re: DT's Autosave
Post by: ArkLennard on January 14, 2013, 12:55:36 AM
I think you should like it:

Code: [Select]
#===============================================================================
#
# DT's Autosave
# Author: DoctorTodd
# Date (06/22/2012)
# Edited by: ArkLennard
# Date (01/13/2013)
# Version: (1.0.0) (VXA)
# Level: (Simple)
# Email: Todd@beacongames.com
#
#===============================================================================
#
# NOTES: 1)This script will only work with ace.
#
#===============================================================================
#
# Description: Saves the game when transferring the map, before battle,
# and opening the menu (all optional).
#
# Credits: Me (DoctorTodd)
#
#===============================================================================
#
# Instructions
# Paste above main.
#
#===============================================================================
#
# Free for any use as long as I'm credited.
#
#===============================================================================
#
# Editing begins 37 and ends on 50.
#
#===============================================================================
module ToddAutoSaveAce
     
      #Max files (without autosave).
      MAXFILES = 16
     
      #Autosave file name.
      AUTOSAVEFILENAME = "Autosave"
     
      #Switch to activate autosave before battle?
      AUTOSAVEBB = 1
     
      #Switch to activate autosave when menu opened?
      AUTOSAVEM =  2
     
      #Switch to activate autosave when changing map?
      AUTOSAVETM =  3
     
      #Variable ID that contains the number where the sutosave file will be saved.
      VARIABLE = 1
     
    end

#==============================================================================
# ** Autosave
#------------------------------------------------------------------------------
# This module contains the autosave method. This allows you to use the
# "Autosave.call" ans "Autosave.load" commands.
#==============================================================================

module Autosave

  #--------------------------------------------------------------------------
  # * Save header writer
  #--------------------------------------------------------------------------
  def self.make_save_header
    header = {}
    header[:characters] = $game_party.characters_for_savefile
    header[:playtime_s] = $game_system.playtime_s
    header
  end
  #--------------------------------------------------------------------------
  # * Save contents writer
  #--------------------------------------------------------------------------
  def self.make_save_contents
    contents = {}
    contents[:system]        = $game_system
    contents[:timer]         = $game_timer
    contents[:message]       = $game_message
    contents[:switches]      = $game_switches
    contents[:variables]     = $game_variables
    contents[:self_switches] = $game_self_switches
    contents[:actors]        = $game_actors
    contents[:party]         = $game_party
    contents[:troop]         = $game_troop
    contents[:map]           = $game_map
    contents[:player]        = $game_player
    contents
  end
 
  #--------------------------------------------------------------------------
  # * Save contents extractor
  #--------------------------------------------------------------------------
  def self.extract_save_contents(contents)
    $game_system        = contents[:system]
    $game_timer         = contents[:timer]
    $game_message       = contents[:message]
    $game_switches      = contents[:switches]
    $game_variables     = contents[:variables]
    $game_self_switches = contents[:self_switches]
    $game_actors        = contents[:actors]
    $game_party         = contents[:party]
    $game_troop         = contents[:troop]
    $game_map           = contents[:map]
    $game_player        = contents[:player]
  end
 
  #--------------------------------------------------------------------------
  # * Map reloader
  #--------------------------------------------------------------------------
  def self.reload_map_if_updated
    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)
      $game_player.make_encounter_count
    end
  end
 
  #--------------------------------------------------------------------------
  # * Total fade out
  #     time : duration (milliseconds)
  #--------------------------------------------------------------------------
  def self.fadeout_all(time = 1000)
    RPG::BGM.fade(time)
    RPG::BGS.fade(time)
    RPG::ME.fade(time)
    Graphics.fadeout(time * Graphics.frame_rate / 1000)
    RPG::BGM.stop
    RPG::BGS.stop
    RPG::ME.stop
  end
 
  #--------------------------------------------------------------------------
  # * Call method
  #--------------------------------------------------------------------------
 
  def self.call
  File.open('Autosave.rvdata2', "wb") do |file|
      $game_system.on_before_save
      Marshal.dump(make_save_header, file)
      Marshal.dump(make_save_contents, file)
    end
    end
         
  def self.load
    fadeout_all
    File.open('Autosave.rvdata2', "rb") do |file|
    Marshal.load(file)
    extract_save_contents(Marshal.load(file))
    reload_map_if_updated
    end
    $game_system.on_after_load
    SceneManager.goto(Scene_Map)       
    end

 
end
#==============================================================================
# ** DataManager
#------------------------------------------------------------------------------
#  This module manages the database and game objects. Almost all of the
# global variables used by the game are initialized by this module.
#==============================================================================

module DataManager
  #--------------------------------------------------------------------------
  # * Maximum Number of Save Files
  #--------------------------------------------------------------------------
  def self.savefile_max
    return ToddAutoSaveAce::MAXFILES + 1
  end 
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Preprocessing for Battle Screen Transition
  #--------------------------------------------------------------------------
  def pre_battle_scene
    Graphics.update
    Graphics.freeze
    @spriteset.dispose_characters
    BattleManager.save_bgm_and_bgs
    BattleManager.play_battle_bgm
    Sound.play_battle_start
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEBB] == true
end
  #--------------------------------------------------------------------------
  # * Call Menu Screen
  #--------------------------------------------------------------------------
  def call_menu
    Sound.play_ok
    SceneManager.call(Scene_Menu)
    Window_MenuCommand::init_command_position
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVEM] == true
end
  #--------------------------------------------------------------------------
  # * Preprocessing for Transferring Player
  #--------------------------------------------------------------------------
  def pre_transfer
    @map_name_window.close
    case $game_temp.fade_type
    when 0
      fadeout(fadeout_speed)
    when 1
      white_fadeout(fadeout_speed)
    end
  #--------------------------------------------------------------------------
  # * Post Processing for Transferring Player
  #--------------------------------------------------------------------------
  def post_transfer
    case $game_temp.fade_type
    when 0
      Graphics.wait(fadein_speed / 2)
      fadein(fadein_speed)
    when 1
      Graphics.wait(fadein_speed / 2)
      white_fadein(fadein_speed)
    end
    @map_name_window.open
  Autosave.call if $game_switches[ToddAutoSaveAce::AUTOSAVETM] == true
  end
 end
end
Title: Re: DT's Autosave
Post by: DoctorTodd on January 14, 2013, 01:06:08 AM
Thanks, it looks good. I added you to the credits.