améliorations des sauvegardes


1.Preparation

ce script vous permet d'améliorer le menu des sauvegardes :
- avoir plus de 4 emplacements de sauvegardes
-confirmation lorsqu'on veut sauvegarder sur une autre sauvegarde
-endroit ou l'on a sauvegardé

/!\ si vous avez installé l'option bonus 1.2 (ou 1.0) elle sera non utilisable !
contactez moi ( theopoom@hotmail.com) pour installez les 2 !

----------------------------------------------------------

allez dans l'éditeur de scripts (F11) ...
créez un script au dessus de "main" appelé "Save_Max" et ..........



2.Script

mettez dans le script le code ci-dessous :


#------------------------------------------------------------------------------
# ■ Save_Max
#------------------------------------------------------------------------------

module ExtraConstants
NB_SAVE_SLOTS = 20 #change this to change the number of save slots
MODE_SLOTS = 0 # change this to 1 if you prefer the other mode.
end

# Window_SaveFile
#------------------------------------------------------------------------------
#  セーブ画面およびロード画面で表示する、セーブファイルのウィンドウです。
#==============================================================================

class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader :filename # ファイル名
attr_reader :selected # 選択状態
#--------------------------------------------------------------------------
# ● オブジェクト初期化
# file_index : セーブファイルのインデックス (0~3)
# filename : ファイル名
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
@file_index = file_index
@filename = "Save#{@file_index + 1}.rxdata"
@game_party_leader = ""
#@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
# @time_stamp = file.mtime

@characters = Marshal.load(file)
@frame_count = Marshal.load(file)

@total_sec = @frame_count / Graphics.frame_rate

@game_party = Marshal.load(file)
@game_map_name = Marshal.load(file)

@game_party_leader = @game_party.actors[0].name

file.close
end

refresh
@selected = false

rescue
file.close
@selected = false
@file_exist = false
@game_party_leader = "Cette sauvegarde est corrompue - Choisissez une autre sauvegarde."
refresh
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# ファイル番号を描画
self.contents.font.color = normal_color

if @game_party_leader == ""
name = "File #{@file_index + 1}"
else
name = "File #{@file_index + 1} : " + @game_party_leader
end

self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# セーブファイルが存在する場合
if @file_exist
# キャラクターを描画
for i in 0...@characters.size
bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
end
# プレイ時間を描画
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(4, 8, 600, 32, time_string, 2)
# タイムスタンプを描画
self.contents.font.color = normal_color

self.contents.draw_text(4, 40, 600, 32, @game_map_name, 2)
end
end
#--------------------------------------------------------------------------
# ● 選択状態の設定
# selected : 新しい選択状態 (true=選択 false=非選択)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● カーソルの矩形更新
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end

#====================================================#==========================
# ■ Scene_Save
#------------------------------------------------------------------------------
#  セーブ画面の処理を行うクラスです。
#====================================================#==========================

class Scene_Save < Scene_File
# -----------------------------
def initialize
super("Voulez vous sauvegarder la partie ?")
@confirm_window = Window_Base.new(120, 188, 400, 64)
@confirm_window.contents = Bitmap.new(368, 32)
string = "Voulez vous remplacer cette sauvegarde ?"
@confirm_window.contents.font.name = "Arial"
@confirm_window.contents.font.size = $fontsize
@confirm_window.contents.draw_text(4, 0, 368, 32, string)
@yes_no_window = Window_Command.new(100, ["Oui", "Non"])
@confirm_window.visible = false
@confirm_window.z = 1500
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@yes_no_window.x = 270
@yes_no_window.y = 252
@yes_no_window.z = 1500
@mode = 0
end
# -----------------------------
def on_decision(filename)
if FileTest.exist?(filename)
@confirm_window.visible = true
@yes_no_window.visible = true
@yes_no_window.active = true
@mode = 1
else
$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(4)
end
end
# -----------------------------
def update
if @mode == 0
super
else
@help_window.update
@yes_no_window.update
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
if @yes_no_window.index == 0
filename = make_filename(@file_index)
$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
else
$scene = Scene_Menu.new(4)
end
else
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@mode = 0
end
end
if Input.trigger?(Input::B)
@confirm_window.visible = false
@yes_no_window.visible = false
@yes_no_window.active = false
@yes_no_window.index = 1
@mode = 0
return
end
end
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(4)
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_party, file)
Marshal.dump($game_map.name, file)

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_map, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_player, file)
end
end

#==============================================================================
# ■ Scene_Load
#------------------------------------------------------------------------------
#  ロード画面の処理を行うクラスです。
#==============================================================================

class Scene_Load < Scene_File
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
# テンポラリオブジェクトを再作成
$game_temp = Game_Temp.new
# タイムスタンプが最新のファイルを選択
$game_temp.last_file_index = 0
latest_time = Time.at(0)
for i in 0..NB_SAVE_SLOTS-1
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("Charger quelle partie ?")
end
#--------------------------------------------------------------------------
# ● 決定時の処理
#--------------------------------------------------------------------------
def on_decision(filename)
# ファイルが存在しない場合
unless FileTest.exist?(filename)
# ブザー SE を演奏
$game_system.se_play($data_system.buzzer_se)
return
end
# ロード SE を演奏
$game_system.se_play($data_system.load_se)
# セーブデータの書き込み
file = File.open(filename, "rb")
read_save_data(file)
file.close
# BGM、BGS を復帰
$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
# キャンセル SE を演奏
$game_system.se_play($data_system.cancel_se)
# タイトル画面に切り替え
$scene = Scene_Title.new
end
#--------------------------------------------------------------------------
# ● セーブデータの読み込み
# file : 読み込み用ファイルオブジェクト (オープン済み)
#--------------------------------------------------------------------------
def read_save_data(file)

characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)

$game_party = Marshal.load(file)
@game_map_name = 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_map = Marshal.load(file)

$game_troop = 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

#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
#  セーブ画面およびロード画面のスーパークラスです。
#==============================================================================

class Scene_File

include ExtraConstants

def initialize(help_text)

@help_text = help_text
@first_window
@last_window
@top_window
@bottom_window
end

#--------------------------------------------------------------------------
# ● メイン処理
#--------------------------------------------------------------------------
def main
# ヘルプウィンドウを作成
@help_window = Window_Help.new
@help_window.set_text(@help_text)
@top_window = 0
@bottom_window = NB_SAVE_SLOTS-1

@savefile_windows = []
for i in 0..NB_SAVE_SLOTS-1
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))

if i == 0 then
@first_window = i
elsif i == 3 then
@last_window = i
end
end

# 最後に操作したファイルを選択
@file_index = $game_temp.last_file_index
if @file_index > NB_SAVE_SLOTS-1 then
@file_index = 0
end

@savefile_windows[@file_index].selected = true

if @file_index >3 then
@last_window = @file_index
@first_window = @file_index - 3

for i in 0...@savefile_windows.size
@savefile_windows[i].y = @savefile_windows[i].y - (104 * (@file_index- 3) )
if i < @first_window then
@savefile_windows[i].visible = false
end
end
end

# トランジション実行
Graphics.transition
# メインループ
loop do
# ゲーム画面を更新
Graphics.update
# 入力情報を更新
Input.update
# フレーム更新
update
# 画面が切り替わったらループを中断
if $scene != self
break
end
end
# トランジション準備
Graphics.freeze
# ウィンドウを解放
@help_window.dispose
for i in @savefile_windows
i.dispose
end

if self.is_a?(Scene_Save)
@confirm_window.dispose
@yes_no_window.dispose
end
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
# ウィンドウを更新
@help_window.update

for i in @savefile_windows
i.update
end

# C ボタンが押された場合
if Input.trigger?(Input::C)
# メソッド on_decision (継承先で定義) を呼ぶ
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
# B ボタンが押された場合
if Input.trigger?(Input::B)
# メソッド on_cancel (継承先で定義) を呼ぶ
on_cancel
return
end

if Input.repeat?(Input::DOWN) or Input.trigger?(Input::DOWN)
# 方向ボタンの下の押下状態がリピートでない場合か、
# またはカーソル位置が 3 より前の場合
###
if @file_index == @last_window and @file_index == @bottom_window
if MODE_SLOTS == 1 then
$game_system.se_play($data_system.buzzer_se)
return
elsif NB_SAVE_SLOTS < 5 then
@savefile_windows[@file_index].selected = false
@file_index = 0
@savefile_windows[@file_index].selected = true
$game_system.se_play($data_system.cursor_se)
return
end

@savefile_windows[@top_window].y = @savefile_windows[@bottom_window].y + 104
@top_window = @top_window + 1
@bottom_window = @bottom_window + 1
if @bottom_window == NB_SAVE_SLOTS then
@bottom_window = 0
end

if @top_window == NB_SAVE_SLOTS then
@top_window = 0
end
end

if @file_index == @last_window
for i in @savefile_windows
i.y = i.y - 104
end
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false
@savefile_windows[@first_window].visible = false
@file_index = @file_index + 1
if @file_index == NB_SAVE_SLOTS then
@file_index = 0
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true

@first_window = @first_window + 1
@last_window = @last_window + 1

if @last_window == NB_SAVE_SLOTS then
@last_window = 0
end

if @first_window == NB_SAVE_SLOTS then
@first_window = 0
end
else
# カーソル SE を演奏
$game_system.se_play($data_system.cursor_se)
# カーソルを下に移動
@savefile_windows[@file_index].selected = false
@file_index = @file_index + 1
if @file_index == NB_SAVE_SLOTS then
@file_index = 0
end

