=begin
Game Custom Data Add-On : Persistent Variables and Switches
by AdiktuzMiko\
--- Version 1.10
--- Date Created: 01/09/2014
--- Last Date Updated: 05/13/2019
--- Level: Easy
Requires: Game Custom Data v1.22 (or newer)
==============================================================================
++ Installation ++
==============================================================================
Install this script in the Materials section in your project's
script editor.
Modify the ADIK::PERSISTENT_DATA module to include all switches and variables
that you want to persist
==============================================================================
++ Compatibility ++
==============================================================================
This script aliases the following default VXA methods:
DataManager#load_database
DataManager#create_game_objects
Game_Variables#[]=
Game_Switches#[]=
Scene_Title#start
==============================================================================
++ Terms and Conditions ++
==============================================================================
Read this: http://lescripts.wordpress.com/terms-and-conditions/
==============================================================================
=end
module ADIK
module PERSISTENT_DATA
#Switches that should be persistent
SWITCHES = [1,2,3,5]
#Variables that should be persistent
VARIABLES = [1,2,10,11]
end
end
#==============================================================================
# DO NOT EDIT BELOW THIS LINE
#==============================================================================
module DataManager
def self.initialize_persistent_s
$adik_custom_data[:persistent_switches] = {}
end
def self.initialize_persistent_v
$adik_custom_data[:persistent_variables] = {}
end
class <<self; alias create_game_objects_customdata create_game_objects; end
def self.create_game_objects
create_game_objects_customdata
initialize_persistent_s if $adik_custom_data[:persistent_switches].nil?
initialize_persistent_v if $adik_custom_data[:persistent_variables].nil?
CustomData.get(:persistent_switches).each {|key,value| $game_switches[key] = value} unless CustomData.get(:persistent_switches).empty?
CustomData.get(:persistent_variables).each {|key,value| $game_variables[key] = value} unless CustomData.get(:persistent_variables).empty?
end
end
class Game_Switches
alias set_switch_adik []=
def []=(switch_id, value)
set_switch_adik(switch_id, value)
if ADIK::PERSISTENT_DATA::SWITCHES.include?(switch_id)
DataManager.initialize_persistent_s if $adik_custom_data[:persistent_switches].nil?
x = $adik_custom_data[:persistent_switches][switch_id] = value
DataManager.save_customdata if ADIK::DATA::AUTOSAVE
end
end
end
class Game_Variables
alias set_variable_adik []=
def []=(variable_id, value)
set_variable_adik(variable_id, value)
if ADIK::PERSISTENT_DATA::VARIABLES.include?(variable_id)
DataManager.initialize_persistent_v if $adik_custom_data[:persistent_variables].nil?
x = $adik_custom_data[:persistent_variables][variable_id] = value
DataManager.save_customdata if ADIK::DATA::AUTOSAVE
end
end
end
Comments