ezmash

Clone Events (VX Ace)

Oct 4th, 2013
974
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #============================================================================
  2. # Clone Events
  3. # v1.0 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This script allows you to clone events from one map to another.
  6. # Customization options allow you to have all clone (source) events on the
  7. # same map, or to specify which map should be used each time, and to
  8. # use either event names or ids to indicate which event should be cloned
  9. #----------------------------------------------------------------------------
  10. # To Install:
  11. # Copy and paste into a new script slot in Materials.  This script aliases
  12. # existing methods, so can go below all other custom scripts.
  13. #----------------------------------------------------------------------------
  14. # To Use:
  15. # Change the customization options in the module below to suit your
  16. # preferences -
  17. # - to have all clone (source) events come from one map, set CLONE_MAP to the
  18. #   map id containing all those events (this might be a map that the player
  19. #   never actually sees.
  20. # - to allow events from any map to be cloned, set CLONE_MAP to nil.
  21. # - to use event names to indicate the source event, set USE_NAME to true.
  22. #   This requires that clone (source) events on the original maps all have
  23. #   unique names.
  24. # - to use event ids to indicate the source event, set USE_NAME to false.
  25. #
  26. # Set up your events to be cloned.  If USE_NAME is set to true, ensure events
  27. # that will be cloned all have unique names on the source map.
  28. #
  29. # To clone an event, on the game map, create a new event, and add a single
  30. # comment to the event commands in one of the below formats:
  31. # - if all clone sources are on the same map, use one of these:
  32. #   <clone eventname>
  33. #   <clone eventid>
  34. # - if events from any map can be cloned, use one of these:
  35. #   <clone mapid eventname>
  36. #   <clone mapid eventid>
  37. #
  38. # Note - the event created will NOT get the same event id as the source.  It
  39. # will keep the event id of the 'dummy' event that has the <clone ...> comment.
  40. # This means you can have several events on the same map that are all clones
  41. # of the same original event.
  42. # It also means you can use multiple event pages and self switches on your
  43. # original event, and the self switches will refer to the correct map and
  44. # event id, so they don't get mixed up.
  45. #----------------------------------------------------------------------------
  46. # Examples
  47. #
  48. # CLONE_MAP = nil
  49. # USE_NAME = false
  50. # <clone 18 23>
  51. # will copy event 23 from map 18 to the current map
  52. #
  53. # CLONE_MAP = nil
  54. # USE_NAME = true
  55. # <clone 18 goldpouch>
  56. # will copy the event whose name is goldpouch from map 18 to the current map
  57. #
  58. # CLONE_MAP = 23
  59. # USE_NAME = false
  60. # <clone 6>
  61. # will copy event 6 from map 23 to the current map
  62. #
  63. # CLONE_MAP = 23
  64. # USE_NAME = true
  65. # <clone goldpouch>
  66. # will copy the event whose name is goldpouch from map 23 to the current map
  67. #----------------------------------------------------------------------------
  68. # Terms:
  69. # Use in free or commercial games
  70. # Credit Shaz
  71. #============================================================================
  72.  
  73. module CloneEvents
  74.   # This is the map id that contains the source events to be cloned
  75.   # set to nil if you want to be able to clone an event from ANY map
  76.   CLONE_MAP = nil
  77.  
  78.   # Use event name, or event id?  If name, each event on the clone map
  79.   # must have a unique name
  80.   # true = use event name
  81.   # false = use event id
  82.   USE_NAME = false
  83.  
  84.   # Regular Expression Patterns
  85.   PATT_MAP_NAME = /<clone\s+(\d+)\s+(\w+)>/i
  86.   PATT_MAP_ID = /<clone\s+(\d+)\s+(\d+)>/i
  87.   PATT_NAME = /<clone\s+(\w+)>/i
  88.   PATT_ID = /<clone\s+(\d+)>/i
  89. end
  90.  
  91.  
  92.  
  93. module DataManager
  94.   class << self;
  95.     alias shaz_clone_events_load_normal_database load_normal_database
  96.   end
  97.  
  98.   def self.load_normal_database
  99.     shaz_clone_events_load_normal_database
  100.     load_cloned_events
  101.   end
  102.  
  103.   def self.load_cloned_events
  104.     $data_clones = {}
  105.     if !CloneEvents::CLONE_MAP.nil?
  106.       clone_map_events(CloneEvents::CLONE_MAP)
  107.     end
  108.   end
  109.  
  110.   def self.clone_map_events(map_id)
  111.     $data_clones[map_id] = {}
  112.     events = load_data(sprintf('Data/Map%03d.rvdata2', map_id)).events
  113.     events.each do |i, event|
  114.       name = CloneEvents::USE_NAME ? event.name.downcase : event.id.to_s
  115.       $data_clones[map_id][name] = event.clone
  116.     end
  117.   end
  118. end
  119.  
  120. class Game_Event < Game_Character
  121.   @@clone_pattern = CloneEvents::CLONE_MAP.nil? ?
  122.     (CloneEvents::USE_NAME ? CloneEvents::PATT_MAP_NAME : CloneEvents::PATT_MAP_ID) :
  123.     (CloneEvents::USE_NAME ? CloneEvents::PATT_NAME : CloneEvents::PATT_ID)
  124.    
  125.   alias shaz_clone_events_initialize initialize
  126.   def initialize(map_id, event)
  127.     shaz_clone_events_initialize(map_id, event)
  128.     check_clone
  129.   end
  130.  
  131.   def check_clone
  132.     if @event && @event.pages[0].list && @event.pages[0].list[0].code == 108
  133.       @event.pages[0].list[0].parameters[0].gsub!(@@clone_pattern) do
  134.         clone_map = CloneEvents::CLONE_MAP.nil? ? $1.to_i : CloneEvents::CLONE_MAP
  135.         clone_name = (CloneEvents::CLONE_MAP.nil? ? $2.to_s : $1.to_s).downcase
  136.         DataManager.clone_map_events(clone_map) if !$data_clones.has_key?(clone_map)
  137.         @event.pages = Array.new($data_clones[clone_map][clone_name].pages.clone)
  138.       end
  139.     end
  140.     @page = nil
  141.     refresh
  142.   end
  143. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×