adiktuzmiko

Custom Game Data Add-On : Persistent Data v1.10

Jan 8th, 2014
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.33 KB | None | 0 0
  1. =begin
  2.  Game Custom Data Add-On : Persistent Variables and Switches
  3.  by AdiktuzMiko\
  4.  --- Version 1.10
  5.  --- Date Created: 01/09/2014
  6.  --- Last Date Updated: 05/13/2019
  7.  --- Level: Easy
  8.  Requires: Game Custom Data v1.22 (or newer)
  9.  
  10.  ==============================================================================
  11.    ++ Installation ++
  12.  ==============================================================================
  13.  
  14.    Install this script in the Materials section in your project's
  15.    script editor.
  16.  
  17.    Modify the ADIK::PERSISTENT_DATA module to include all switches and variables
  18.    that you want to persist
  19.  ==============================================================================
  20.    ++ Compatibility ++
  21.  ==============================================================================
  22.    This script aliases the following default VXA methods:
  23.  
  24.      DataManager#load_database
  25.      DataManager#create_game_objects
  26.      Game_Variables#[]=
  27.      Game_Switches#[]=
  28.      Scene_Title#start
  29.    
  30.  ==============================================================================
  31.    ++ Terms and Conditions ++
  32.  ==============================================================================
  33.  
  34.  Read this: http://lescripts.wordpress.com/terms-and-conditions/
  35.  
  36.  ==============================================================================
  37. =end
  38.  
  39. module ADIK
  40.   module PERSISTENT_DATA
  41.     #Switches that should be persistent
  42.     SWITCHES = [1,2,3,5]
  43.     #Variables that should be persistent
  44.     VARIABLES = [1,2,10,11]
  45.   end
  46. end
  47.  
  48. #==============================================================================
  49. # DO NOT EDIT BELOW THIS LINE
  50. #==============================================================================
  51.  
  52. module DataManager
  53.  
  54.   def self.initialize_persistent_s
  55.     $adik_custom_data[:persistent_switches] = {}
  56.   end
  57.  
  58.   def self.initialize_persistent_v
  59.     $adik_custom_data[:persistent_variables] = {}
  60.   end
  61.  
  62.   class <<self; alias create_game_objects_customdata create_game_objects; end
  63.   def self.create_game_objects
  64.     create_game_objects_customdata
  65.     initialize_persistent_s if $adik_custom_data[:persistent_switches].nil?
  66.     initialize_persistent_v if $adik_custom_data[:persistent_variables].nil?
  67.     CustomData.get(:persistent_switches).each {|key,value| $game_switches[key] = value} unless CustomData.get(:persistent_switches).empty?
  68.     CustomData.get(:persistent_variables).each {|key,value| $game_variables[key] = value} unless CustomData.get(:persistent_variables).empty?
  69.   end
  70.  
  71.  
  72. end
  73.  
  74. class Game_Switches
  75.   alias set_switch_adik []=
  76.   def []=(switch_id, value)
  77.     set_switch_adik(switch_id, value)
  78.     if ADIK::PERSISTENT_DATA::SWITCHES.include?(switch_id)
  79.       DataManager.initialize_persistent_s if $adik_custom_data[:persistent_switches].nil?
  80.       x = $adik_custom_data[:persistent_switches][switch_id] = value
  81.       DataManager.save_customdata if ADIK::DATA::AUTOSAVE
  82.     end
  83.   end
  84.  end
  85.  
  86.  class Game_Variables
  87.   alias set_variable_adik []=
  88.   def []=(variable_id, value)
  89.     set_variable_adik(variable_id, value)
  90.     if ADIK::PERSISTENT_DATA::VARIABLES.include?(variable_id)
  91.       DataManager.initialize_persistent_v if $adik_custom_data[:persistent_variables].nil?
  92.       x = $adik_custom_data[:persistent_variables][variable_id] = value
  93.       DataManager.save_customdata if ADIK::DATA::AUTOSAVE
  94.     end
  95.   end
  96.  end
Advertisement
Add Comment
Please, Sign In to add comment