Code:
#==============================================================================
# ** เซฟหลายช่อง (Multiple_Save_Slots)
#------------------------------------------------------------------------------
# * โดย: jojo741963
# * เวอร์ชั่น: 1.0
# 29-11-2016
#------------------------------------------------------------------------------
# รายละเอียดของสคริปต์นี้ :
# - เซฟมากกว่า 4 ช่องได้
#------------------------------------------------------------------------------
# วิธีการใช้งานสคริปต์นี้ :
# วางสคริปต์นี้เหนือสคริปต์ Main และใต้สคริปต์ Scene_Debug
# แล้วเซ็ตค่าได้ด่านล่างเลยครับ
#------------------------------------------------------------------------------
# ความเข้ากันได้ :
# อาจจะเกิดปัญหาได้กับสคิรปต์ที่มีการเขียนทับ Scene_Title, Window_SaveFile และ
# Scene_File ได้ เพราะใช้วิธีการเขียนทับในการเขียนสคริปต์นี้
# แต่ก็อาจจะสามารถใช้ร่วมกันได้ หากผู้ใช้คัดลอกไปเฉพาะโค้ดเพิ่มเติมที่ผู้สร้างระบุไว้
# โค้ดในส่วนที่เพิ่มไปจะมี #ADD เขียนกำกับไว้อยู่
#==============================================================================
module MSS#Multiple_Save_Slots
#ช่องเซฟที่ต้องการ (ต้องไม่น้อยกว่า 4)
SLOTS = 8
end
class Scene_Title
#--------------------------------------------------------------------------
# - Main processing
#--------------------------------------------------------------------------
def main
# In case of aggressive test
if $BTEST
battle_test
return
end
# Loading the database
$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")
# Drawing up system object
$game_system = Game_System.new
# Drawing up title graphics
@sprite = Sprite.new
@sprite.bitmap = RPG::Cache.title($data_system.title_name)
# Drawing up the command window
s1 = "New Game"
s2 = "Continue"
s3 = "Shutdown"
@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
# Continuing effective decision
# You inspect whether or not the saving file exists even at one
# If validity if @continue_enabled true, invalidity it makes false
@continue_enabled = false
for i in 0..MSS::SLOTS-1 #ADD
if FileTest.exist?("Save#{i+1}.rxdata")
@continue_enabled = true
end
end
# When continuing is effective, cursor is adjusted to continuing
# In invalid case, letter of continuing is made grey indication
if @continue_enabled
@command_window.index = 1
else
@command_window.disable_item(1)
end
# Performing title BGM
$game_system.bgm_play($data_system.title_bgm)
# Stopping the performance of ME and BGS
Audio.me_stop
Audio.bgs_stop
# Transition execution
Graphics.transition
# Main loop
loop do
# Renewing the game picture
Graphics.update
# Updating the information of input
Input.update
# Frame renewal
update
# When the picture changes, discontinuing the loop
if $scene != self
break
end
end
# Transition preparation
Graphics.freeze
# Releasing the command window
@command_window.dispose
# Releasing title graphics
@sprite.bitmap.dispose
@sprite.dispose
end
end
#==============================================================================
# * Window_SaveFile
#------------------------------------------------------------------------------
# It indicates in the saving picture and the load picture, it is the window of the saving file.
#==============================================================================
class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# - Open instance variable
#--------------------------------------------------------------------------
attr_reader :filename # File name
attr_reader :selected # Selective state
#--------------------------------------------------------------------------
# - Object initialization
# file_index : Index of saving file (0 - 3)
# filename : File name
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % MSS::SLOTS * 104, 640, 104) #ADD
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"
@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)
@game_system = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
file.close
end
refresh
@selected = false
end
end
#==============================================================================
# * Scene_File
#------------------------------------------------------------------------------
# It is superclass of the saving picture and the load picture.
#==============================================================================
class Scene_File
def main
# Drawing up the help window
@help_window = Window_Help.new
@help_window.set_text(@help_text)
# Drawing up the saving file window
@savefile_windows = []
for i in 0..MSS::SLOTS-1
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
end
# Selecting the file which was operated lastly
#ADD
@top_index = 0
@bottom_index = 3
@file_index = $game_temp.last_file_index
@savefile_windows[@file_index].selected = true
#ADD
set_window_from_start if @file_index > 0
# Transition execution
Graphics.transition
# Main loop
loop do
# Renewing the game picture
Graphics.update
# Updating the information of input
Input.update
# Frame renewal
update
# When the picture changes, discontinuing the loop
if $scene != self
break
end
end
# Transition preparation
Graphics.freeze
# Releasing the window
@help_window.dispose
for i in @savefile_windows
i.dispose
end
end
#--------------------------------------------------------------------------
# - Frame renewal
#--------------------------------------------------------------------------
def update
# Renewing the window
@help_window.update
for i in @savefile_windows
i.update
end
# When C button is pushed
if Input.trigger?(Input::C)
# Method on_decision (definition ahead succeeding) it calls
on_decision(make_filename(@file_index))
$game_temp.last_file_index = @file_index
return
end
# The B when button is pushed
if Input.trigger?(Input::B)
# od on_cancel (definition ahead succeeding) it calls
on_cancel
return
end
# When the bottom of the direction button is pushed
if Input.repeat?(Input::DOWN)
# Depression state under the direction button is not repeat when
# Or when cursor position it is before from 3
if Input.trigger?(Input::DOWN) or @file_index < MSS::SLOTS-1
# Performing cursor SE
$game_system.se_play($data_system.cursor_se)
# Moving cursor under
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + 1) % MSS::SLOTS
@savefile_windows[@file_index].selected = true
#ADD
check_move_window
return
end
end
# When the top of the direction button is pushed
if Input.repeat?(Input::UP)
# Depression state on the direction button is not repeat when
# Or when cursor position it is rear from 0
if Input.trigger?(Input::UP) or @file_index > 0
# Performing cursor SE
$game_system.se_play($data_system.cursor_se)
# Moving cursor on
@savefile_windows[@file_index].selected = false
@file_index = (@file_index + MSS::SLOTS-1) % MSS::SLOTS
@savefile_windows[@file_index].selected = true
#ADD
check_move_window
return
end
end
end
#ADD
def check_move_window
if @file_index > @bottom_index
@bottom_index = @file_index
@top_index = @bottom_index - 3
move_window_up
end
if @file_index < @top_index
@top_index = @file_index
@bottom_index = @top_index + 3
move_window_down
end
if @file_index == 0
@top_index = 0
@bottom_index = 3
set_window
end
if @file_index == MSS::SLOTS-1
@bottom_index = MSS::SLOTS-1
@top_index = @bottom_index - 3
set_window_from_bottom
end
check_visible
end
def check_visible
for i in 0..MSS::SLOTS-1
if i.between?(@top_index, @bottom_index)
@savefile_windows[i].visible = true
else
@savefile_windows[i].visible = false
end
end
end
def move_window_up
for i in @savefile_windows
i.y -= 104
end
end
def move_window_down
for i in @savefile_windows
i.y += 104
end
end
def set_window
for i in @savefile_windows
i.dispose
end
@savefile_windows = []
for i in 0..MSS::SLOTS-1
@savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
end
@savefile_windows[@file_index].selected = true
end
def set_window_from_bottom
set_window
for i in 1..@top_index
move_window_up
end
end
def set_window_from_start
if @file_index >= MSS::SLOTS-4
@top_index = MSS::SLOTS-4
@bottom_index = MSS::SLOTS-1
set_window_from_bottom
else
@top_index = @file_index
@bottom_index = @top_index + 3
for i in 1..@top_index
move_window_up
end
end
check_visible
end
end