- 1,224
- Posts
- 11
- Years
- Omnipresence
- Seen Aug 8, 2023
In Scene_Map, under def update , add this inside the loop (being inside the loop is very important)
This is what actually keeps track of the time and calls the save.
It uses a couple variables, so we need to set those. In class PokemonGlobalMetadata, we add these along with the other accessors
and then set them in the class' initialize function (def initialize)
This sets the autosave on, and its timer to 300 seconds.
To allow the player to change this on and off, and to change the time, we'll add this option to PokemonOptions in class PokemonOptionScene
This should be pretty obvious where it goes.
Very last step, add this to PokemonSave under def pbSave
This will save the game for the player in a separate file "Game_autosave" in the same place as the regular save, so that the user can easily change the name and use it as their main save. You can also easily add in a couple lines to save it as a regular files as well, or replace "if pbAutoSave" to "if pbSave" to have it only save normally.
Note that this will not work unless you start a new game, since the it has to initialize the PokemonGlobalMetadata class, which it only does when you start a new game.
This goes by your computer's clock, so it will count regular seconds even for things like FL's Unreal Time System.
If syntax errors(edit: there are, at least in Chrome), use Show Printable Version under Thread Tools to get unformatted text.
Also, you might have to add a $scene=Scene_Map.new to several pbEndScene methods to force it to start again. Not sure how what this part affects in gameplay, or that it is necessary.
Spoiler:
Code:
#------------------------------------------------------------------------------
# Autosave. When ending a scene, make sure to reset the scene map($scene=Scene_Map.new)
#autosavetimer runs in seconds.
#------------------------------------------------------------------------------
if $PokemonGlobal.autosave
if !@autotimer || @autotimer<=0
@autotimer=0
end
if !@timer
@timer=Time.now
@[email protected]
end
newtime=Time.now
if newtime.sec==(@currentsec+1) || newtime.sec==0
@autotimer+=1
@currentsec=newtime.sec
end
@currentsec=@currentsec
if @autotimer==$PokemonGlobal.autosavetimer
Kernel.pbMessage(pbAutoSave ? _INTL("{1} saved the game",$Trainer.name) : _INTL("Save failed."))
@autotimer=0
end
end
#------------------------------------------------------------------------------
This is what actually keeps track of the time and calls the save.
It uses a couple variables, so we need to set those. In class PokemonGlobalMetadata, we add these along with the other accessors
Code:
attr_accessor :autosave
attr_accessor :autosavetimer
and then set them in the class' initialize function (def initialize)
Code:
@autosave = true
@autosavetimer = 300
To allow the player to change this on and off, and to change the time, we'll add this option to PokemonOptions in class PokemonOptionScene
Spoiler:
Code:
EnumOption.new(_INTL("Autosave"),[_INTL("On"),_INTL("False")],
proc { $PokemonSystem.autosave },
proc {|value|
$PokemonSystem.autosave=value
if value==0
if $PokemonGlobal.autosave==false
params=ChooseNumberParams.new
params.setRange(1,60)
params.setInitialValue(5)
params.setCancelValue(5)
savetime=Kernel.pbMessageChooseNumber(
_INTL("How many minutes between autosaves? (1-60)"),params
)
$PokemonGlobal.autosavetimer=savetime*60 #converts choice to seconds
end
$PokemonGlobal.autosave=true
else
$PokemonGlobal.autosave=false
end
}
),
Very last step, add this to PokemonSave under def pbSave
Spoiler:
Code:
def pbAutoSave(safesave=false)
begin
File.open(RTP.getSaveFileName("Game_autosave.rxdata"),"wb"){|f|
Marshal.dump($Trainer,f)
Marshal.dump(Graphics.frame_count,f)
if $data_system.respond_to?("magic_number")
$game_system.magic_number = $data_system.magic_number
else
$game_system.magic_number = $data_system.version_id
end
$game_system.save_count+=1
Marshal.dump($game_system,f)
Marshal.dump($PokemonSystem,f)
Marshal.dump($game_map.map_id,f)
Marshal.dump($game_switches,f)
Marshal.dump($game_variables,f)
Marshal.dump($game_self_switches,f)
Marshal.dump($game_screen,f)
Marshal.dump($MapFactory,f)
Marshal.dump($game_player,f)
$PokemonGlobal.safesave=safesave
Marshal.dump($PokemonGlobal,f)
Marshal.dump($PokemonMap,f)
Marshal.dump($PokemonBag,f)
Marshal.dump($PokemonStorage,f)
}
Graphics.frame_reset
rescue
return false
end
return true
end
This will save the game for the player in a separate file "Game_autosave" in the same place as the regular save, so that the user can easily change the name and use it as their main save. You can also easily add in a couple lines to save it as a regular files as well, or replace "if pbAutoSave" to "if pbSave" to have it only save normally.
Note that this will not work unless you start a new game, since the it has to initialize the PokemonGlobalMetadata class, which it only does when you start a new game.
This goes by your computer's clock, so it will count regular seconds even for things like FL's Unreal Time System.
If syntax errors(edit: there are, at least in Chrome), use Show Printable Version under Thread Tools to get unformatted text.
Also, you might have to add a $scene=Scene_Map.new to several pbEndScene methods to force it to start again. Not sure how what this part affects in gameplay, or that it is necessary.
Last edited: