Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Fantasist on February 24, 2008, 05:02:29 am

Title: [XP] Temp Save v2.1
Post by: Fantasist on February 24, 2008, 05:02:29 am
Temp Save
Authors: Fantasist
Version: 2.1
Type: Save Feature
Key Term: Title / Save / Load / GameOver Add-on



Introduction

With this script, the 'Save' option in the menu will do a quick save and take you to the title screen. The next time you load, the quick save is loaded instead of letting the player choose from the save files. Once the quick save file is loaded, it is deleted.


Features




Screenshots

n/a


Demo

On demand.


Script

Place this script anywhere above "Main" and below "Scene_Load".
Spoiler: ShowHide

#==============================================================================
# ** Temp Save
#------------------------------------------------------------------------------
# by Fantasist
# Version: 2.1
# Date: 05-July-2009
#------------------------------------------------------------------------------
# Version History:
#
#   1.0 - First version for the default title and file scenes
#   1.1 - Improved coding
#   2.0 - Complete overhaul, greatly increased compatibility
#   2.1 - Removed obselete option, added prompt disable and fixed some bugs
#------------------------------------------------------------------------------
# Description:
#
#     With this script, the 'Save' option in the menu will do a quick save and
#   take you to the title screen. The next time you load, the quick save is
#   loaded instead of letting the playwer choose from the save files. Once the
#   quick save file is loaded, it is deleted.
#------------------------------------------------------------------------------
# Compatibility:
#
#     From version 2.0, it should be compatible with almost anything, including
#   exotic save systems, save scenes and even encryption systems.
#
#   For scripters: There is nothing like absolute compatibility, so this still
#   has it's limitations:
#    - The quick save procedure is only activated when Scene_Save is called
#      from Scene_Menu. You can change that by tinkering with
#      "@temp_save_active" in "Scene_Save" -> "initialize".
#    - This script assumes that you're using the Scene_File class for the
#      saving and loading.
#==============================================================================
# Instructions:
#
#    - Place this script anywhere above "Main" and below "Scene_Load".
#    - In Scene_Title, find the following lines or similar:
#
#          @continue_enabled = false
#          for i in 0..3
#            if FileTest.exist?("Save#{i+1}.rxdata")
#              @continue_enabled = true
#            end
#          end
#
#      Now add the following line right after the above code:
#
#          if FileTest.exist?(Scene_File::TEMP_SAVE_NAME)
#            @continue_enabled = true
#          end
#------------------------------------------------------------------------------
# Configuration:
#
#     Scroll down a bit and you'll see the configuration.
#
#   TEMP_SAVE_NAME: The name (and path if needed) for the temp save file.
#   TEMP_LOAD_TEXT: The message to be displayed when a temp save is loaded.
#   TEMP_SAVE_TEXT: The message to be displayed when asking for temp save
#                   confirmation.
#   DISABLE_PROMPT: If this is set to true, the prompt and confirmation windows
#                   will be disabled. (Please check Issues!)
#------------------------------------------------------------------------------
# Issues:
#
#     If DISABLE_PROMPT is activated, while loading or saving a quick-save,
#   there will be 2 sounds of button press instead of 1. Actually, it is the
#   sound of button press and the sound of saving and loading. Fixing this
#   means losing a lot of compatibility (since v2.0), so I have no intention
#   of doing that unless I get an idea which retains compatibility.
#------------------------------------------------------------------------------
# Credits and Thanks:
#
#   Fantasist, for making this script
#   dmoose for requesting this script
#   Hadeki for requesting the improvements
#------------------------------------------------------------------------------
# Notes:
#
#     If you have any problems, suggestions or comments, you can find me at:
#
#  - forum.chaos-project.com
#  - www.quantumcore.forumotion.com
#
#   Enjoy ^_^
#==============================================================================

#==============================================================================
# ** Scene_Load
#==============================================================================

