Advertisement
ezmash

Clone Events (VX)

Feb 14th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.25 KB | None | 0 0
  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 = 1
  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 = true
  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.  
  90.   def self.load_cloned_events
  91.     $data_clones = {}
  92.     if !CloneEvents::CLONE_MAP.nil?
  93.       clone_map_events(CloneEvents::CLONE_MAP)
  94.     end
  95.   end
  96.  
  97.   def self.clone_map_events(map_id)
  98.     $data_clones[map_id] = {}
  99.     events = load_data(sprintf("Data/Map%03d.rvdata", map_id)).events
  100.     events.each do |i, event|
  101.       name = CloneEvents::USE_NAME ? event.name.downcase : event.id.to_s
  102.       $data_clones[map_id][name] = event.clone
  103.     end
  104.   end
  105. end
  106.  
  107. class Scene_Title < Scene_Base
  108.   alias shaz_clone_events_load_database load_database
  109.   def load_database
  110.     shaz_clone_events_load_database
  111.     CloneEvents.load_cloned_events
  112.   end
  113. end
  114.  
  115. class Game_Event < Game_Character
  116.   @@clone_pattern = CloneEvents::CLONE_MAP.nil? ?
  117.     (CloneEvents::USE_NAME ? CloneEvents::PATT_MAP_NAME : CloneEvents::PATT_MAP_ID) :
  118.     (CloneEvents::USE_NAME ? CloneEvents::PATT_NAME : CloneEvents::PATT_ID)
  119.    
  120.   alias shaz_clone_events_initialize initialize
  121.   def initialize(map_id, event)
  122.     shaz_clone_events_initialize(map_id, event)
  123.     check_clone
  124.   end
  125.  
  126.   def check_clone
  127.     if @event && @event.pages[0].list && @event.pages[0].list[0].code == 108
  128.       @event.pages[0].list[0].parameters[0].gsub!(@@clone_pattern) do
  129.         clone_map = CloneEvents::CLONE_MAP.nil? ? $1.to_i : CloneEvents::CLONE_MAP
  130.         clone_name = (CloneEvents::CLONE_MAP.nil? ? $2.to_s : $1.to_s).downcase
  131.         CloneEvents.clone_map_events(clone_map) if !$data_clones.has_key?(clone_map)
  132.         @event.pages = Array.new($data_clones[clone_map][clone_name].pages.clone)
  133.       end
  134.     end
  135.     @page = nil
  136.     refresh
  137.   end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement