#═╦═════════════════════════════════════════════════════════════════════════════ # ║ § Event Memory (1.0) by Solistra [License: CC BY-SA 3.0] # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Change Log #─╫───────────────────────────────────────────────────────────────────────────── # ║ v1.0 (December 29th, 2012) - Initial release # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Summary #─╫───────────────────────────────────────────────────────────────────────────── # ║ This script allows events to remember their positions on the map, even # ║ through map changes. This script also provides a way to permanently erase # ║ events (unlike the VX Ace default, which only erases events temporarily). # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Required Scripts #─╫───────────────────────────────────────────────────────────────────────────── # ║ None. # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Known Incompatibilities #─╫───────────────────────────────────────────────────────────────────────────── # ║ None. # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Installation #─╫───────────────────────────────────────────────────────────────────────────── # ║ Place this script below Materials, but above Main -- preferably relatively # ║ high in your list of custom scripts. # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Configuration #─╫───────────────────────────────────────────────────────────────────────────── # ║ This script only has three very simple customization options: REMEMBER_ALL, # ║ REMEMBER_TAG, and EXCLUDE_TAG. The REMEMBER_ALL constant may be set to one # ║ of "true" or "false" (without quotes). If it is true, all events will have # ║ their positions remembered automatically unless otherwise excluded -- if it # ║ is false, events will only remember their positions if explicitly told to # ║ do so. # ║ # ║ You can also configure the tags used to determine whether or not an event # ║ should remember its position with the REMEMBER_TAG and EXCLUDE_TAG options. # ║ An event is tagged if it includes the value of one of these constants in its # ║ name. # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Script Calls #─╫───────────────────────────────────────────────────────────────────────────── # ║ To permanently erase an event, use the erase! method like so: # ║ $game_map.events[event_id].erase! # ║ # ║ You can also check if an event has been erased or permanently erased with # ║ the script calls erased? or permanently_erased? respectively. # ║ # ║ In addition to this, you can also restore an event that has been previously # ║ erased (whether permanently or otherwise) with the restore method: # ║ $game_map.events[event_id].restore # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § Aliased Methods #─╫───────────────────────────────────────────────────────────────────────────── # ║ ● Game_System # ║ initialize # ║ ● Game_Map # ║ setup_events # ║ ● Game_Event # ║ initialize # ║ ● Scene_Map # ║ pre_transfer # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ § New Methods #─╫───────────────────────────────────────────────────────────────────────────── # ║ ● Game_Event # ║ restore # ║ erase! # ║ erased? # ║ permanently_erased? # ║ name # ║ #═╬═════════════════════════════════════════════════════════════════════════════ # ║ ▼ module SES::Event_Extension #═╩═════════════════════════════════════════════════════════════════════════════ module SES module Event_Memory #═╦═══════════════════════════════════════════════════════════════════════════ # ║ α BEGIN CONFIGURATION #═╩═══════════════════════════════════════════════════════════════════════════ # Set this to "true" if you want the variables of all events to be stored by # default. REMEMBER_ALL = true # Tag events to remember if REMEMBER_ALL has been set to "false" by including # this string in the event's name. REMEMBER_TAG = "" # Likewise, tag events to exclude from memory if REMEMBER_ALL has been set to # "true" with this string. EXCLUDE_TAG = "" #═╦═══════════════════════════════════════════════════════════════════════════ # ║ Ω END CONFIGURATION #═╩═══════════════════════════════════════════════════════════════════════════ # A hash of reader methods for Game_Event objects that are used to remember # their values. Used by the self.memory_variables method. @event_memory = {x: :x, y: :y, dir: :direction, erased: :permanently_erased?} # Method used in Scene_Map's pre_transfer method to store event variables in # $game_system.events. def self.store_event_variables(map_id) $game_map.events.values.each do |event| if storage_requirements_met?(event) ($game_system.events[map_id] ||= {})[event.id] = memory_variables(event) end end end # Determine whether or not to store variables for the passed event. def self.storage_requirements_met?(event) return true if !REMEMBER_ALL && event.name.include?(REMEMBER_TAG) return true if REMEMBER_ALL && !event.name.include?(EXCLUDE_TAG) return true if event.permanently_erased? return false end # Used to get the variables that are remembered for events. def self.memory_variables(event) hash = {}; @event_memory.each{|k, v| hash[k] = event.send(v)} return hash end end end #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▲ module SES::Event_Memory #═╩═════════════════════════════════════════════════════════════════════════════ ($imported ||= {})["SES - Event Memory"] = 1.0 #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▼ class Game_System #═╩═════════════════════════════════════════════════════════════════════════════ class Game_System attr_accessor :events # Aliased to initialize the new instance variable @events, which stores the # x, y, and direction values for events. alias :ses_evmem_gs_init :initialize def initialize(*a, &b) ses_evmem_gs_init(*a, &b); @events = {} end end #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▲ class Game_System #─╫───────────────────────────────────────────────────────────────────────────── # ║ ▼ class Game_Map #═╩═════════════════════════════════════════════════════════════════════════════ class Game_Map # Aliased to move events to their remembered positions if the positions have # been stored in $game_system.events and to erase permanently erased events. alias :ses_evmem_gm_setupev :setup_events def setup_events(*args, &block) ses_evmem_gm_setupev(*args, &block) $game_system.events[@map_id].each do |id, vars| @events[id].erase! if vars[:erased] == true @events[id].moveto(vars[:x], vars[:y]) @events[id].set_direction(vars[:dir]) end if $game_system.events[@map_id] end end #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▲ class Game_Map #─╫───────────────────────────────────────────────────────────────────────────── # ║ ▼ class Game_Event #═╩═════════════════════════════════════════════════════════════════════════════ class Game_Event < Game_Character # Aliased to initialize the new instance variable @permanently_erased. alias :ses_evmem_ge_init :initialize def initialize(*args, &block) ses_evmem_ge_init(*args, &block) @permanently_erased = false end # Restores an event that has been erased (permanently or otherwise). def restore @erased, @permanently_erased = false, false refresh end # Permanently erases a method. def erase!() @permanently_erased = true; erase end # Convenience methods to determine if an event has been erased (permanently or # otherwise) and to get the event's name. def erased?() @erased end def permanently_erased?() @permanently_erased end def name() @event.name end end #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▲ class Game_Event #─╫───────────────────────────────────────────────────────────────────────────── # ║ ▼ class Scene_Map #═╩═════════════════════════════════════════════════════════════════════════════ class Scene_Map < Scene_Base # Aliased to remember event positions on the current map before the next # one is loaded. alias :ses_evmem_sm_pre :pre_transfer def pre_transfer(*args, &block) SES::Event_Memory.store_event_variables($game_map.map_id) ses_evmem_sm_pre(*args, &block) end end #═╦═════════════════════════════════════════════════════════════════════════════ # ║ ▲ class Scene_Map #═╩═════════════════════════════════════════════════════════════════════════════