Advertisement
quack_rgss

Template Events 1.0

Oct 29th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.15 KB | None | 0 0
  1. =begin
  2. #==============================================================================
  3.  * Quack Template Events - v1.0
  4.   Author: Quack
  5. #==============================================================================
  6.  
  7. What is this and what does it do?
  8. -------------------------------------------------------------------------------
  9. In your game there are probably going to be some events which you will be
  10. reusing a lot, like a save point. Let's say you have about 100 save points
  11. spread out all over your game and you find out there is a bug in your save point
  12. or that there is something you want to change about it. Once you have edited the
  13. save point you now have to copy/paste it to all those 100 places all over your
  14. game which is annoying, time consuming and you might miss one or two of them.
  15. This script attempts to solve that by having you place your template events that
  16. you want to reuse across many maps in one place and then for all those 100
  17. places where you want to place a save point you just create a new event and
  18. place a command in it to tell the game to replace it with your template save
  19. point event. This way when you change the template save point event, it will
  20. affect all those events that load that template rather than just that one event.
  21.  
  22. -To use it you first have to designate one map to be your template map where you
  23. keep all the template events.
  24. To do this scroll down to the line: 'STOCK_EVENT_MAP_ID = 1' and change the '1'
  25. to the id of the map you want to be your template map.
  26.  
  27. -Next create your template event on the template map and in its namebox add a
  28. unique tag which you will be identifying the template event by, like: '<save>'
  29.  
  30. -Then to make an event load this template, create a new event. Set its namebox
  31. '<template>' and add a comment event command with the text: 'QTEVENT: save'
  32. The event will now be replaced with your template save point.
  33.  
  34. -However just replacing an event with a template event isn't very flexible and
  35. won't do for a lot of reused events. Let's take a treasure chest or an enemy
  36. for example. You don't want every chest to have the same contents and different
  37. enemies should probably be different encounters and probably look different too.
  38. To do this, there exist a couple of additional commands for customizing the
  39. template.
  40.  
  41. -By using a comment event command with the text: 'QTPAGE: X, Y' will allow you
  42. to load a specific page of a template event to the current page of the event,
  43. where 'X' is the template event and 'Y' is the number of the page on the
  44. template event that you want to replace the current page of the event with.
  45.  
  46. -Another comment command is 'QTREPLACE' which allows you to replace and insert
  47. event commands on the template you have loaded. To use it you first need to add
  48. two comment commands to the template event to indicate where and what commands
  49. should be replaced on the template. Let's say you have a treasure chest template
  50. event and you want to replace the commands which give you the items in it.
  51. First place a comment with the text: '<X' right before the commands you want
  52. replaced, and then a comment with the text: 'X>' right after the commands you
  53. want replaced (where 'X' is whatever name you want to identify it by). If you
  54. don't want to replace any commands and just insert commands, just place the
  55. first comment where you want the commands inserted and the second comment right
  56. after.
  57. Then to actually do the replacing you will be creating two comment commands on
  58. the event loading the template as well. First you create a comment with the
  59. text: '<QTREPLACE: X' (where 'X' is the name you used in the two comments on the
  60. template to indicate the replace range), and then you add whatever event
  61. commands you want to use as replacement after it followed by a second comment
  62. with the text: 'QTREPLACE>'.
  63.  
  64. -It's also possible to change the graphics used by the template using the
  65. comment commands: 'QTGFXALL', 'QTGFXSAME: X' and 'QTGFXSINGLE'.
  66. Using 'QTGFXALL' will replace the graphic on all the template's pages using the
  67. graphic used by the current page.
  68. Using 'QTGFXSAME: X' (where 'X' is a page number on the template event) will
  69. replace the graphic on page 'X' of the template and all other pages on the
  70. template that use the same graphic as page 'X' with graphic on the current page
  71. of the event loading the template. (usefull for example if loading an enemy
  72. template where it uses the same graphic on most pages but no graphic on one
  73. page which is used when the enemy is dead)
  74. Using 'QTGFXSINGLE' will use the graphic on the current page to replace the
  75. graphic on the same page of the template.
  76.  
  77. -You can also customize conditions for a page on the template using these
  78. comment commands:
  79. -'QTSW1' to make the same page on the template use the same condition for first
  80. switch slot as the current page.
  81. -'QTSW2' same but for switch slot 2.
  82. -'QTVAR' same but for variable condition.
  83. -'QTITEM' same but for item condition.
  84. -'QTACTOR' same but for actor condition.
  85.  
  86. Requirements:
  87. My script Qonvenience. You can get it here:
  88.  
  89. Instructions/Install notes:
  90. Paste it below Materials like you would any other script.
  91.  
  92. Terms of Use:
  93. Use it however you wish (yes, that does include commercial projects), as long
  94. as you do not claim it as your own code. I would also prefer you mention me in
  95. your credits if you do decide to use it.
  96.  
  97. Bugs:
  98. dunno
  99.  
  100. History:
  101. 29/10/2016 - Initial release.
  102.  
  103. =end
  104.  
  105. module QUACK
  106.   module TEMPLATE_EVENTS
  107.     # The id of the map you keep your template events
  108.     STOCK_EVENT_MAP_ID = 1
  109.   end
  110. end
  111.  
  112. #==============================================================================
  113. # DataManager
  114. #==============================================================================
  115. module DataManager
  116.     # alias
  117.     class <<self; alias qs_load_normal_database load_normal_database; end
  118.     def self.load_normal_database
  119.         qs_load_normal_database
  120.         $data_stock_event_map = load_data(sprintf("Data/Map%03d.rvdata2", QUACK::TEMPLATE_EVENTS::STOCK_EVENT_MAP_ID))
  121.    
  122.     # build name tags database for events in stock map
  123.     $data_stock_name_tags = {}
  124.     for key in $data_stock_event_map.events
  125.       event = key[1]
  126.       next if event.nil?
  127.       t = event.name.scan(/<([^<>]*)>/i)
  128.       next if t.nil? || t.length < 1
  129.       t.each {|s|
  130.         $data_stock_name_tags[s[0]] = event
  131.       }
  132.     end
  133.     end
  134. end
  135.  
  136. #==============================================================================
  137. # Game_Map
  138. #==============================================================================
  139. class Game_Map
  140.   alias qte_gm_setup_events setup_events
  141.   def setup_events
  142.     #@events = {}
  143.     #@map.events.each do |i, event|
  144.     #  @events[i] = Game_Event.new(@map_id, event)
  145.     #end
  146.     #@common_events = parallel_common_events.collect do |common_event|
  147.     #  Game_CommonEvent.new(common_event.id)
  148.     #end
  149.     #refresh_tile_events
  150.     qte_gm_setup_events
  151.     # Load template events
  152.     evs = all_event_tag("template")
  153.     return if evs.nil?
  154.     evs.each {|e|
  155.       ex = e.x
  156.       ey = e.y
  157.       qte = Marshal.load(Marshal.dump(e.event))
  158.       qte.name.gsub!(/<template>/i) {""}
  159.       repstart = nil
  160.       insstart = nil
  161.       e.event.pages.each_with_index {|p,ind|
  162.         next if !p || !p.list || p.list.size <= 0
  163.         p.list.each_with_index {|i,eci|
  164.           if i && (i.code == 108 || i.code == 408)
  165.             # LOAD TEMPLATE EVENT?
  166.             if i.parameters[0] =~ /QTEVENT:[ ]*(.*)/i
  167.               unless $data_stock_name_tags.has_key?($1)
  168.                 msgbox("template '" + $1 + "' doesn't exist")
  169.                 exit
  170.               end
  171.               qte = Marshal.load(Marshal.dump($data_stock_name_tags[$1]))
  172.               qte.id = e.id
  173.             # LOAD TEMPLATE PAGE?
  174.             elsif i.parameters[0] =~ /QTPAGE:[ ]*(.*),[ ]*(.*)/i
  175.               unless $data_stock_name_tags.has_key?($1)
  176.                 msgbox("template '" + $1 + "' doesn't exist")
  177.                 exit
  178.               end
  179.               unless $data_stock_name_tags[$1].pages.length >= $2.to_i
  180.                 msgbox("template page doesn't exist")
  181.                 exit
  182.               end
  183.               qte.pages[ind] = $data_stock_name_tags[$1].pages[$2.to_i-1]
  184.             # REPLACE COMMANDS?
  185.             elsif i.parameters[0] =~ /<QTREPLACE:[ ]*(.*)/i
  186.               comm = $1
  187.               repstart = [$1, eci]
  188.             elsif i.parameters[0] =~ /QTREPLACE>/i
  189.               unless repstart.nil?
  190.                 # finish replace list
  191.                 nec = e.event.pages[ind].list[(repstart[1]+1)..(eci)]
  192.                 rstart = 0
  193.                 rend = 0
  194.                 qte.pages.each{|qtp|
  195.                   next if !qtp || !qtp.list || qtp.list.size <= 0
  196.                   qtp.list.each_with_index{|evcom,evcomi|
  197.                     if evcom && (evcom.code == 108 || evcom.code == 408)
  198.                       if evcom.parameters[0] == '<' + repstart[0]
  199.                         rstart = evcomi
  200.                       elsif evcom.parameters[0] == repstart[0] + '>'
  201.                         rend = evcomi
  202.                         #slice away object between rstart and rend
  203.                         qtp.list.slice!((rstart+1)..(rend-1))
  204.                         #insert nec between rstart and rend
  205.                         qtp.list.insert(rstart+1, nec)
  206.                         qtp.list.flatten!
  207.                         repstart = nil
  208.                         break
  209.                       end
  210.                     end
  211.                   }
  212.                 }
  213.               end
  214.             # CHANGE GRAPHIC ALL PAGES?
  215.             elsif i.parameters[0] =~ /QTGFXALL/i
  216.               # changes graphic on all pages to the graphic on the current page
  217.               qte.pages.each{|qp|
  218.                 qp.graphic.tile_id = e.event.pages[ind].graphic.tile_id
  219.                 qp.graphic.character_name = e.event.pages[ind].graphic.character_name
  220.                 qp.graphic.character_index = e.event.pages[ind].graphic.character_index
  221.               }
  222.             # CHANGE GRAPHIC SAME?
  223.             elsif i.parameters[0] =~ /QTGFXSAME:[ ]*(.*)/i
  224.               # uses graphic on current page for page X and all other pages
  225.               # that use the same graphic as page X
  226.               tid = qte.pages[$1.to_i+1].graphic.tile_id
  227.               cn = qte.pages[$1.to_i+1].graphic.character_name
  228.               ci = qte.pages[$1.to_i+1].graphic.character_index
  229.               qte.pages.each{|qp|
  230.                 next if qp.graphic.tile_id != tid || qp.graphic.character_name != cn || qp.graphic.character_index != ci
  231.                 qp.graphic.tile_id = e.event.pages[ind].graphic.tile_id
  232.                 qp.graphic.character_name = e.event.pages[ind].graphic.character_name
  233.                 qp.graphic.character_index = e.event.pages[ind].graphic.character_index
  234.               }
  235.             # CHANGE GRAPHIC SINGLE PAGE?
  236.             elsif i.parameters[0] =~ /QTGFXSINGLE/i
  237.               # retains original graphic for current page
  238.               qte.pages[ind].graphic.tile_id = e.event.pages[ind].graphic.tile_id
  239.               qte.pages[ind].graphic.character_name = e.event.pages[ind].graphic.character_name
  240.               qte.pages[ind].graphic.character_index = e.event.pages[ind].graphic.character_index
  241.             # CHANGE PAGE SWITCH CONDITION
  242.             elsif i.parameters[0] =~ /QTSW1/i
  243.               qte.pages[ind].condition.switch1_valid = e.event.pages[ind].condition.switch1_valid
  244.               qte.pages[ind].condition.switch1_id = e.event.pages[ind].condition.switch1_id
  245.             elsif i.parameters[0] =~ /QTSW2/i
  246.               qte.pages[ind].condition.switch2_valid = e.event.pages[ind].condition.switch2_valid
  247.               qte.pages[ind].condition.switch2_id = e.event.pages[ind].condition.switch2_id
  248.             # CHANGE PAGE VARIABLE CONDITION
  249.             elsif i.parameters[0] =~ /QTVAR/i
  250.               qte.pages[ind].condition.variable_valid = e.event.pages[ind].condition.variable_valid
  251.               qte.pages[ind].condition.variable_id = e.event.pages[ind].condition.variable_id
  252.               qte.pages[ind].condition.variable_value = e.event.pages[ind].condition.variable_value
  253.             # CHANGE PAGE ITEM CONDITION
  254.             elsif i.parameters[0] =~ /QTITEM/i
  255.               qte.pages[ind].condition.item_valid = e.event.pages[ind].condition.item_valid
  256.               qte.pages[ind].condition.item_id = e.event.pages[ind].condition.item_id
  257.             # CHANGE PAGE ACTOR CONDITION
  258.             elsif i.parameters[0] =~ /QTACTOR/i
  259.               qte.pages[ind].condition.actor_valid = e.event.pages[ind].condition.actor_valid
  260.               qte.pages[ind].condition.actor_id = e.event.pages[ind].condition.actor_id
  261.             end
  262.           end
  263.         }
  264.       }
  265.       @events[e.id] = Game_Event.new(@map_id, qte)
  266.       @events[e.id].moveto(ex, ey)
  267.     }
  268.    
  269.     @events.each do |k, e|
  270.       # Check if event uses template
  271.       next unless e.name
  272.       e.event.pages.each {|p|
  273.         next if !p || !p.list || p.list.size <= 0
  274.       }
  275.     end
  276.   end
  277. end
  278.  
  279. #==============================================================================
  280. # Game_Event
  281. #==============================================================================
  282. class Game_Event < Game_Character
  283.   attr_reader :event
  284. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement