01-16-2007, 01:00 PM
My Saving system
by crystal
Jan 16 2007
Here are the edits you need:
And your done! Any questions, just reply.
~Tim
by crystal
Jan 16 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
Updates
Retry System should work
Added Scene_End edit - 16/03/07
Replaced all the scripts in Code boxes after the CA2 move - 19/03/07
Replaced all the scripts after a few edits - 19/03/07
Added Scene_End edit - 16/03/07
Replaced all the scripts in Code boxes after the CA2 move - 19/03/07
Replaced all the scripts after a few edits - 19/03/07
About
This is a multi-system script edit with a old but new saving system.
what it does is this:
When you load up 'New game' on the title, it shows the save screen. You choose witch slot you want to save in, and when ever you save, you save in that slot again. Almost like an auto-save system, but not that convenient.
It also works slightly like a auto-load system. On the gameover screen you can choose to 'retry/continue', this loads the save that you had made.
This requires no new scripts, and only one or two edits, and a whole bunch of code lines to put in. This is a very simple edit and works with these scripts: Dube's Ring Menu, and Sonicia's CTS (well, he found it, I edit it).
what it does is this:
When you load up 'New game' on the title, it shows the save screen. You choose witch slot you want to save in, and when ever you save, you save in that slot again. Almost like an auto-save system, but not that convenient.
It also works slightly like a auto-load system. On the gameover screen you can choose to 'retry/continue', this loads the save that you had made.
This requires no new scripts, and only one or two edits, and a whole bunch of code lines to put in. This is a very simple edit and works with these scripts: Dube's Ring Menu, and Sonicia's CTS (well, he found it, I edit it).
Request for you all
I found a bug or rather something I want to get done.
On the title, when It calls the Save_Menu script, I want it to be able to show that something has already be written there (shows the time played, gold, players etc)
and if the user still selects the one where stuff already exists, then its prompts you if you want to overwrite it.
Any help in the matter?
On the title, when It calls the Save_Menu script, I want it to be able to show that something has already be written there (shows the time played, gold, players etc)
and if the user still selects the one where stuff already exists, then its prompts you if you want to overwrite it.
Any help in the matter?
Here are the edits you need:
Scene_Save
After:Put this in:
Code:
write_save_data(file)
Code:
$save_slot = filename #Edit
Scene_Load
Replace the "on_decision" method with this one:
Code:
def on_decision(filename)
# Tests if the save exists
unless FileTest.exist?(filename)
# Plays SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Plays SE
$game_system.se_play($data_system.load_se)
# If there is no save, then open the selected save, if there is, then load that
if $save_slot = nil
file = File.open(filename, "rb")
else
file = File.open($save_slot, "rb")
end
read_save_data(file)
file.close
# Play BGM and BGS
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
# Update Map
$game_map.update
# Call Map
$scene = Scene_Map.new
end
Scene_Gameover
Replace your whole script with this, its just edits, but theres so many, it would take ages to list them. If you have another game over system already, you could just pick through it.
Code:
#==============================================================================
# ■ Scene_Gameover
#------------------------------------------------------------------------------
# ゲームオーバー画面の処理を行うクラスです。
#==============================================================================
class Scene_Gameover
#--------------------------------------------------------------------------
# ● メイン処理
#--------------------------------------------------------------------------
def main
#lose_gold(999999999999999)
#Commands
s1 = "Continue/Retry"
s2 = "Return to Title"
s3 = "Quit"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.x = 470 - @command_window.width / 2
@command_window.y = 390 - @command_window.height / 2
# トランジション実行
Graphics.transition
# ゲームオーバーグラフィックを作成
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.gameover($data_system.gameover_name)
# BGM、BGS を停止
$game_system.bgm_play(nil)
$game_system.bgs_play(nil)
# ゲームオーバー ME を演奏
$game_system.me_play($data_system.gameover_me)
#Execute transition
Graphics.transition(120)
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of game over graphic
@sprite.bitmap.dispose
@sprite.dispose
# Execute transition
Graphics.transition(40)
# Prepare for transition
Graphics.freeze
# If battle test
if $BTEST
$scene = nil
end
# Prepare for transition
Graphics.freeze
# Dispose of command window
@command_window.dispose
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
# Update command window
@command_window.update
if Input.trigger?(Input::C)
# コマンドウィンドウのカーソル位置で分岐
case @command_window.index
when 0 # タイトルへ
command_retry
when 1 # シャットダウン
command_to_title
when 2 # やめる
command_shutdown
end
return
end
end
end
#--------------------------------------------------------------------------
# ● Read Save Data Method
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# ● Command_retry
#--------------------------------------------------------------------------
def command_retry
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Fade Music
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Load save in slot
file = File.open($save_slot, "rb")
read_save_data(file)
file.close
# Call Map
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ● Command_to_title
#--------------------------------------------------------------------------
def command_to_title
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Fade Music
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Call Title Screen
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# ● Command_shutdown
#--------------------------------------------------------------------------
def command_shutdown
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Fade Music
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
# Destroy all scenes
$scene = nil
end
Scene_Title
Find the command method where it starts a new game, around the end of the method you will find that it calls Scene_Map. ($scene = Scene_Map)
Insert this code just after it:
Insert this code just after it:
Code:
#-------------Edit------------
# Open save window
$scene = Scene_Save.new
#-------------Edit------------
Dube's Ring Menu. Not required, and it still works with other systems
Ok, for all you non-users of the Ring Menu, this is still possible, but you have to understand your 'Scene_Menu' script a bit better. Reply with a link to the scripts of your menu system and I will guide you through it (if you don't know how)
I'll take the Ring menu users through this first:
After Main has been defined, (line 167) you should enter in these:
enter in this small line, at line 258:
Next you will need to add a icon to the ring menu. If you do not know how to do this, look at Dube's ring menu topic or reply here asking how.
(make it number 6 in your list so 'when 5' is now your section of code for the load option.)
then scroll down to the new line 304, where it should say:
I'll take the Ring menu users through this first:
After Main has been defined, (line 167) you should enter in these:
Code:
#--------------------------------------------------------------------------
# Write Save Data Method
#--------------------------------------------------------------------------
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)
# セーブ回数を 1 増やす
$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
#--------------------------------------------------------------------------
# Load Save Data Method
#--------------------------------------------------------------------------
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
enter in this small line, at line 258:
Code:
if loaded = true
Graphics.transition(20)
loaded = nil
end
(make it number 6 in your list so 'when 5' is now your section of code for the load option.)
then scroll down to the new line 304, where it should say:
Code:
when 4 # Save
# If save disabled
if $game_system.save_disabled
$game_system.se_play($data_system.buzzer_se)
return
end
file = File.open($save_slot, "wb")
write_save_data(file)
file.close
$game_system.se_play($data_system.save_se)
$scene = Scene_Map.new
when 5 # Load
file = File.open($save_slot, "rb")
read_save_data(file)
file.close
$game_system.se_play($data_system.load_se)
$scene = Scene_Map.new
loaded = true
when 6 # End
$game_system.se_play($data_system.decision_se)
$scene = Scene_End.new
And your done! Any questions, just reply.
~Tim