Szyu

Local Switches & Variables

Aug 22nd, 2013
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.46 KB | None | 0 0
  1. #==============================================================================
  2. # Local Switches and Variables
  3. # Version 1.1
  4. # By Szyu
  5. #
  6. # About:
  7. # Use local variables and switches for each map, while holding the normal
  8. # ones for global event triggering
  9. #
  10. # Instructions:
  11. # - Place below "▼ Materials" but above "▼ Main Process".
  12. #
  13. # How to Use:
  14. # - Event -> "Script..." ->
  15. #   "$local_switches[switch_id] = true|false"
  16. #   "$local_switches.set(map_id, switch_id, value)"
  17. #   "$local_switches[switch_id] => returns the value of the local switch
  18. #   "$local_switches.get(map_id, switch_id) => returns the value of the
  19. #                                             local switch on map map_id
  20. # - Same goes for local variables
  21. #
  22. # Requires:
  23. # - RPG Maker VX Ace
  24. #
  25. # Terms of Use:
  26. # - Free for commercal and non-commercial use. Please list me
  27. #   in the credits to support my work.
  28. #
  29. # Pastebin:
  30. # http://adf.ly/UP832
  31. #
  32. #==============================================================
  33. #==============================================================
  34. #   * Alias Map Using
  35. #==============================================================
  36. class Game_Map
  37.   attr_accessor :local_switches
  38.   attr_accessor :local_variables
  39.  
  40.   alias locale_switch_variable_init initialize
  41.   alias locale_switch_variable_setup setup
  42.  
  43.   def initialize
  44.     locale_switch_variable_init
  45.     @local_switches = {}
  46.     @local_variables = {}
  47.   end
  48.  
  49.   def setup(map_id)
  50.     locale_switch_variable_setup(map_id)
  51.     @local_switches[map_id] = [] if !@local_switches[map_id]
  52.     @local_variables[map_id] = [] if !@local_variables[map_id]
  53.   end
  54.  
  55. end
  56.  
  57. #==============================================================
  58. #   * Alias Object Creation
  59. #==============================================================
  60. module DataManager
  61.   class << self
  62.     alias sz_loc_switch_variable create_game_objects
  63.   end
  64.  
  65.   def self.create_game_objects
  66.     sz_loc_switch_variable
  67.     $local_switches = Local_Switches.new
  68.     $local_variables = Local_Variables.new
  69.   end
  70. end
  71.  
  72. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. #==============================================================
  74. #   * Local_Switches
  75. #==============================================================
  76. class Local_Switches
  77.  
  78.   def [](switch_id)
  79.     $game_map.local_switches[$game_map.map_id][switch_id] || false
  80.   end
  81.  
  82.   def []=(switch_id, value)
  83.     $game_map.local_switches[$game_map.map_id][switch_id] = value
  84.     on_change
  85.   end
  86.  
  87.   def set(map_id, switch_id, value)
  88.     $game_map.local_switches[map_id][switch_id] = value
  89.     on_change
  90.   end
  91.  
  92.   def get(map_id, switch_id)
  93.     $game_map.local_switches[map_id][switch_id] || false
  94.   end
  95.  
  96.   def on_change
  97.     $game_map.need_refresh = true
  98.   end
  99. end
  100.  
  101. #==============================================================
  102. #   * Local_Variables
  103. #==============================================================
  104. class Local_Variables
  105.  
  106.   def [](variable_id)
  107.     $game_map.local_variables[$game_map.map_id][variable_id] || 0
  108.   end
  109.  
  110.   def []=(variable_id, value)
  111.     $game_map.local_variables[$game_map.map_id][variable_id] = value
  112.     on_change
  113.   end
  114.  
  115.   def set(map_id, variable_id, value)
  116.     $game_map.local_variables[map_id][variable_id] = value
  117.     on_change
  118.   end
  119.  
  120.   def get(map_id, variable_id)
  121.     $game_map.local_variables[map_id][variable_id] || 0
  122.   end
  123.  
  124.   def on_change
  125.     $game_map.need_refresh = true
  126.   end
  127. end
Add Comment
Please, Sign In to add comment