class Scene_File 
 
  #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  # CONFIG START
  #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  TEMP_SAVE_NAME = 'Data/ScriptCache.rxdata'
  DISABLE_PROMPT = false
  TEMP_LOAD_TEXT = 'Quick load complete. Press Enter to continue.'
  TEMP_SAVE_TEXT = 'Do you want to quick save?'
  #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  # CONFIG END
  #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
  alias temp_save_main_hack main
  def main
    if $scene.is_a?(Scene_Load)
      if FileTest.exist?(TEMP_SAVE_NAME)
        main_quickload
      else
        temp_save_main_hack
      end
    elsif $scene.is_a?(Scene_Save)
      if @temp_save_active
        main_quicksave
      else
        temp_save_main_hack
      end
    end
  end
 
  def main_quickload
    unless DISABLE_PROMPT
      @prompt_window = Window_Prompt.new(TEMP_LOAD_TEXT)
      Graphics.transition
      loop do
        Graphics.update
        Input.update
        break if Input.trigger?(Input::C)
      end
      Graphics.freeze
      @prompt_window.dispose
    end
    load_quicksave_data # Load Data
    # Load Map
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    $game_map.update
    $scene = Scene_Map.new
  end
 
  def load_quicksave_data
    $game_temp = Game_Temp.new unless $game_temp
    $game_system.se_play($data_system.load_se)
    file = File.open(TEMP_SAVE_NAME, 'rb')
    read_save_data(file)
    file.close
    File.delete(TEMP_SAVE_NAME)
  end
 
  def main_quicksave
    if DISABLE_PROMPT
      on_decision(TEMP_SAVE_NAME)
      $scene = Scene_Title.new
    else
      @prompt_window = Window_Prompt.new(TEMP_SAVE_TEXT, 1)
      Graphics.transition
      loop do
        Graphics.update
        Input.update
        update_quicksave
        break if $scene != self
      end
      Graphics.freeze
      @prompt_window.dispose
    end
  end
 
  def update_quicksave
    @prompt_window.update
    if Input.trigger?(Input::C)
      if @prompt_window.index == 0
        on_decision(TEMP_SAVE_NAME)
        $scene = Scene_Title.new
      else
        on_cancel
      end
    elsif Input.trigger?(Input::B)
      on_cancel
    end
  end
 
end

#==============================================================================
# ** Scene_Save
#==============================================================================

class Scene_Save
 
  alias temp_save_detect_menu initialize
  def initialize
    @temp_save_active = $scene.is_a?(Scene_Menu)
    temp_save_detect_menu
  end
 
end

#==============================================================================
# ** Window_Prompt
#==============================================================================

class Window_Prompt < Window_Base
 
  attr_reader :index
 
  def initialize(txt, mode=0, index=0)
    @txt, @mode = txt, mode
    width = text_width(txt) + 32
    width = 300 if width < 300
    height = 64 + mode * 64
    super(320 - width/2, 240 - height/2, width, height)
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    @index = @mode > 0 ? index : -1
  end
 
  def text_width(text)
    b = Bitmap.new(1, 1)
    w = b.text_size(text).width
    b.dispose
    return w
  end
 
  def reset(txt, mode=0, index=0)
    @txt = txt unless txt == nil
    @mode = mode
    @index = @mode > 0 ? index : -1
    self.contents.dispose
    width = text_width(txt) + 32
    width = 300 if width < 300
    self.width, self.height = width, 64 + mode * 64
    self.x, self.y = 320 - self.width/2, 240 - self.height/2
    self.contents = Bitmap.new(self.width - 32, self.height - 32)
    refresh
    update_cursor_rect
  end
 
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, self.width - 32, 32, @txt, 1)
    return unless @mode > 0
    self.contents.draw_text(self.width/2 - 16 - 34, 32, 68, 32, 'Yes', 1)
    self.contents.draw_text(self.width/2 - 16 - 34, 64, 68, 32, 'No', 1)
  end
 
  def index=(index)
    @index = index
    update_cursor_rect
  end
 
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    cursor_width = self.contents.text_size('  Yes  ').width
    x = (self.width - cursor_width)/2 - 16
    y = 32 + @index * 32
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
 
  def update
    super
    return unless @mode > 0
    if self.active && @index >= 0
      if Input.repeat?(Input::DOWN)
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + 1) % 2
      elsif Input.repeat?(Input::UP)
        $game_system.se_play($data_system.cursor_se)
        @index = (@index + 3) % 2
      end
    end
    update_cursor_rect
  end
 
end



Instructions

In Scene_Title, find the following lines or similar:


@continue_enabled = false
for i in 0..3
  if FileTest.exist?("Save#{i+1}.rxdata")
    @continue_enabled = true
  end
