Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # kode-xchange/lib/variable_store.rb
- # by IceDragon
- # Due to limitations in the RGSS3 Player, (finalizers are not called when
- # the player closes the Game Window)
- # You should place:
- # DataManager.save_system_variables
- # In a [Script Command] whenever you wish to save the current variables
- # STORE.
- #
- # EG.
- # After a cutscene event
- module VariableStore
- # add the variable_ids and switch_ids
- # you wish to save and restore regardless of game state
- # eg.
- # VARIABLES = [1, 2, 3, 4, 5, 6, 7]
- # SWITCHES = [1, 2, 3, 4, 5, 6, 7]
- SWITCHES = [ 1 ]
- VARIABLES = [ 1 ]
- end
- module DataManager
- class << self
- SYS_VAR_FILENAME = "save_glob.rvdata2"
- def save_system_variables
- var_hsh = Hash[VariableStore::VARIABLES.map { |v| [v, $game_variables[v]] }]
- swi_hsh = Hash[VariableStore::SWITCHES.map { |v| [v, $game_switches[v]] }]
- hsh = { variables: var_hsh, switches: swi_hsh }
- save_data(hsh, SYS_VAR_FILENAME)
- end
- def load_system_variables
- if File.exist?(SYS_VAR_FILENAME)
- hsh = load_data(SYS_VAR_FILENAME)
- hsh[:variables].each { |(k, v)| $game_variables[k] = v.to_i }
- hsh[:switches].each { |(k, v)| $game_switches[k] = v.to_i }
- end
- end
- alias :no_sys_var_create_game_objects :create_game_objects
- def create_game_objects(*args, &block)
- no_sys_var_create_game_objects(*args, &block)
- load_system_variables
- end
- alias :no_sys_var_save_game :save_game
- def save_game(*args, &block)
- no_sys_var_save_game(*args, &block)
- save_system_variables
- end
- end
- end
- class Scene_Gameover
- alias :no_sys_var_start :start
- def start
- no_sys_var_start
- DataManager.save_system_variables
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment