Kain Nobel
Member
This topic is closed and resolved!
#===============================================================================
# ~** Auto-Save System **~
#-------------------------------------------------------------------------------
# Written by : Kain Nobel
# Version   : 0.2c
# Last Update : 09.11.2008
# Created On : 09.10.2008
#-------------------------------------------------------------------------------
# * Description  :
#-------------------------------------------------------------------------------
#Â Â This is an AutoSave system for the map scene. Whenever you visit a new map,
#Â Â a file is saved within the game's Data directory. If you ever can't find a
#Â Â save point, and want to quit a game (as long as the script is enabled), you
#Â Â can simply close the game without saving and resume it at a later time.
#-------------------------------------------------------------------------------
# * Features   :
#-------------------------------------------------------------------------------
#Â Â - Create an AutoSave file in the games internal directory each time visiting
#Â Â Â a new map scene.
#Â Â - Close your game and open it at a later time from the entrance of the last
#Â Â Â map scene visited.
#Â Â - Author can toggle script activity with 'AutoSave::Enabled = true/false'
#-------------------------------------------------------------------------------
# * To-Do List  :
#-------------------------------------------------------------------------------
#Â Â - Get the map resume loading to work, first of all...
#Â Â - Create a quick 'n convenient sprite message to let player know if autosave
#Â Â Â is enabled.
#-------------------------------------------------------------------------------
# * Requirements :
#-------------------------------------------------------------------------------
#Â Â - SDK version 2.2 or higher, at least parts 1 and 3
#===============================================================================
module AutoSave
 Enabled = true
 Filename = 'AutoSave.rxdata'
end
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Map.AutoSaveResume', 'Kain Nobel', 0.2, '09.11.2008')
SDK.log_alias(Game_Temp, :autosave_game_temp_intialize, :initialize)
SDK.log_alias(Game_Map,  :autosave_game_map_setup,    :setup)
SDK.log_alias(Scene_Title,:autosave_scene_title_main,   :main)
#-------------------------------------------------------------------------------
# * Use AutoSave::Enabled, not SDK.enable() to toggle script
#-------------------------------------------------------------------------------
if SDK.enabled?('Map.AutoSaveResume') && !AutoSave::Enabled
 SDK.disable('Map.AutoSaveResume')
end
if !SDK.enabled?('Map.AutoSaveResume') && AutoSave::Enabled
 SDK.enable('Map.AutoSaveResume')
end
#-------------------------------------------------------------------------------
# * SDK Enabled Test - BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Map.AutoSaveResume')
#===============================================================================
# ** Game_Temp
#-------------------------------------------------------------------------------
#Â Â This class has an extra attribute added to it, so the Title scene knows to
# load the autosave or not.
#===============================================================================
class Game_Temp
 #-----------------------------------------------------------------------------
 # * Public Instance Variables
 #-----------------------------------------------------------------------------
 attr_accessor :autosave_invalid
 attr_accessor :autosave_load
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :autosave_game_temp_initialize, :initialize
 #-----------------------------------------------------------------------------
 # * Object Initialization
 #-----------------------------------------------------------------------------
 def initialize
  autosave_game_temp_initialize
  @autosave_invalid = false
  @autosave_load  = FileTest.exist?('Data/'+AutoSave::Filename)
 end
end
#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
#Â Â Each time the map is set up, the game does an autosave.
#===============================================================================
class Game_Map
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :autosave_game_map_setup, :setup
 #-----------------------------------------------------------------------------
 # * Setup
 #-----------------------------------------------------------------------------
 def setup(map_id)
  $game_temp.autosave_load = true
  file = File.open('Data/'+AutoSave::Filename, 'wb')
  save = Scene_Save.new
  save.write_save_data(file)
  file.close
  $game_temp.autosave_load = false
  unless exists?(map_id)
   print("Failed to setup $game_map.map_id:#{map_id}\n\nI am now deleting",
   " your AutoSave file and \n taking you back to the Title Screen.")
   $game_temp.autosave_invalid = true
   $scene = Scene_Title.new
   autosave_game_map_setup(1)
  else ; autosave_game_map_setup(map_id)
  end
 end
 #-----------------------------------------------------------------------------
 # * Name   : Exists? (Submitted as a MACL 'RGSS.Map' method)
 #  Info   : Tests to see if Map exists
 #  Author  : Kain Nobel
 #  Call Info : id = Map ID in question
 #-----------------------------------------------------------------------------
 def exists?(id)
  if  id.between?(100, 999) ; filename = "Data/Map"  + id.to_s + ".rxdata"
  elsif id.between?( 10, 99) ; filename = "Data/Map0" + id.to_s + ".rxdata"
  elsif id.between?( 1,  9) ; filename = "Data/Map00" + id.to_s + ".rxdata"
  else            ; return false
  end
  return FileTest.exist?(filename)
 end
end
#===============================================================================
# ** Scene_Title
#-------------------------------------------------------------------------------
#Â Â This scene prettymuch has its own sub-scene that is called if a AutoSave
# file exists.
#===============================================================================
class Scene_Title < SDK::Scene_Base
 #-----------------------------------------------------------------------------
 # * Alias Listing
 #-----------------------------------------------------------------------------
 alias_method :autosave_scene_title_main,     :main
 #-----------------------------------------------------------------------------
 # * Main
 #-----------------------------------------------------------------------------
 def main
  main_autosave_load if main_autosave_exist?
  if $game_temp.autosave_invalid
   if FileTest.exist?('Data/'+AutoSave::Filename)
    File.delete('Data/'+AutoSave::Filename)
   end
   $game_temp.autosave_invalid = false
  end
  autosave_scene_title_main
 end
 #-----------------------------------------------------------------------------
 # * Main Autosave Exist?
 #-----------------------------------------------------------------------------
 def main_autosave_exist?
  if FileTest.exist?('Data/'+AutoSave::Filename) && $game_temp.autosave_load
   return true
  end
  return false
 end
 #-----------------------------------------------------------------------------
 # * Main Autosave
 #-----------------------------------------------------------------------------
 def main_autosave_load
  file = File.open('Data/'+AutoSave::Filename, 'rb')
  load = Scene_Load.new
  load.on_decision('Data/'+AutoSave::Filename)
  file.close
  $game_temp.autosave_load = false
  if FileTest.exist?('Data/'+AutoSave::Filename)
   File.delete('Data/'+AutoSave::Filename)
  end
 end
end
#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end
[code]First, a couple things:
[code]
SDK.log_alias(Game_Temp, :autosave_game_temp_intialize, :initialize)
SDK.log_alias(Game_Map, :autosave_game_map_setup, :setup)
SDK.log_alias(Scene_Title,:autosave_scene_title_main, :main)
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Map.AutoSaveResume', 'Kain Nobel', 0.2, '09.11.2008')
module AutoSave
SDK.disable('Map.AutoSaveResume') if true
Filename = 'AutoSave.rxdata'
end
def exists?(id)
if id.between?(100, 999) ; filename = "Data/Map" + id.to_s + ".rxdata"
elsif id.between?( 10, 99) ; filename = "Data/Map0" + id.to_s + ".rxdata"
elsif id.between?( 1, 9) ; filename = "Data/Map00" + id.to_s + ".rxdata"
else ; return false
end
return FileTest.exist?(filename)
end
def exists?(id)
return FileTest.exist?(sprintf("Data/Map%03d.rxdata", map_id))
end
module AutoSave
def self.autosave
file = File.open(Filename, "wb")
(Scene_Save.new).write_save_data(file)
file.close
end
def self.autoload
(Scene_Load.new).on_decision(Filename)
end
def self.exist?
return FileTest.exist?(Filename)
end
end
class Game_Map
alias_method :kn_autosave_gmmap_setup, :setup
def setup(map_id)
Autosave.autosave
kn_autosave_gmmap_setup(map_id)
end
end
class Scene_Title
alias_method :kn_autosave_scnttl_mdb, :main_database
def main_database
kn_autosave_scnttl_mdb
if AutoSave.exists?
AutoSave.autoload
$scene = Scene_Map.new
end
end
end
Script '[SDK-2]::Game/Sprite Objects' line 366: NoMethodError occured
undefined method '>' for nil:NilClass
def update_scrolling
  # If scrolling
  if @scroll_rest > 0 #<---This line.
   # Change from scroll speed to distance in map coordinates
   distance = 2 ** @scroll_speed
   # Execute scrolling
   case @scroll_direction
   when 2 # Down
    scroll_down(distance)
   when 4 # Left
    scroll_left(distance)
   when 6 # Right
    scroll_right(distance)
   when 8 # Up
    scroll_up(distance)
   end
   # Subtract distance scrolled
   @scroll_rest -= distance
  end
 end
#===============================================================================
# ~** Map.AutoSaveResume **~
#-------------------------------------------------------------------------------
# Written by : Kain Nobel
# Version   : 0.3
# Last Update : 09.15.2008
# Created On : 09.10.2008
#-------------------------------------------------------------------------------
# * Description  :
#-------------------------------------------------------------------------------
#Â Â This is an AutoSave system for the map scene. Whenever you visit a new map,
#Â Â a file is saved within the game's Data directory. If you ever can't find a
#Â Â save point, and want to quit a game (as long as the script is enabled), you
#Â Â can simply close the game without saving and resume it at a later time.
#-------------------------------------------------------------------------------
# * Features   :
#-------------------------------------------------------------------------------
#Â Â - Create an AutoSave file in the games internal directory each time visiting
#Â Â Â a new map scene.
#Â Â - Close your game and open it at a later time from the entrance of the last
#Â Â Â map scene visited.
#Â Â - Author can toggle script activity with 'AutoSave::Enabled = true/false'
#-------------------------------------------------------------------------------
# * To-Do List  :
#-------------------------------------------------------------------------------
#Â Â - Get the map resume loading to work, first of all...
#Â Â - Create a quick 'n convenient sprite message to let player know if autosave
#Â Â Â is enabled.
#-------------------------------------------------------------------------------
# * Requirements :
#-------------------------------------------------------------------------------
#Â Â - SDK version 2.2 or higher, at least parts 1 and 3
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Map.AutoSaveResume', 'Kain Nobel', 0.3, '09.15.2008')
#-------------------------------------------------------------------------------
# * SDK Enabled Test - BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Map.AutoSaveResume')
#===============================================================================
# ~** AutoSave **~
#-------------------------------------------------------------------------------
#Â Â This module handles all the AutoSave methods.
#===============================================================================
module AutoSave
 #-----------------------------------------------------------------------------
 # * Customizable Constant
 #-----------------------------------------------------------------------------
 Filename = "Data/AutoSave.rxdata"
 #-----------------------------------------------------------------------------
 # * AutoSave.save_file
 #-----------------------------------------------------------------------------
 def self.save_file
  $game_temp.autosave_load = false
  file = File.open(Filename, "wb")
  (Scene_Save.new).write_save_data(file)
  file.close
 end
 #-----------------------------------------------------------------------------
 # * AutoSave.load_file
 #-----------------------------------------------------------------------------
 def self.load_file
  (Scene_Load.new).on_decision(Filename)
 end
 #-----------------------------------------------------------------------------
 # * AutoSave.exists?
 #-----------------------------------------------------------------------------
 def self.exists?
  return FileTest.exist?(Filename)
 end
end
#===============================================================================
# ** Game_Temp
#-------------------------------------------------------------------------------
#Â Â This class has an extra attribute added to it, so the Title scene knows to
# load the autosave or not.
#===============================================================================
class Game_Temp
 #-----------------------------------------------------------------------------
 # * Public Instance Variables
 #-----------------------------------------------------------------------------
 attr_accessor :autosave_load
 #-----------------------------------------------------------------------------
 # * Alias Listings
 #-----------------------------------------------------------------------------
 alias_method :autosave_game_temp_initialize, :initialize
 #-----------------------------------------------------------------------------
 # * Object Initialization
 #-----------------------------------------------------------------------------
 def initialize
  autosave_game_temp_initialize
  @autosave_load = AutoSave.exists?
 end
end
#===============================================================================
# ** Scene_Title
#-------------------------------------------------------------------------------
#Â Â This class has been enhanced to load an AutoSave file (if it exists) apon
# opening the Game.exe later on after previously closing a game in progress.
#===============================================================================
class Scene_Title < SDK::Scene_Base
 #-----------------------------------------------------------------------------
 # * Alias Listing
 #-----------------------------------------------------------------------------
 alias_method :autosave_scene_title_main_database, :main_database
 #-----------------------------------------------------------------------------
 # * Main Database
 #-----------------------------------------------------------------------------
 def main_database
  autosave_scene_title_main_database
  if $game_temp.autosave_load
   AutoSave.load_file
   $scene = Scene_Map.new
  end
 end
end
#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
#Â Â Each time you visit a new map scene, the AutoSave file is written to so you
# can just close the game and open it later and start where you left off at.
#===============================================================================
class Game_Map
 #-----------------------------------------------------------------------------
 # * Alias Listing
 #-----------------------------------------------------------------------------
 alias_method :autosave_game_map_setup, :setup
 #-----------------------------------------------------------------------------
 # * Setup
 #-----------------------------------------------------------------------------
 def setup(map_id)
  AutoSave.save_file
  autosave_game_map_setup(map_id)
 end
end
#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end
#===============================================================================
# ~** Map.AutoSaveResume **~
#-------------------------------------------------------------------------------
# Written by : Kain Nobel
# Version : 0.3
# Last Update : 09.15.2008
# Created On : 09.10.2008
#-------------------------------------------------------------------------------
# * Description :
#-------------------------------------------------------------------------------
# This is an AutoSave system for the map scene. Whenever you visit a new map,
# a file is saved within the game's Data directory. If you ever can't find a
# save point, and want to quit a game (as long as the script is enabled), you
# can simply close the game without saving and resume it at a later time.
#-------------------------------------------------------------------------------
# * Features :
#-------------------------------------------------------------------------------
# - Create an AutoSave file in the games internal directory each time visiting
# a new map scene.
# - Close your game and open it at a later time from the entrance of the last
# map scene visited.
# - Author can toggle script activity with 'AutoSave::Enabled = true/false'
#-------------------------------------------------------------------------------
# * To-Do List :
#-------------------------------------------------------------------------------
# - Get the map resume loading to work, first of all...
# - Create a quick 'n convenient sprite message to let player know if autosave
# is enabled.
#-------------------------------------------------------------------------------
# * Requirements :
#-------------------------------------------------------------------------------
# - SDK version 2.2 or higher, at least parts 1 and 3
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Map.AutoSaveResume', 'Kain Nobel', 0.3, '09.15.2008')
#-------------------------------------------------------------------------------
# * SDK Enabled Test - BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Map.AutoSaveResume')
#===============================================================================
# ~** AutoSave **~
#-------------------------------------------------------------------------------
# This module handles all the AutoSave methods.
#===============================================================================
module AutoSave
#-----------------------------------------------------------------------------
# * Customizable Constant
#-----------------------------------------------------------------------------
Filename = "Data/AutoSave.rxdata"
#-----------------------------------------------------------------------------
# * AutoSave.save_file
#-----------------------------------------------------------------------------
def self.save_file
file = File.open(Filename, "wb")
(Scene_Save.new).write_save_data(file)
file.close
end
#-----------------------------------------------------------------------------
# * AutoSave.load_file
#-----------------------------------------------------------------------------
def self.load_file
(Scene_Load.new).on_decision(Filename)
end
#-----------------------------------------------------------------------------
# * AutoSave.exists?
#-----------------------------------------------------------------------------
def self.exists?
return FileTest.exist?(Filename)
end
end
#===============================================================================
# ** Scene_Title
#-------------------------------------------------------------------------------
# This class has been enhanced to load an AutoSave file (if it exists) apon
# opening the Game.exe later on after previously closing a game in progress.
#===============================================================================
class Scene_Title < SDK::Scene_Base
#-----------------------------------------------------------------------------
# * Alias Listing
#-----------------------------------------------------------------------------
alias_method :autosave_scene_title_main_database, :main_database
#-----------------------------------------------------------------------------
# * Main Database
#-----------------------------------------------------------------------------
def main_database
autosave_scene_title_main_database
if AutoSave.exists?
AutoSave.load_file
$scene = Scene_Map.new
end
end
end
#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
# Each time you visit a new map scene, the AutoSave file is written to so you
# can just close the game and open it later and start where you left off at.
#===============================================================================
class Game_Map
#-----------------------------------------------------------------------------
# * Alias Listing
#-----------------------------------------------------------------------------
alias_method :autosave_game_map_setup, :setup
#-----------------------------------------------------------------------------
# * Setup
#-----------------------------------------------------------------------------
def setup(map_id)
autosave_game_map_setup(map_id)
AutoSave.save_file
end
end
#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end
#===============================================================================
# ** Game_Player
#-------------------------------------------------------------------------------
# You encounter a bug with this script if you don't do this.
#===============================================================================
class Game_Player < Game_Character
#-----------------------------------------------------------------------------
# * Alias Listing
#-----------------------------------------------------------------------------
alias_method :autosave_game_character_encounter_count, :encounter_count
#-----------------------------------------------------------------------------
# * Encounter Count
#-----------------------------------------------------------------------------
def encounter_count
if @encounter_count.nil?
make_encounter_count
end
autosave_game_character_encounter_count
end
end