Autosave Script

Autosave Script
Version: Offline 1.0


Introduction

Well, this was originally created for MNetplay, but since I didn't have acess to a server to test it out, I made a version for offline games.

Features
  • Automatically Saves the game file to the first file slot, user may choose by using call script:
    1. $scene = Scene_AutoSave.new
    Expand to see the code.
  • Game now only saves after important events (gaining items, teleporting, etc)

Screenshots

N/A

Demo
N/A Very simple to put in game

Script

Script Spoiler
  1. #==============================================================================
  2. # Autosave Script Offline 1.0
  3. #------------------------------------------------------------------------------
  4. # Authors   Darklord, Blue Elf and Meâ„¢
  5. # Version   Offline 1.0
  6. #------------------------------------------------------------------------------
  7. # This script aliases(a)/rewrites(r) in the folowwing classes and methods:
  8. #
  9. #  Game_Party  -> gain_gold  (a) , gain_item (a), gain_armor (a), gain_weapon (a)
  10. #  add_actor (a), remove_actor (a)
  11. #  Game_System -> initialize (a)
  12. #  Scene_Save  -> initialize (a,r) , on_decision (a,r)
  13. #  Scene_Map   -> transfer player (r)
  14. #  Scene_Battle 1 -> battle_end (a)
  15. #==============================================================================
  16.  
  17.  
  18. #==============================================================================
  19. # *** AutoSave
  20. #------------------------------------------------------------------------------
  21. # This module handles the AutoSaving
  22. #==============================================================================
  23. module AutoSave
  24. #--------------------------------------------------------------------------
  25. # * Saves File
  26. #--------------------------------------------------------------------------
  27. def self.save
  28.   begin
  29.     #Saves the file to whatever $game_system.filename is
  30.     file = File.open($game_system.filename, "wb")
  31.     a = Scene_Save.new
  32.     a.write_save_data(file)
  33.   ensure
  34.     file.close
  35.   end
  36. end
  37. #--------------------------------------------------------------------------
  38. # * Deletes File
  39. #--------------------------------------------------------------------------
  40. def self.deletesave
  41.   begin
  42.     if FileTest.exits?($game_system.filename)
  43.       File.delete($game_system.filename)
  44.     end  
  45.   end
  46. end
  47. end
  48. #==============================================================================
  49.  
  50. #==============================================================================
  51. # ** Scene_AutoSave
  52. #------------------------------------------------------------------------------
  53. # This class performs save screen processing.
  54. # This changes the autosave file
  55. #==============================================================================
  56.  
  57. class Scene_AutoSave < Scene_File
  58.   #--------------------------------------------------------------------------
  59.   # * Object Initialization
  60.   #--------------------------------------------------------------------------
  61.   def initialize
  62.     super("Which file would you like to Autosave to?")
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * Decision Processing
  66.   #--------------------------------------------------------------------------
  67.   def on_decision(filename)
  68.     # Play save SE
  69.     $game_system.se_play($data_system.save_se)
  70.     $game_system.filename_c(filename)
  71.     # If called from event
  72.     if $game_temp.save_calling
  73.       # Clear save call flag
  74.       $game_temp.save_calling = false
  75.       # Switch to map screen
  76.       $scene = Scene_Map.new
  77.       return
  78.     end
  79.     # Switch to menu screen
  80.     $scene = Scene_Map.new
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # * Cancel Processing
  84.   #--------------------------------------------------------------------------
  85.   def on_cancel
  86.     # Play cancel SE
  87.     $game_system.se_play($data_system.cancel_se)
  88.     # If called from event
  89.     if $game_temp.save_calling
  90.       # Clear save call flag
  91.       $game_temp.save_calling = false
  92.       # Switch to map screen
  93.       $scene = Scene_Map.new
  94.       return
  95.     end
  96.     # Switch to menu screen
  97.     $scene = Scene_Map.new
  98.   end
  99. end
  100.  
  101. #==============================================================================
  102. # ** Game_System
  103. #------------------------------------------------------------------------------
  104. #  This class handles data surrounding the system. Backround music, etc.
  105. #  is managed here as well. Refer to "$game_system" for the instance of
  106. #  this class.
  107. #==============================================================================
  108. class Game_System
  109. #--------------------------------------------------------------------------
  110. # * Aliasing Objects
  111. #--------------------------------------------------------------------------
  112. alias autosaveinit initialize
  113. #--------------------------------------------------------------------------
  114. # * Initialize
  115. #--------------------------------------------------------------------------
  116. def initialize
  117.   autosaveinit
  118.   @filename = "Save1.rxdata"
  119. end
  120. #--------------------------------------------------------------------------
  121. # * Filename -> Returns Autosave Filename
  122. #--------------------------------------------------------------------------
  123. def filename
  124.   if @filename != nil
  125.     return @filename
  126.   else
  127.     return "Save1.rxdata"
  128.   end  
  129. end
  130. #--------------------------------------------------------------------------
  131. # * Filename_change -> Sets New Autosave Filename
  132. #--------------------------------------------------------------------------
  133. def filename_c(newname)
  134.   return if newname == "" or newname == nil
  135.   @filename = newname
  136. end
  137. end
  138.  
  139. #==============================================================================
  140. # ** Game_Party
  141. #------------------------------------------------------------------------------
  142. # This class handles the party. It includes information on amount of gold
  143. # and items. Refer to "$game_party" for the instance of this class.
  144. #==============================================================================
  145. class Game_Party
  146.  
  147. alias gainglod_autosave gain_gold
  148. alias gainitem_autosave gain_item
  149. alias gainweap_autosave gain_weapon
  150. alias gainarmor_autosave gain_armor
  151. alias add_actor_autosave add_actor
  152. alias remove_actor_autosave remove_actor
  153. #--------------------------------------------------------------------------
  154. # * Gain Gold (or lose)
  155. # n : amount of gold
  156. #--------------------------------------------------------------------------
  157. def gain_gold(n)
  158.   gainglod_autosave(n)
  159.   AutoSave.save
  160. end
  161. #--------------------------------------------------------------------------
  162. # * Gain Items (or lose)
  163. # item_id : item ID
  164. # n : quantity
  165. #--------------------------------------------------------------------------
  166. def gain_item(item_id, n)
  167.   gainitem_autosave(item_id, n)
  168.   AutoSave.save
  169. end
  170. #--------------------------------------------------------------------------
  171. # * Gain Weapons (or lose)
  172. # weapon_id : weapon ID
  173. # n : quantity
  174. #--------------------------------------------------------------------------
  175. def gain_weapon(weapon_id, n)
  176.   gainweap_autosave(weapon_id, n)
  177.   AutoSave.save
  178. end
  179. #--------------------------------------------------------------------------
  180. # * Gain Armor (or lose)
  181. # armor_id : armor ID
  182. # n : quantity
  183. #--------------------------------------------------------------------------
  184. def gain_armor(armor_id, n)
  185.   gainarmor_autosave(armor_id, n)
  186.   AutoSave.save
  187. end
  188. #--------------------------------------------------------------------------
  189. # * Add an Actor
  190. #     actor_id : actor ID
  191. #--------------------------------------------------------------------------
  192. def add_actor(actor_id)
  193.   add_actor_autosave(actor_id)
  194.   AutoSave.save
  195. end
  196. #--------------------------------------------------------------------------
  197. # * Remove Actor
  198. #     actor_id : actor ID
  199. #--------------------------------------------------------------------------
  200. def remove_actor(actor_id)
  201.   remove_actor_autosave(actor_id)
  202.   AutoSave.save
  203. end
  204. end
  205. #==============================================================================
  206. # ** Scene_Map
  207. #------------------------------------------------------------------------------
  208. #  This class performs map screen processing.
  209. #==============================================================================
  210.  
  211. class Scene_Map
  212. alias tp_autosave transfer_player
  213. #--------------------------------------------------------------------------
  214. # * Player Place Move
  215. #--------------------------------------------------------------------------
  216. def transfer_player
  217.  $game_map.map_id != $game_temp.player_new_map_id ? result = true : result = false
  218.  tp_autosave
  219.  AutoSave.save if result
  220. end
  221. end
  222. #==============================================================================
  223. # ** Scene_Battle (part 1)
  224. #------------------------------------------------------------------------------
  225. #  This class performs battle screen processing.
  226. #==============================================================================
  227. class Scene_Battle
  228. alias battle_end_autosave battle_end
  229.   #--------------------------------------------------------------------------
  230.   # * Battle Ends
  231.   #     result : results (0:win 1:lose 2:escape)
  232.   #--------------------------------------------------------------------------
  233.   def battle_end(result)
  234.    battle_end_autosave(result)
  235.    AutoSave.save
  236.  end
  237. end
  238.  
Expand to see the code.


Instructions

Add that above main.

FAQ

To be added later.

Compatibility

Incompatible with the SDK.

Credits and Thanks

Credits:
Darklord, Blue Elf, and Me(TM)

Thanks to:
Trickster (for ideas on when the game should autosave)
Blizzard (for explanining some save errors to me)

Author's Notes

I havent taken a long beta testing period, so if you find a horrible bug, dont bash me too much, please :(
hmm.. Ragnarokish!

was it?
It's made for an MMO, if thats what you mean :P (making it for offline was easy though :P)
Quote:
Should work with the SDK, has no definitons or closings, but I havent tested it.

Well I took a look through your script

This script is incompatible with SDK since the user has to replace Scene_Map with the one you provided anywhere you place this script in the project if the user has SDK added then there will be incompatibility

And well all I saw to your edit to Scene_Map was a new method and you added five lines of code to the update method I didn't see anything else done to the other methods. If you remove the non edited methods and then you increase compatibility by alot.

I know that this is only a beta version, but why only the first file is autosaved why not let the autosave save it to the currently used save (you would have to let the player select a save when they start a new game and then go from there)

Also I don't like/recommend it being autosaved on every frame It may cause lag on slower machines, in fact, I just inserted this script to test it out and there is lag for my machine, remember just because you don't see lag doesn't mean that person X is not going to see lag either. I think you should rethink how you want it to be game to be autosaved. I'll leave you with a couple of ideas on a better implementation, maybe autosave
  • when the map is changed
  • before an event executes
  • when the user says so (Through a call script)
  • before a battle
And finally Don't consider my post as offensive/bashing this is just constructive criticism on how to improve your script
Thanks for the suggestions!
This was a port over from the script I made for MNetplay, it wasn't made with offline games in mind, so I'll do that over the week.
(Also, bad lag and huge maps go together with this script :P)

I'm still not at a very high level of scripting, so this will probably take me a while.
Hey, Can you post the original script, for one MMO?
I need it... hehehe
Okay, this has been completly redone, and should have much less lag :)

@bmamone: check the Second Nature Studios forum for the Autosave Script for Mnetplay
alias tp_autosave transfer_player

def transfer_player
$game_map.map_id != $game_temp.player_new_map_id ? result = true : result = false
tp_autosave
AutoSave.save if result
end
Expand to see the code.
Already done ;)
ive been looking for one of these. Yes thanks
Wait, is this still incompatible with the SDK?
I suppose it would be compatible, since everything is aliased, but it doesnt have the SDK opening/closing, definition, etc.
[QUOTE=The_Darklord]check the Second Nature Studios forum for the Autosave Script for Mnetplay[/QUOTE]And...where is that? I can't find it. I do a google search, and all I get are a bunch of stuff. One is for Christopher MacDonald, but it's a site about site designing, not a forum for RMXP game making...
Here, http://s10.invisionfree.com/RPG2/index.php?act=idx, but it's no longer active, so don't post any bugs or anything there, because no one will respond.
Sweet, thanks...I am getting an error on their, and I'm not sure where to go to ask why I'm getting an error on there...
You could ask here :P
Or just wait for the N+ version when it comes out.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=4038