Advertisement
Cryranos

RGSS3: Quicksave

Jul 6th, 2012
1,783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.13 KB | None | 0 0
  1. #===============================================================================
  2. # RGSS3: Quicksave v1.3.1
  3. #===============================================================================
  4. # by Cryranos/Metatron
  5. #===============================================================================
  6. # Instructions:  Paste In the Materials section.  Edit Module if desired.
  7. #===============================================================================
  8. # This script allows the player to quickly save and quit the game.  Upon
  9. # reopening the game, the player will be prompted to load the game.  If it is
  10. # loaded or declined, the quicksave file will be deleted.
  11. #===============================================================================
  12. # Compatibility:  This script will not work with any script that edits
  13. # Datamanager.first_scene_class.
  14. #===============================================================================
  15. $imported = {} if $imported.nil?
  16. $imported["CRY_Quicksave"] = true
  17.  
  18. module Cry
  19.   module Quicksave
  20.     QSFile  = "Save.qsav"  # Filename for the quicksave.
  21.     QSDcty  = "System"    # Directory in which the quicksave is found.  Enter
  22.     # nil if you want it saved to the game's parent directory.
  23.     MenuOp  = true         # Add a quicksave command to the menu?
  24.     QSVNam  = "Quicksave"  # This is what the menu command will show up as.
  25.  
  26.     # These are the Quicksave help and the Quickload help.  Insert the second
  27.     # line with \n.
  28.     QSVMess  = "Would you like to save and quit?\nYour save will be deleted upon resuming."
  29.     QSVLoad  = "Would you like to load your quicksave?\nPress cancel to close the game."
  30.  
  31.     # These are for those who wish to bind the quicksave function to a key
  32.     # rather than to the menu.
  33.     UseKey   = false
  34.     QSVKey   = Input::F5
  35.   end
  36. end
  37.  
  38. module DataManager
  39.   def self.quicksave_file_exists?
  40.     if Cry::Quicksave::QSDcty == nil
  41.       !Dir.glob(Cry::Quicksave::QSFile).empty?
  42.     else
  43.       !Dir.glob(Cry::Quicksave::QSDcty + "/" + Cry::Quicksave::QSFile).empty?
  44.     end
  45.   end
  46.   def self.make_quicksave_filename
  47.     if Cry::Quicksave::QSDcty == nil
  48.       sprintf(Cry::Quicksave::QSFile)
  49.     else
  50.       sprintf(Cry::Quicksave::QSDcty + "/" + Cry::Quicksave::QSFile)
  51.     end
  52.   end
  53.   def self.quicksave_game
  54.     self.quicksave_game_without_rescue
  55.   end
  56.   def self.quicksave_game_without_rescue
  57.     File.open(make_quicksave_filename, "wb") do |file|
  58.       $game_system.on_before_save
  59.       Marshal.dump(make_save_header, file)
  60.       Marshal.dump(make_save_contents, file)
  61.     end
  62.   end
  63.   def self.quickload_game
  64.     self.load_quicksave_without_rescue
  65.     self.dispose_quicksave
  66.   end
  67.   def self.load_quicksave_without_rescue
  68.     File.open(make_quicksave_filename, "rb") do |file|
  69.       Marshal.load(file)
  70.       extract_save_contents(Marshal.load(file))
  71.       reload_map_if_updated
  72.     end
  73.   end
  74.   def self.dispose_quicksave
  75.     File.delete(make_quicksave_filename) rescue nil
  76.   end
  77. end
  78.  
  79. module SceneManager
  80.   def self.first_scene_class
  81.     if $BTEST
  82.       Scene_Battle
  83.     elsif DataManager.quicksave_file_exists?
  84.       Scene_QuickLoadTitle
  85.     else
  86.       Scene_Title
  87.     end
  88.   end
  89. end
  90.  
  91. if Cry::Quicksave::UseKey
  92. class Game_Player < Game_Character  
  93.   alias quicksave_update update
  94.   def update
  95.     quicksave_update
  96.     if Input.trigger?(Cry::Quicksave::QSVKey)
  97.       SceneManager.call(Scene_Quicksave)
  98.     end
  99.   end
  100. end
  101. end
  102.  
  103. class Window_QuicksaveCommand < Window_Command
  104.   def initialize
  105.     super(0, 0)
  106.     update_placement
  107.   end
  108.   def window_width
  109.     return 160
  110.   end
  111.   def update_placement
  112.     self.x = (Graphics.width - width) / 2
  113.     self.y = (Graphics.height * 1.6 - height) / 2
  114.   end
  115.   def make_command_list
  116.     add_command("Yes", :confirm)
  117.     add_command("No", :decline)
  118.   end
  119. end
  120.  
  121. class Scene_Quicksave < Scene_MenuBase
  122.   def start
  123.     super
  124.     create_command_window
  125.     create_help_window
  126.   end
  127.   def help_window_text
  128.     Cry::Quicksave::QSVMess
  129.   end
  130.   def create_command_window
  131.     @command_window = Window_QuicksaveCommand.new
  132.     @command_window.set_handler(:confirm,      method(:command_quicksave))
  133.     @command_window.set_handler(:decline,     method(:command_decline))
  134.     @command_window.set_handler(:cancel,    method(:return_scene))
  135.   end
  136.  
  137.   def create_help_window
  138.     @help_window = Window_Help.new(2)
  139.     @help_window.set_text(help_window_text)
  140.   end
  141.   def command_quicksave
  142.     DataManager.quicksave_game
  143.     fadeout_all
  144.     SceneManager.exit
  145.   end
  146.   def command_decline
  147.     SceneManager.return
  148.   end
  149.   def return_scene
  150.     SceneManager.return
  151.   end
  152. end
  153.  
  154. class Scene_QuickLoadTitle < Scene_Title
  155.   def start
  156.     super
  157.     SceneManager.clear
  158.     Graphics.freeze
  159.     create_background
  160.     create_foreground
  161.     create_command_window
  162.     play_title_music
  163.     create_help_window
  164.   end
  165.   def help_window_text
  166.     Cry::Quicksave::QSVLoad
  167.   end
  168.   def create_command_window
  169.     @command_window = Window_QuicksaveCommand.new
  170.     @command_window.set_handler(:confirm,      method(:command_quickload))
  171.     @command_window.set_handler(:decline,     method(:command_decline))
  172.     @command_window.set_handler(:cancel,    method(:return_scene))
  173.   end
  174.   def create_help_window
  175.     @help_window = Window_Help.new(2)
  176.     @help_window.set_text(help_window_text)
  177.   end
  178.   def command_quickload
  179.     close_command_window
  180.     DataManager.quickload_game
  181.     Sound.play_load
  182.     fadeout_all
  183.     $game_system.on_after_load
  184.     SceneManager.goto(Scene_Map)
  185.   end
  186.   def command_decline
  187.     DataManager.dispose_quicksave
  188.     SceneManager.goto(Scene_Title)
  189.   end
  190.   def return_scene
  191.     fadeout_all
  192.     SceneManager.exit
  193.   end
  194. end
  195.  
  196. if Cry::Quicksave::MenuOp
  197. class Window_MenuCommand
  198.   alias add_qsv_command add_save_command
  199.   def add_save_command
  200.     add_qsv_command
  201.     add_command(Cry::Quicksave::QSVNam, :qsav)
  202.   end
  203. end
  204.  
  205. class Scene_Menu
  206.   alias add_qsv_to_commands create_command_window
  207.   def create_command_window
  208.     add_qsv_to_commands
  209.     @command_window.set_handler(:qsav,      method(:command_quicksave))    
  210.   end  
  211.   def command_quicksave
  212.     SceneManager.call(Scene_Quicksave)
  213.   end
  214. end
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement