Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Local Switches and Variables
- # Version 1.1
- # By Szyu
- #
- # About:
- # Use local variables and switches for each map, while holding the normal
- # ones for global event triggering
- #
- # Instructions:
- # - Place below "▼ Materials" but above "▼ Main Process".
- #
- # How to Use:
- # - Event -> "Script..." ->
- # "$local_switches[switch_id] = true|false"
- # "$local_switches.set(map_id, switch_id, value)"
- # "$local_switches[switch_id] => returns the value of the local switch
- # "$local_switches.get(map_id, switch_id) => returns the value of the
- # local switch on map map_id
- # - Same goes for local variables
- #
- # Requires:
- # - RPG Maker VX Ace
- #
- # Terms of Use:
- # - Free for commercal and non-commercial use. Please list me
- # in the credits to support my work.
- #
- # Pastebin:
- # http://adf.ly/UP832
- #
- #==============================================================
- #==============================================================
- # * Alias Map Using
- #==============================================================
- class Game_Map
- attr_accessor :local_switches
- attr_accessor :local_variables
- alias locale_switch_variable_init initialize
- alias locale_switch_variable_setup setup
- def initialize
- locale_switch_variable_init
- @local_switches = {}
- @local_variables = {}
- end
- def setup(map_id)
- locale_switch_variable_setup(map_id)
- @local_switches[map_id] = [] if !@local_switches[map_id]
- @local_variables[map_id] = [] if !@local_variables[map_id]
- end
- end
- #==============================================================
- # * Alias Object Creation
- #==============================================================
- module DataManager
- class << self
- alias sz_loc_switch_variable create_game_objects
- end
- def self.create_game_objects
- sz_loc_switch_variable
- $local_switches = Local_Switches.new
- $local_variables = Local_Variables.new
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #==============================================================
- # * Local_Switches
- #==============================================================
- class Local_Switches
- def [](switch_id)
- $game_map.local_switches[$game_map.map_id][switch_id] || false
- end
- def []=(switch_id, value)
- $game_map.local_switches[$game_map.map_id][switch_id] = value
- on_change
- end
- def set(map_id, switch_id, value)
- $game_map.local_switches[map_id][switch_id] = value
- on_change
- end
- def get(map_id, switch_id)
- $game_map.local_switches[map_id][switch_id] || false
- end
- def on_change
- $game_map.need_refresh = true
- end
- end
- #==============================================================
- # * Local_Variables
- #==============================================================
- class Local_Variables
- def [](variable_id)
- $game_map.local_variables[$game_map.map_id][variable_id] || 0
- end
- def []=(variable_id, value)
- $game_map.local_variables[$game_map.map_id][variable_id] = value
- on_change
- end
- def set(map_id, variable_id, value)
- $game_map.local_variables[map_id][variable_id] = value
- on_change
- end
- def get(map_id, variable_id)
- $game_map.local_variables[map_id][variable_id] || 0
- end
- def on_change
- $game_map.need_refresh = true
- end
- end
Add Comment
Please, Sign In to add comment