# * GlobalValues XP * #
# Scripter : Kyonides Arkanthes
# v0.3.0 - 2023-06-03
# This script creates a new Global Variable and stores values there for future
# use in all game sessions.
# It will update the battle result variables automatically if you are using
# a Battle System that is compatible enough with the Default BS.
# Stats like Wins, Escapes, Losses, Saves and Loads are already
# updated by the script automatically!
# * Script Calls * #
# - Access Wins:
# $global_data.wins
# - Access Escapes:
# $global_data.escapes
# - Access Losses:
# $global_data.losses
# - Access Total Saves:
# $global_data.saves
# - Access Total Loads:
# $global_data.loads
# - Access or Update Total Gameovers:
# $global_data.gameovers
# $global_data.gameover!
# - Access or Update the Switch:
# $global_data.switch
# $global_data.switch = true
# $global_data.switch = false
# * Optional - No Need for You to use them! * #
# - Create or Load the new Global Variable
# Global.load_file
# - Save Global Data at Any Moment
# Global.save_file
module Global
# PATH = "" means the Game's Root Directory (RD)
# PATH = "Saves" means the Saves Directory at the RD
PATH = ""
FILENAME = "GlobalValues.rxdata"
class Values
def initialize
@wins = 0
@escapes = 0
@losses = 0
@saves = 0
@loads = 0
@gameovers = 0
@switch = nil
end
def save_result(result)
case result
when 0
@wins += 1
when 1
@escapes += 1
when 2
@losses += 1
end
Global.save_file
end
def saved!
@saves += 1
Global.save_file
end
def loaded!
@loads += 1
Global.save_file
end
def gameover!
@gameovers += 1
Global.save_file
end
attr_accessor :wins, :escapes, :losses
attr_accessor :saves, :loads, :gameovers, :switch
end
extend self
def filename
if PATH.empty?
FILENAME
else
PATH + "/" + FILENAME
end
end
def save_file
save_data($global_data, filename)
end
def load_file
if File.exist?(filename)
$global_data = load_data(filename)
else
$global_data = Global::Values.new
save_file
end
end
load_file
end
class Scene_Save
alias :kyon_global_values_scn_sv_wsd :write_save_data
def write_save_data(file)
kyon_global_values_scn_sv_wsd(file)
$global_data.saved!
end
end
class Scene_Load
alias :kyon_global_values_scn_ld_rsd :read_save_data
def read_save_data(file)
kyon_global_values_scn_ld_rsd(file)
$global_data.loaded!
end
end
class Scene_Battle
alias :kyon_global_values_scn_btl_btl_end :battle_end
def save_global_data(result)
$global_data.save_result(result)
end
def battle_end(result)
save_global_data(result)
kyon_global_values_scn_btl_btl_end(result)
end
end