@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true
return
end
end

if Input.repeat?(Input::UP) or Input.trigger?(Input::UP)
if @file_index == @first_window and @file_index == @top_window
if MODE_SLOTS == 1 then
$game_system.se_play($data_system.buzzer_se)
return
elsif NB_SAVE_SLOTS < 5 then
@savefile_windows[@file_index].selected = false
@file_index = NB_SAVE_SLOTS - 1
@savefile_windows[@file_index].selected = true
$game_system.se_play($data_system.cursor_se)
return
end

@savefile_windows[@bottom_window].y = @savefile_windows[@top_window].y - 104
@top_window = @top_window - 1
@bottom_window = @bottom_window - 1
if @bottom_window == -1 then
@bottom_window = NB_SAVE_SLOTS-1
end

if @top_window == -1 then
@top_window = NB_SAVE_SLOTS-1
end
end

if @file_index == @first_window
for i in @savefile_windows
i.y = i.y + 104
end
$game_system.se_play($data_system.cursor_se)
@savefile_windows[@file_index].selected = false

@file_index = @file_index - 1
if @file_index == -1 then
@file_index = NB_SAVE_SLOTS-1
end
@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true

@first_window = @first_window - 1
@last_window = @last_window - 1

if @last_window == -1 then
@last_window = NB_SAVE_SLOTS - 1
end

if @first_window == -1 then
@first_window = NB_SAVE_SLOTS-1
end
else
# カーソル SE を演奏
$game_system.se_play($data_system.cursor_se)
# カーソルを下に移動
@savefile_windows[@file_index].selected = false
@file_index = @file_index - 1
if @file_index == -1 then
@file_index = NB_SAVE_SLOTS - 1
end

@savefile_windows[@file_index].selected = true
@savefile_windows[@file_index].visible = true

return
end
end
end

#--------------------------------------------------------------------------
# ● ファイル名の作成
# file_index : セーブファイルのインデックス (0~3)
#--------------------------------------------------------------------------
def make_filename(file_index)
return "Save#{file_index + 1}.rxdata"
end
end

#==============================================================================
# Game_Map
#==============================================================================

class Game_Map
#--------------------------------------------------------------------------
def name
$map_infos[@map_id]
end
end

#==============================================================================
# Scene_Title
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
include ExtraConstants
def main
$map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys
$map_infos[key] = $map_infos[key].name
end

# 戦闘テストの場合
if $BTEST
battle_test
return
end
# データベースをロード
$data_actors = load_data("Data/Actors.rxdata")
$data_classes = load_data("Data/Classes.rxdata")
$data_skills = load_data("Data/Skills.rxdata")
$data_items = load_data("Data/Items.rxdata")
$data_weapons = load_data("Data/Weapons.rxdata")
$data_armors = load_data("Data/Armors.rxdata")
$data_enemies = load_data("Data/Enemies.rxdata")
$data_troops = load_data("Data/Troops.rxdata")
$data_states = load_data("Data/States.rxdata")
$data_animations = load_data("Data/Animations.rxdata")
$data_tilesets = load_data("Data/Tilesets.rxdata")
$data_common_events = load_data("Data/CommonEvents.rxdata")
$data_system = load_data("Data/System.rxdata")
# システムオブジェクトを作成
$game_system = Game_System.new
# タイトルグラフィックを作成
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# コマンドウィンドウを作成
s1 = "Nouvelle partie"
s2 = "Charger une partie"
s3 = "Quitter"
@command_window = Window_Command.new(192, [s1, s2, s3])
@command_window.back_opacity = 160
@command_window.x = 320 - @command_window.width / 2
@command_window.y = 288
# コンティニュー有効判定
# セーブファイルがひとつでも存在するかどうかを調べる
# 有効なら @continue_enabled を true、無効なら false にする
@continue_enabled = false
for i in 0..NB_SAVE_SLOTS
if FileTest.exist?("Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# コンティニューが有効な場合、カーソルをコンティニューに合わせる
# 無効な場合、コンティニューの文字をグレー表示にする
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# タイトル BGM を演奏
$game_system.bgm_play($data_system.title_bgm)
# ME、BGS の演奏を停止
Audio.me_stop
Audio.bgs_stop
# トランジション実行
Graphics.transition
# メインループ
loop do
# ゲーム画面を更新
Graphics.update
# 入力情報を更新
Input.update
# フレーム更新
update
# 画面が切り替わったらループを中断
if $scene != self
break
end
end
# トランジション準備
Graphics.freeze
# コマンドウィンドウを解放
@command_window.dispose
# タイトルグラフィックを解放
@sprite.bitmap.dispose
@sprite.dispose
end
end


vous avez dans les premières lignes (ligne 6) la ligne de code :

NB_SAVE_SLOTS = 20

changez juste le nombre 20 en le nombre de sauvegarde que vous voulez !!!