Jump to content
roninator2

Auto Save / Auto Load

Recommended Posts

Auto Save / Auto Load v1.10
by Roninator2


Introduction
A script requested to perform auto save on specific maps and auto load

Features
- Decide to use switch to control auto save or not
- Specify number of save slots used
- Specify if you want auto load from the start of the game of when pressing continue on the title screen
- add in what maps you want auto save to work on
- must have only 1 save slot specified for auto load to work.
- if using more than 1 save file then saving will use the last save file used.


How to Use
Put below Materials

Images
I don't think any is required

Script

Spoiler

# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Auto Save / Load             ║  Version: 1.10     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function: Requested by kiriyubel    ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Allows auto saving and auto loading ║    21 Jan 2021     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Requires: nil                                            ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Script provides auto save and auto load features         ║
# ║ Switch controls and specifically designed for a single   ║
# ║ save slot. Can be used for multiple save slots but the   ║
# ║ auto load and auto save will not work if                 ║
# ║ using more than 1 save slot.                             ║
# ║ Autosave is designed to work for specific maps.          ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║ 1.00 - 21 Jan 2021 - Initial publish                     ║
# ║ 1.10 - 06 Mar 2021 - Removed 1 slot restriction          ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all RPG Maker uses                              ║
# ╚══════════════════════════════════════════════════════════╝

module R2_AutoSave_AutoLoad
  Switch_Save = 6 # switch to enable auto save
  Use_switch = false # turns switch feature on if true
  
  Save_Maps = [1, 2] 
  # add as many maps as you want to use autosave feature with
  Save_Slots = 16
  # change the number for how many slot you wish to use.
  
  Auto_load = false
  # if true will load the saved game if there is only one save slot
  # without going to scene title
  Continue_load = true
  # if true this will load the save game when selecting continue
end

module DataManager
  def self.savefile_max
    return R2_AutoSave_AutoLoad::Save_Slots
  end
end

class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  alias r2_autostart_autoload start
  def start
    @saves = []
    @last = 0
    if DataManager.save_file_exists?
      for i in 0..DataManager.savefile_max
        i += 1
        if i > 9
          if !Dir.glob("Save#{i}.rvdata2").empty?
            i -= 1
            @saves << i
          end
        else
          if !Dir.glob("Save0#{i}.rvdata2").empty?
            i -= 1
            @saves << i
          end
        end
      end
      @last = @saves[0]
      @saves.each do |i|
        if DataManager.savefile_time_stamp(i) > DataManager.savefile_time_stamp(@last)
          @last = i
        end
      end
      if R2_AutoSave_AutoLoad::Auto_load
        super
        SceneManager.clear
        fadeout_all
        DataManager.load_game(@last)
        SceneManager.goto(Scene_Map)
      else
        r2_autostart_autoload
      end
    else
      r2_autostart_autoload
    end
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  alias r2_autosave_load_terminate  terminate
  def terminate
    if R2_AutoSave_AutoLoad::Auto_load == true
      if DataManager.save_file_exists?
        super
      else
        r2_autosave_load_terminate
      end
    else
      r2_autosave_load_terminate
    end
  end
  #--------------------------------------------------------------------------
  # * [Continue] Command
  #--------------------------------------------------------------------------
  def command_continue
    if R2_AutoSave_AutoLoad::Continue_load == true
      DataManager.load_game(@last)
      fadeout_all
      RPG::BGM.fade(30)
      $game_map.autoplay
      SceneManager.goto(Scene_Map)
    else
      close_command_window
      SceneManager.call(Scene_Load)
    end
  end
  
end

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Post Processing for Transferring Player
  #--------------------------------------------------------------------------
  alias r2_autosave_post_transfer   post_transfer
  def post_transfer
    r2_autosave_post_transfer
    @saves = []
    @last = 0
    if DataManager.save_file_exists?
      for i in 0..DataManager.savefile_max
        i += 1
        if i > 9
          if !Dir.glob("Save#{i}.rvdata2").empty?
            i -= 1
            @saves << i
          end
        else
          if !Dir.glob("Save0#{i}.rvdata2").empty?
            i -= 1
            @saves << i
          end
        end
      end
      @last = @saves[0]
      @saves.each do |i|
        if DataManager.savefile_time_stamp(i) > DataManager.savefile_time_stamp(@last)
          @last = i
        end
      end
    end
    if R2_AutoSave_AutoLoad::Use_switch == true && 
      $game_switches[R2_AutoSave_AutoLoad::Switch_Save] == true
      if R2_AutoSave_AutoLoad::Save_Maps.include?($game_map.map_id)
        DataManager.save_game(@last)
      end
    elsif R2_AutoSave_AutoLoad::Save_Maps.include?($game_map.map_id) && 
      R2_AutoSave_AutoLoad::Use_switch == false
      DataManager.save_game(@last)
    end
  end
end

 


Credit and Thanks
- Roninator2

Terms of use
Free for all RPG Maker VX Ace uses

Edited by roninator2
updated script

Share this post


Link to post
Share on other sites

I'm just curious; what happens if one were to make it so that auto_load or continue_load were allowed even if there were more than one game save?
Would it try to load the data from all game saves?

Share this post


Link to post
Share on other sites
2 hours ago, PhoenixSoul said:

what happens if one were to make it so that auto_load or continue_load were allowed even if there were more than one game save?

If you specify more than 1 save slot then the script does very little.

The auto load and continue will only work if there is one save slot specified.

the only thing that works with more than one save slot is the saving, but that only saves to the last saved slot used.

Share this post


Link to post
Share on other sites
9 hours ago, PhoenixSoul said:

I guess loading the last savefile index would not work as intended

No. Think about you starting the game after having it off for 1 second - 200 years. when the game starts it would have no idea what savefile was used.

The script checks to see if a save file exists and (if used) will load that save file. But it does this because if there is only one then we can easily say what index position it is - 0.

To have it load a savefile when there are more than one, would have to reconfigure the script to check for file modification date and load the file index for that file with the newest date.

Not something I'm familiar with yet.

Share this post


Link to post
Share on other sites
On 3/1/2021 at 3:57 PM, roninator2 said:

To have it load a savefile when there are more than one, would have to reconfigure the script to check for file modification date and load the file index for that file with the newest date.

Hmmm...
Could this be done with custom data? Like say, using Aditkuzmiko's Custom Data script? To have it look for some specific dataset that is specific per file, or something like that? Eh, I'm just spitballing here, but, if anything helps, I'm trying. Heh-ha.

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/4/2021 at 2:21 PM, PhoenixSoul said:

I'm just spitballing here, but, if anything helps

No that's ok, I actually just discovered that there is a method for finding the last save file by time.

*EDIT

Script updated. Use as many save slots as you want.

When auto loading it will use the newest save file created.

Edited by roninator2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted