Help - Search - Members - Calendar
Full Version: autosave in last saved slot
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
LostSamurai
I've always been a avid fan of putting gambling and mini games in RPGs, and i have done so in my last two games. However, the games are really easy to cheat, since all you need to do is save beforehand and load if you lose. It basically converts the game from "gambling" to "money farming."

Obviously, this can easily be remedied by putting in an autosave feature whenever you gamble. I would like to have the game force a manual save when entering the casino (I know how to do this) then auto-save into the previously saved slot whenever they play a game. (I don't know how to do this) Is this possible?
Jens of Zanicuud
This should work...

CODE
#===============================================================================
# ** Jens of Zanicuud autosave script v 1.0
# - free use, just credit
# - free customization, just PM me the modified version
# - you can fin me on www.rpgrevolution.com
#===============================================================================
class Scene_Load < Scene_File
  alias joz3_old_on_decision on_decision
  def on_decision(filename)
    joz3_old_on_decision(filename)
    $game_system.last_index = @file_index
  end
end

class Scene_Save < Scene_File
  alias joz3_old_on_decision on_decision
  def on_decision(filename)
    joz3_old_on_decision(filename)
    $game_system.last_index = @file_index
  end
end

class Game_System
  attr_accessor :last_index
  alias joz3_old_system_initialize initialize
  def initialize
    joz3_old_system_initialize
    @last_index = -1
  end
  
  def autosave
    filename = "Save#{@last_index + 1}.rxdata"
    if FileTest.exist?(filename)
    file = File.open(filename, "wb")
    write_save_data(file)
    file.close
    end
  end

  def write_save_data(file)
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1
    $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)
  end
end


Just call a script in an event like this:
CODE
$game_system.autosave

and it should overwrite last file loaded...

Tell me if it is what you were looking for...

Jens
LostSamurai
The saving feature definitely works, but I'm having some issues. It autosaves to whichever file you loaded at startup. If you load a different file from the menu screen, it will still autosave to whichever file you originally loaded. In order to prevent this, you must exit to title screen and load from the title screen. (For example, if you load slot one from the title screen, then load slot 2 from the menu screen, it will autosave in slot 1, overwriting the slot 1 file with slot 2's data.)

Also, if you decide to save in a different slot, it will still autosave the original slot. (For example, if you load slot 1, then save in slot 2, it will autosave in slot 1 still.)

I think I need it to overwrite the last saved file, not the last loaded. I would like it that if you load slot 1, then save in slot 2, it will autosave in slot 2. But if you haven't saved since you loaded the file, it needs to save to the last loaded file.

I realize that's very complicated. I'm going to look at the script myself and see if I can understand why it doesn't do that. But I don't know if I'll be successful.

Thank you for your help so far.
Jens of Zanicuud
Uhm... I'll check it in my (little) spare time, then...
If I'll succeed in doing something, I'll reply here...

Tell me if you are using a different Scene_Load / Scene_Save, before.
I designed it on the standard one, so there could be compatibility issues...

EDIT:

replace Scene_Save section in my script with this:

CODE
class Scene_Save < Scene_File
  alias joz3_old_on_decision on_decision
  def on_decision(filename)
    $game_system.last_index = @file_index
    joz3_old_on_decision(filename)
  end
end


this will work with standard Scene_Save / Scene_Load system.
If you have a custom one, just PM me the script folder and I'll fix it.

Jens
LostSamurai
I'm still having the same problem. I'm using Sandgolem's animated save file script (which I can VERY EASILY part with if need be)

CODE
begin
  SDK.log('SG Animated SaveFile', 'sandgolem', 1, '7.08.06')
  if SDK.state('SG Animated SaveFile') != true
    @sg_animsavefile_disabled = true
  end
  rescue
end

if !@sg_animsavefile_disabled
#--------------------------------------------------------------------------

class Window_SaveFile < Window_Base
  alias sg_animatedsave_winsf_ref refresh
  def refresh
    if @sg_animstage != nil
      @sg_animstage += 1
      if @sg_animstage == 4
        @sg_animstage = 0
      end
    else
      @sg_animstage = 0
    end
    sg_animatedsave_winsf_ref
  end
end

class Scene_File
  alias sg_animatedsave_file_upd update
  def update
    if @sg_active != nil
      @sg_active += 1
    else
      @sg_active = 1
    end
    if @sg_active == 8
      @savefile_windows[@file_index].refresh
      @sg_active = 0
    end
    sg_animatedsave_file_upd
  end
end

#--------------------------------------------------------------------------
end


and StormTronics Custom Menu System by Blizzard Version: 4.4b - Nemesis Edition which I cannot part with, I have already modified it to include the Blizzard Stat Distribution system I'm using . I think this script is the problem, because it modifies Scene Save and Scene Load. I'm sorry that I didn't mention it before, I didn't realize.

Here's the Scene Save and Scene Load from that script:

CODE
class Scene_NewSave < Scene_File

  def initialize
    super("Which file would you like to save to?")
  end

  def on_decision(filename)
    $game_system.se_play($data_system.save_se)
    file = File.open(filename, "wb")
    write_save_data(file)
    file.close
    if $game_temp.save_calling
      $game_temp.save_calling = false
      $scene = Scene_Map.new
      return
    end
    $scene = Scene_Menu.new(6)
  end
  
  def on_cancel
    $game_system.se_play($data_system.cancel_se)
    if $game_temp.save_calling
      $game_temp.save_calling = false
      $scene = Scene_Map.new
      return
    end
    $scene = Scene_Menu.new(6)
  end
  
  def write_save_data(file)
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1
    $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)
  end
  
end

class Scene_NewLoad < Scene_File

  def initialize
    $game_temp = Game_Temp.new
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..3
      filename = make_filename(i)
      if FileTest.exist?(filename)
        file = File.open(filename, "r")
        if file.mtime > latest_time
          latest_time = file.mtime
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
    super("Which file do you wish to load from?")
  end

  def on_decision(filename)
    unless FileTest.exist?(filename)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    $game_system.se_play($data_system.load_se)
    file = File.open(filename, "rb")
    read_save_data(file)
    file.close
    $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 on_cancel
    $game_system.se_play($data_system.cancel_se)
    $scene = Scene_Menu.new(7)
  end

  def read_save_data(file)
    characters            = Marshal.load(file)
    Graphics.frame_count  = Marshal.load(file)
    $game_system          = Marshal.load(file)
    $game_switches        = Marshal.load(file)
    $game_variables       = Marshal.load(file)
    $game_self_switches   = Marshal.load(file)
    $game_screen          = Marshal.load(file)
    $game_actors          = Marshal.load(file)
    $game_party           = Marshal.load(file)
    $game_troop           = Marshal.load(file)
    $game_map             = Marshal.load(file)
    $game_player          = Marshal.load(file)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh
  end
  
end
Jens of Zanicuud
Okay, paste this below your script, without erasing the previous one I've sent you.
Just paste the scripts this way:

StormTronics Custom Menu System by Blizzard Version: 4.4b - Nemesis Edition
Jens of Zanicuud autosave v 1.0
Jens of Zanicuud autosave patch v 1.0 (i.e. this script)
...
Main

I'm almost sure it will work (I hope so).

CODE
#===============================================================================
# ** Jens of Zanicuud autosave script patch v 1.0
# - free use, just credit
# - free customization, just PM me the modified version
# - you can fin me on www.rpgrevolution.com
#===============================================================================
class Scene_NewLoad < Scene_File
  alias joz3_old_on_decision on_decision
  def on_decision(filename)
    joz3_old_on_decision(filename)
    $game_system.last_index = @file_index
  end
end

class Scene_NewSave < Scene_File
  alias joz3_old_on_decision on_decision
  def on_decision(filename)
    $game_system.last_index = @file_index
     joz3_old_on_decision(filename)
  end
end


Jens
LostSamurai
Beautiful! Your scripting capabilities are very impressive, and I am extremely grateful for your help smile.gif
Jens of Zanicuud
QUOTE (LostSamurai @ Feb 24 2012, 05:34 PM) *
Beautiful! Your scripting capabilities are very impressive, and I am extremely grateful for your help smile.gif


You're welcome smile.gif
I'm only a spare-time-scripter who has a three years experience, though.
Let's say I'm just a curious freelance who is constantly looking for new challenges.

Jens
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.