Skip to content

Instantly share code, notes, and snippets.

@fluid-decanter
Last active January 24, 2023 11:32
Show Gist options
  • Save fluid-decanter/8c923f9f506d66db14fb916d0d3e8581 to your computer and use it in GitHub Desktop.
Save fluid-decanter/8c923f9f506d66db14fb916d0d3e8581 to your computer and use it in GitHub Desktop.
RMVXA script by Hime with modifications for flexibility and error handling.
=begin
#===============================================================================
Title: Reference Event Pages
Author: Hime (modded by Decanter where noted)
Date: Mar 16, 2014
URL: http://www.himeworks.com/2014/03/16/reference-event-pages/
--------------------------------------------------------------------------------
** Change log
Mar 16, 2014
- 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 allows you to create reference pages for your events.
A reference page allows you to create one page and then re-use it in different
events or troops. This can be applied to troop events and map events.
For map events, the reference page will copy the event commands,
page conditions, page graphic, as well as any other page settings.
For troop events, the reference page will copy the event commands, the
condition, the span, and any other page settings
Troop events can only reference other troop events. Similarly, map events
can only reference other map events.
--------------------------------------------------------------------------------
** Installation
In the script editor, place this script below Materials and above Main
--------------------------------------------------------------------------------
** Usage
-- Map Events --
To create a reference page for map events, create a comment and tag it with
<reference page: eventID pageNum>
<reference page: eventID pageNum mapID>
If you don't specify a map ID, then the event assumes the referenced event is
on the same map as the current event.
-- Troop Events --
You can have a troop event page reference any other troop event page.
To create a reference page, create a comment and then tag it with
<reference page: troopID pageNumber>
--------------------------------------------------------------------------------
** Example
To use page 1 of troop 5's events as the reference of a reference page,
the comment would look like
<reference page: 1 5>
To use page 4 of map event 2 on map 6 as the reference page, the comment
would look like
<reference page: 2 4 6>
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported[:TH_ReferenceEventPages] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
module Reference_Event_Pages
Regex = /<reference[-_ ]page:\s*(\S+)\s+(\S+)(?:\s+(\S+))?\s*>/i # modded \d to \S
#---------------------------------------------------------------------------
# Simple cache mechanism
#---------------------------------------------------------------------------
def self.load_map(map_id)
@cache ||= {}
@cache[map_id] = load_data("Data/Map%03d.rvdata2" %map_id) unless @cache.include?(map_id)
@cache[map_id]
end
end
end
#===============================================================================
# ** Rest of script
#===============================================================================
module RPG
class Event
alias :th_reference_event_pages_pages :pages
def pages
load_reference_event_pages unless @reference_event_pages_loaded
th_reference_event_pages_pages
end
def load_reference_event_pages
@reference_event_pages_loaded = true
self.pages.each_with_index do |page, i|
page.list.each do |cmd|
if cmd.code == 108 && cmd.parameters[0] =~ TH::Reference_Event_Pages::Regex
event_id = eval($1).to_i # modded to eval
page_id = eval($2).to_i # modded to eval
map_id = $3 ? eval($3).to_i : $game_map.map_id # modded to eval
begin # modded to add error handling
map = TH::Reference_Event_Pages.load_map(map_id)
page = map.events[event_id].pages[page_id-1]
@pages[i] = page
rescue
puts $!
puts "Invalid map, event, or page specified for event " + self.id.to_s + " at (" + self.x.to_s + "," + self.y.to_s + ") on map " + $game_map.map_id.to_s
end
end
end
end
end
end
class Troop
alias :th_reference_event_pages_pages :pages
def pages
load_reference_event_pages unless @reference_event_pages_loaded
th_reference_event_pages_pages
end
def load_reference_event_pages
@reference_event_pages_loaded = true
self.pages.each_with_index do |page, i|
page.list.each do |cmd|
if cmd.code == 108 && cmd.parameters[0] =~ TH::Reference_Event_Pages::Regex
troop_id = eval($1).to_i # modded to eval
page_id = eval($2).to_i # modded to eval
begin # modded to add error handling
page = $data_troops[troop_id].pages[page_id-1]
@pages[i] = page
rescue
puts $!
end
end
end
end
end
end
end
# modded in everything from here down
class Game_Event < Game_Character
def name
return @event.name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment