TheSixth

Quick Save/Load Feature

Jan 23rd, 2021 (edited)
1,360
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. - Quick Save/Load Feature v1.0
  3. - Made by: Sixth
  4.  
  5. - Description:
  6. Just a basic quick save/load function for your game.
  7. Can enable/disable this feature during the game with a switch.
  8. Can setup the keys used for quick save/load.
  9.  
  10. - Script calls:
  11. To manually save/load the game with the new methods, use these script calls:
  12.  
  13.   DataManager.quick_save
  14.   DataManager.quick_load
  15.  
  16. - Installation:
  17. Place it between Materials and Main!
  18.  
  19. - Terms of use:
  20. Credit me (Sixth) in your game, pretty please! :P
  21.  
  22. =end
  23.  
  24. module QSaveLoad
  25.   # Settings:
  26.   Data = {
  27.     :index   => 0,   # File index for quick save (0 = 1st slot, 1 = 2nd, etc)
  28.     :disable => 0,   # Disable switch ID (0 = always enabled)
  29.     :save    => :F7, # Key for quick save (nil = disabled)
  30.     :load    => :F8, # Key for quick load (nil = disabled)
  31.   }
  32.  
  33. end
  34.  
  35. # No setting here anymore, touchy-touchy disabled! o.o
  36.  
  37. module DataManager
  38.  
  39.   def self.quick_save
  40.     begin
  41.       quick_save_game_without_rescue
  42.     rescue
  43.       File.delete(make_filename(QSaveLoad::Data[:index])) rescue nil
  44.       false
  45.     end
  46.   end
  47.  
  48.   def self.quick_load(reload_map = true)
  49.     v = quick_load_game_without_rescue rescue false
  50.     if v == true && reload_map
  51.       SceneManager.scene.fadeout_all
  52.       $game_system.on_after_load
  53.       SceneManager.goto(Scene_Map)
  54.     end
  55.     return v
  56.   end
  57.  
  58.   def self.quick_save_game_without_rescue
  59.     File.open(make_filename(QSaveLoad::Data[:index]), "wb") do |file|
  60.       $game_system.on_before_save
  61.       Marshal.dump(make_save_header, file)
  62.       Marshal.dump(make_save_contents, file)
  63.       @last_savefile_index = 0
  64.     end
  65.     return true
  66.   end
  67.  
  68.   def self.quick_load_game_without_rescue
  69.     File.open(make_filename(QSaveLoad::Data[:index]), "rb") do |file|
  70.       Marshal.load(file)
  71.       extract_save_contents(Marshal.load(file))
  72.       reload_map_if_updated
  73.       @last_savefile_index = 0
  74.     end
  75.     return true
  76.   end
  77.  
  78. end
  79.  
  80. class Scene_Map < Scene_Base
  81.  
  82.   alias add_q_saveload8826 update
  83.   def update
  84.     add_q_saveload8826
  85.     upd_qsaveload unless $game_switches[QSaveLoad::Data[:disable]]
  86.   end
  87.  
  88.   def upd_qsaveload
  89.     if Input.trigger?(QSaveLoad::Data[:save])
  90.       DataManager.quick_save
  91.     elsif Input.trigger?(QSaveLoad::Data[:load])
  92.       DataManager.quick_load
  93.     end
  94.   end
  95.  
  96. end
  97.  
  98. # End of script.
RAW Paste Data