=begin #=============================================================================== Title: Extended Common Events Author: Hime Date: Jan 7, 2014 -------------------------------------------------------------------------------- ** Change log Jan 7, 2014 - address crash issue when no page is selected Nov 20, 2013 - Added support for replacing specific common events Oct 13, 2013 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script replaces the way common events are created and managed. Instead of using the database to set up common events, you create a special "common event map" and all events on that map will be loaded as common events. The advantage of using these extended common events include having multiple pages for a single common event and setting up complex common events using conditions. These extended common events will replace the database common events, but you can still use the database common events to set the names so that you can reference them throughout your project. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main. You should place this above other custom scripts. -------------------------------------------------------------------------------- ** Usage Create a map for your common events, and then in the configuration set up the filename of this common event map. Note that you don't have to use an actual map in your current project: you can choose any name you want as long as it is a map file. This means you can create the common event map in a separate project. By default, each event created on the map will be loaded as a common event based on its ID. So for example, if the event's ID is 12, then it will replace common event 12 in the database. You can choose which common event an event will replace manually by writing the following as its name: Where x is the common event ID. This allows you to replace specific common events. #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_ExtendedCommonEvents"] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Extended_Common_Events # The file that contains your extended common events. Common_Event_Map = "Data/map001.rvdata2" Regex = //i end end #=============================================================================== # ** Rest of Script #=============================================================================== module DataManager class << self alias :th_extended_common_events_create_game_objects :create_game_objects end def self.create_game_objects th_extended_common_events_create_game_objects load_extended_common_events end def self.load_extended_common_events map = load_data(TH::Extended_Common_Events::Common_Event_Map) map.events.each do |id, event| event_id = id if event.name =~ TH::Extended_Common_Events::Regex event_id = $1.to_i end p event_id $data_common_events[event_id] = Game_ExtCommonEvent.new(event) end end end class Game_Map #----------------------------------------------------------------------------- # Replaced. Extended common events are loaded differently #----------------------------------------------------------------------------- def setup_events @events = {} @map.events.each do |i, event| @events[i] = Game_Event.new(@map_id, event) end @common_events = parallel_common_events.collect do |common_event| if common_event.is_a?(Game_ExtCommonEvent) common_event else Game_CommonEvent.new(common_event.id) end end refresh_tile_events end #----------------------------------------------------------------------------- # Replaced. The extended common events can be parallel if you refresh the # page #----------------------------------------------------------------------------- def parallel_common_events $data_common_events.select {|event| event && (event.is_a?(Game_ExtCommonEvent) || event.parallel?) } end end class Game_ExtCommonEvent < Game_CommonEvent def initialize(event) @page = nil @event = event refresh end #----------------------------------------------------------------------------- # Returns whether the common event is active #----------------------------------------------------------------------------- def active? @page && parallel? end #----------------------------------------------------------------------------- # Returns whether the current page is parallel #----------------------------------------------------------------------------- def parallel? @page && @page.trigger == 4 end #----------------------------------------------------------------------------- # Returns whether the current page is autorun #----------------------------------------------------------------------------- def autorun? @page && @page.trigger == 3 end #----------------------------------------------------------------------------- # Returns the current page's list. Should refresh the pages first #----------------------------------------------------------------------------- def list refresh @page.list end def update if @interpreter @interpreter.setup(@page.list) unless @interpreter.running? @interpreter.update end end def refresh new_page = @erased ? nil : find_proper_page setup_page(new_page) if !new_page || new_page != @page if active? @interpreter ||= Game_Interpreter.new else @interpreter = nil end end def find_proper_page @event.pages.reverse.find {|page| conditions_met?(page) } end def setup_page(new_page) @page = new_page if @page setup_page_settings else clear_page_settings end end def conditions_met?(page) c = page.condition if c.switch1_valid return false unless $game_switches[c.switch1_id] end if c.switch2_valid return false unless $game_switches[c.switch2_id] end if c.variable_valid return false if $game_variables[c.variable_id] < c.variable_value end if c.self_switch_valid key = [@map_id, @event.id, c.self_switch_ch] return false if $game_self_switches[key] != true end if c.item_valid item = $data_items[c.item_id] return false unless $game_party.has_item?(item) end if c.actor_valid actor = $game_actors[c.actor_id] return false unless $game_party.members.include?(actor) end return true end def clear_page_settings @trigger = nil @list = nil @interpreter = nil end def setup_page_settings @trigger = @page.trigger @list = @page.list @interpreter = @trigger == 4 ? Game_Interpreter.new : nil end end