end


Now add the following lines right after the above code:


if FileTest.exist?(Scene_File::TEMP_SAVE_NAME)
  @continue_enabled = true
end



Configuration

TEMP_SAVE_NAME: The name (and path if needed) for the temp save file.

TEMP_LOAD_TEXT: The message to be displayed when a temp save is loaded.

TEMP_SAVE_TEXT: The message to be displayed when asking for temp save confirmation.

DISABLE_PROMPT: If this is set to true, the prompt and confirmation windows will be disabled. (Please check Issues!)


Compatibility

   From version 2.0, it should be compatible with almost anything, including exotic save systems, save scenes and even encryption systems.

For scripters: There is nothing like absolute compatibility, so this still has it's limitations:



Issues

   If DISABLE_PROMPT is activated, while loading or saving a quick-save, there will be 2 sounds of button press instead of 1. Actually, it is the sound of button press and the sound of saving and loading. Fixing this means losing a lot of compatibility (since v2.0), so I have no intention of doing that unless I get an idea which retains compatibility.


Credits and Thanks




Author's Notes

If you have any problems, suggestions or comments, you can find me at:

- http://forum.chaos-project.com
- http://quantumcore.forumotion.com

Enjoy ^_^
Title: Re: [XP]Temp Save v1.1
Post by: Nortos on February 24, 2008, 05:03:52 am
good job I saw this on your forum a request by Dmoose it's a nice script :)
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 24, 2008, 05:49:37 am
ty Nortos :D

I have an idea, I'll mod the Scene_File to handle quick-load (pressing continue will open the loading screen, but you'll be shown a dialog where you chose to quickload or not. If not, you're returned to the title screen. Technically the same effect, youre forced to use the quicksave file, but it's more compatible. Hm... I'll do it sometime, it prevents conflicts with other scripts which mod Scene_Title's def main.
Title: Re: [XP]Temp Save v1.1
Post by: Nortos on February 24, 2008, 06:06:17 am
sounds good I'm looking forward to it atm I'm making a HUD for my game of gold playtime location ect and it appears for 5 or so seconds every time you come back to scene_map say after a menu or battle or if an input is pressed
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 24, 2008, 06:39:58 am
when will be the net update btw? Just chuck in another few scenes, update your scripting work, and if there's lot of updates in features, and if you don't want to call it a second demo, call it a tech demo ;)
Title: Re: [XP]Temp Save v1.1
Post by: Punn on February 24, 2008, 07:18:37 am
Oh!! Can you adjust Stormtronic CMS? Just remove the Save scene with the Temp save scene instead.. xD
Title: Re: [XP]Temp Save v1.1
Post by: Sally on February 24, 2008, 11:25:40 am
i don't understand what it dose...
Title: Re: [XP]Temp Save v1.1
Post by: Punn on February 24, 2008, 01:35:33 pm
Quote from: Susys on February 24, 2008, 11:25:40 am
i don't understand what it dose...


Read there...

Quote from: Fantasist on February 24, 2008, 05:02:29 am
Temp Save
Version: 1.1
Type: Save Feature



Introduction

With this script, the 'Save' option in the menu will do a quick save and take you to the title screen, which will have a 'Quick Save' (or any word you like) option instead of 'Continue'. On loading a quick save, the quick save file is deleted after loading the game.


Features


  • Imitates the quick save feature found in many games
  • Saving from menu will quick save and take you to the title screen instead of opening the save scene (and leaves the actual saving only for save points in the game)
  • The 'Continue' option in the game becomes 'Quick Load' (or any text you want) when you're taken to the title screen after a quick save



If you play games like Breath Of Fire, if your choose to save from the menu, it will make a temp file,once its load, its gone.
Title: Re: [XP]Temp Save v1.1
Post by: Nortos on February 24, 2008, 05:03:50 pm
yeah Mums would be easy to mod storms cms with this
Title: Re: [XP]Temp Save v1.1
Post by: Calintz on February 24, 2008, 07:22:58 pm
This is nice...
I've always thought that quick-saves were a good feature to have in your games...
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 25, 2008, 09:22:22 am
QuoteIf you play games like Breath Of Fire, if your choose to save from the menu, it will make a temp file,once its load, its gone.

Right you are, and not to forget, it basically forces you to use the quick save instead of the save files.

@mum: Mod coming up in my next post.
Title: Re: [XP]Temp Save v1.1
Post by: fugibo on February 26, 2008, 09:00:44 pm
How about you just have the game save a backup of all the game data into the RAM, rather than saving? It'll be 10x faster and non-abusable (you know my history with save files...)
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 27, 2008, 08:38:10 am
RAM as in Random Access Memory? That's way beyond my level! hm, or do you just mean to use, say, a global to dump all data instead of a marshal file? Like this?:

$temp_save_data = [$game_system, $game_party, $game_screen.....]


But that would get erased when the user exits the program, I want the file to stay for when the user reopens the project later.

@mum: I just realized STCMS is one of the only (probably the only) CMS where I need to mod a part of my script for everything to work right. Here's what you need to do:

1) Search for 'class Scene_Menu', scroll down for 'when 6' and find this line:
@scene = Scene_CMSSave.new


2) comment that line and add 'quick_save', it should look like this:
quick_save #@scene = Scene_CMSSave.new

(commenting only for backup reasons, not necessary)

3) Make a new slot and paste the following (or paste this below everything in the temp save script instead of making a new slot):

Spoiler: ShowHide
class Scene_Menu
 
  def quick_save
    file = File.open(Quick_Save, 'wb')
    characters = []
    $game_party.actors.each {|actor|
      characters.push([actor.character_name, actor.character_hue])
    }
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1 if Change_Save_Count
    $game_system.magic_number = $data_system.magic_number
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
    file.close
    @scene = Scene_Title.new
  end
 
end


Now, arrange the scripts in this order:

- Temp Save
- Temp Save fix for STCMS (if you put the above code in a new slot)
- STCMS

It will work.

@Bliz: Does STCMS have a recognizable global (like $stcms)? I didn't find one...
Title: Re: [XP]Temp Save v1.1
Post by: Blizzard on February 27, 2008, 08:56:23 am
# for compatibility
$stormtronics_cms = 5.2
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 27, 2008, 09:11:56 am
Shit, bad Bliz, BAD! I searched, and double checked for $stcms! *goes makes this script compatible with STCMS*

Say, how far back does this go? Do I use
if $stormtronics_cms


or do I use
if $stormtronics_cms >= 5.2


EDIT: Wait! Not so fast! When I place this above STCMS, it doesn't work! And when I place it below, it messes up STCMS. That's it. I'll come up with version 2 in an hour.

@Bliz: Is it a good idea to mod Scene_Title to show 'Quick Load' instead of continue or do I mod Scene_File instead? Modding  Scene_File is more compatible, but what would you prefer? Not technically, but what would you think will be cooler?
Title: Re: [XP]Temp Save v1.1
Post by: Blizzard on February 27, 2008, 09:32:14 am
Scene_File, then you wouldn't even need to check the compatibility of STCMS.

If you use the first you only check whether STCMS is installed, the second one would make a version requirement as well.
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 27, 2008, 09:40:42 am
Scene_File for v2 then :)

QuoteIf you use the first you only check whether STCMS is installed, the second one would make a version requirement as well.


I know, I meant to ask if even really old versions have that global, where 'when 6' is 'when <num>', that is to say in older versions, 'Save' is not the 7th file. Cause if I use the first one, I can make it compatible with older versions too. but now that I think about it, I don;t see why one would prefer using an older version of STCMS...
Title: Re: [XP]Temp Save v1.1
Post by: Blizzard on February 27, 2008, 09:55:31 am
I think 5.1 was the first to have that.
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 27, 2008, 10:01:17 am
Cool, I'll go with only recognition and not version recognition.

Hey, KCG uses a module for recognition constants, right? Why don't you adopt that method too?
Title: Re: [XP]Temp Save v1.1
Post by: Blizzard on February 27, 2008, 01:32:16 pm
Because checking whether a module exists or not is a pain. :P I put big configs into the BlizzCFG module now, but I always use a global variable for recognition. Simply easier that way.
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 28, 2008, 09:34:55 am
Right...
And tell me this, which is better? a global hash or lots of global variables? If you used something like $blizzard_scripts = {}
instead of one global (of float kind) for each script... I think a global hash is a bad idea, by the way it works, it takes longer(and takes up more RAM?), right? I'm asking this cause I somehow don't like too many globals...
Title: Re: [XP]Temp Save v1.1
Post by: Blizzard on February 29, 2008, 06:47:07 am
Hashes are good if you have lots of data. If I used hash for like 100 scripts, then it would still be a waste of time. I rather have a couple of globals to easify things so people don't have to check whether the global hash is there and then check whether a specific script is installed. You can use it if you want, I won't.
Title: Re: [XP]Temp Save v1.1
Post by: Fantasist on February 29, 2008, 07:16:50 am
Okay, so I've learnt another lesson on hashes. ty as always :)
Title: Re: [XP] Temp Save v1.1
Post by: Hadeki on January 18, 2009, 02:46:22 am
Is it possible for me to use this in my game, but, like, shift the scripting around and change some terms and stuff? I'll still give credit to you though.
I separated the Scene_Title class into two scenes and it would take a little bit of tweeking of this script for it to work out. I know exactly how I'll do it though.

EDIT.
Is there a way to bring up a message and choice confirming the temporary save option when you select "Save" from the menu before the same file is created?
Also, how would I go about fading the screen to black and fading out the background music and sounds, then showing a "Temporary save file created" message right before it sends the player back to the title screen?
Title: Re: [XP] Temp Save v1.1
Post by: Fantasist on January 18, 2009, 04:18:08 am
QuoteIs there a way to bring up a message and choice confirming the temporary save option when you select "Save" from the menu before the same file is created?
Also, how would I go about fading the screen to black and fading out the background music and sounds, then showing a "Temporary save file created" message right before it sends the player back to the title screen?


I made a window class for confirmation and message displaying. I don't remember if it's included in this script, but it's there in Chaos Project Save Layout. I'm already late with updating this, so I'll do it now with the features you mentioned.

EDIT: Updated to version 2.0: Complete overhaul and major compatability improvement ;)
Title: Re: [XP] Temp Save v2.0
Post by: Hadeki on January 20, 2009, 09:31:29 pm
Okay, thaaaaaaaaaaaaank you a lot for this. I really appreciate it.
But I have one last question: is there a way to have three rows of text or more for the confirmation message? (The one for when you save from the menu.) My confirmation message is a little long. I guess it's not that important though...
Title: Re: [XP] Temp Save v2.0
Post by: Fantasist on January 21, 2009, 10:15:04 am
More than one line, huh? It can be done with some coding but I'd like to avoid it. I can script the feature to put a background picture during the messages so it's not just black. Will that be okay?
Title: Re: [XP] Temp Save v2.0
Post by: Hadeki on January 21, 2009, 08:01:30 pm
Well, it's okay. If you don't want to do it then it's fine. I have sort of asked to do, like, five hundred things in the last few days. This script is fine as it is, thank you.
Title: Re: [XP] Temp Save v2.0
Post by: Fantasist on January 22, 2009, 07:03:44 am
Don't mention it :) I WILL implement the multi-line feature, but not now. Glad you like it :)

PS: And seriously, I don't think there are many similar scripts taking this approach. Its compatiblity is impressive for this type of script (I think :shy:)
Title: Re: [XP] Temp Save v2.0
Post by: Reno-s--Joker on February 09, 2009, 11:38:36 pm
You probably don't need me to tell you that this is good! :haha:

Thanks for making this script - I'll probably find it very useful. <3
Title: Re: [XP] Temp Save v2.0
Post by: Fantasist on February 09, 2009, 11:53:27 pm
Thanks Reno :)
Title: Re: [XP] Temp Save v2.0
Post by: G_G on February 10, 2009, 12:08:14 am
awesome script fant!

I might use this in an upcoming rpg afer my star wars game is done.

*powers up*
Title: Re: [XP] Temp Save v2.0
Post by: Reno-s--Joker on February 14, 2009, 05:09:18 am
I just tested this out today - I love how simple it is! :D This works really well with limited save points too - sometimes it's hard to get to the next one if you're playing for only a short while at a time... >.<

:haha: Lol... you're almost going to take up as much of the credits as Blizzard is atm... :xD: Once again, awesome script. <333
Title: Re: [XP] Temp Save v2.1
Post by: Fantasist on July 05, 2009, 02:34:06 pm
Updated to version 2.1:

- Fixed bugs
- Added Disable Prompt option