Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- #==============================================================================
- * Quack Template Events - v1.0
- Author: Quack
- #==============================================================================
- What is this and what does it do?
- -------------------------------------------------------------------------------
- In your game there are probably going to be some events which you will be
- reusing a lot, like a save point. Let's say you have about 100 save points
- spread out all over your game and you find out there is a bug in your save point
- or that there is something you want to change about it. Once you have edited the
- save point you now have to copy/paste it to all those 100 places all over your
- game which is annoying, time consuming and you might miss one or two of them.
- This script attempts to solve that by having you place your template events that
- you want to reuse across many maps in one place and then for all those 100
- places where you want to place a save point you just create a new event and
- place a command in it to tell the game to replace it with your template save
- point event. This way when you change the template save point event, it will
- affect all those events that load that template rather than just that one event.
- -To use it you first have to designate one map to be your template map where you
- keep all the template events.
- To do this scroll down to the line: 'STOCK_EVENT_MAP_ID = 1' and change the '1'
- to the id of the map you want to be your template map.
- -Next create your template event on the template map and in its namebox add a
- unique tag which you will be identifying the template event by, like: '<save>'
- -Then to make an event load this template, create a new event. Set its namebox
- '<template>' and add a comment event command with the text: 'QTEVENT: save'
- The event will now be replaced with your template save point.
- -However just replacing an event with a template event isn't very flexible and
- won't do for a lot of reused events. Let's take a treasure chest or an enemy
- for example. You don't want every chest to have the same contents and different
- enemies should probably be different encounters and probably look different too.
- To do this, there exist a couple of additional commands for customizing the
- template.
- -By using a comment event command with the text: 'QTPAGE: X, Y' will allow you
- to load a specific page of a template event to the current page of the event,
- where 'X' is the template event and 'Y' is the number of the page on the
- template event that you want to replace the current page of the event with.
- -Another comment command is 'QTREPLACE' which allows you to replace and insert
- event commands on the template you have loaded. To use it you first need to add
- two comment commands to the template event to indicate where and what commands
- should be replaced on the template. Let's say you have a treasure chest template
- event and you want to replace the commands which give you the items in it.
- First place a comment with the text: '<X' right before the commands you want
- replaced, and then a comment with the text: 'X>' right after the commands you
- want replaced (where 'X' is whatever name you want to identify it by). If you
- don't want to replace any commands and just insert commands, just place the
- first comment where you want the commands inserted and the second comment right
- after.
- Then to actually do the replacing you will be creating two comment commands on
- the event loading the template as well. First you create a comment with the
- text: '<QTREPLACE: X' (where 'X' is the name you used in the two comments on the
- template to indicate the replace range), and then you add whatever event
- commands you want to use as replacement after it followed by a second comment
- with the text: 'QTREPLACE>'.
- -It's also possible to change the graphics used by the template using the
- comment commands: 'QTGFXALL', 'QTGFXSAME: X' and 'QTGFXSINGLE'.
- Using 'QTGFXALL' will replace the graphic on all the template's pages using the
- graphic used by the current page.
- Using 'QTGFXSAME: X' (where 'X' is a page number on the template event) will
- replace the graphic on page 'X' of the template and all other pages on the
- template that use the same graphic as page 'X' with graphic on the current page
- of the event loading the template. (usefull for example if loading an enemy
- template where it uses the same graphic on most pages but no graphic on one
- page which is used when the enemy is dead)
- Using 'QTGFXSINGLE' will use the graphic on the current page to replace the
- graphic on the same page of the template.
- -You can also customize conditions for a page on the template using these
- comment commands:
- -'QTSW1' to make the same page on the template use the same condition for first
- switch slot as the current page.
- -'QTSW2' same but for switch slot 2.
- -'QTVAR' same but for variable condition.
- -'QTITEM' same but for item condition.
- -'QTACTOR' same but for actor condition.
- Requirements:
- My script Qonvenience. You can get it here:
- Instructions/Install notes:
- Paste it below Materials like you would any other script.
- Terms of Use:
- Use it however you wish (yes, that does include commercial projects), as long
- as you do not claim it as your own code. I would also prefer you mention me in
- your credits if you do decide to use it.
- Bugs:
- dunno
- History:
- 29/10/2016 - Initial release.
- =end
- module QUACK
- module TEMPLATE_EVENTS
- # The id of the map you keep your template events
- STOCK_EVENT_MAP_ID = 1
- end
- end
- #==============================================================================
- # DataManager
- #==============================================================================
- module DataManager
- # alias
- class <<self; alias qs_load_normal_database load_normal_database; end
- def self.load_normal_database
- qs_load_normal_database
- $data_stock_event_map = load_data(sprintf("Data/Map%03d.rvdata2", QUACK::TEMPLATE_EVENTS::STOCK_EVENT_MAP_ID))
- # build name tags database for events in stock map
- $data_stock_name_tags = {}
- for key in $data_stock_event_map.events
- event = key[1]
- next if event.nil?
- t = event.name.scan(/<([^<>]*)>/i)
- next if t.nil? || t.length < 1
- t.each {|s|
- $data_stock_name_tags[s[0]] = event
- }
- end
- end
- end
- #==============================================================================
- # Game_Map
- #==============================================================================
- class Game_Map
- alias qte_gm_setup_events setup_events
- 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|
- # Game_CommonEvent.new(common_event.id)
- #end
- #refresh_tile_events
- qte_gm_setup_events
- # Load template events
- evs = all_event_tag("template")
- return if evs.nil?
- evs.each {|e|
- ex = e.x
- ey = e.y
- qte = Marshal.load(Marshal.dump(e.event))
- qte.name.gsub!(/<template>/i) {""}
- repstart = nil
- insstart = nil
- e.event.pages.each_with_index {|p,ind|
- next if !p || !p.list || p.list.size <= 0
- p.list.each_with_index {|i,eci|
- if i && (i.code == 108 || i.code == 408)
- # LOAD TEMPLATE EVENT?
- if i.parameters[0] =~ /QTEVENT:[ ]*(.*)/i
- unless $data_stock_name_tags.has_key?($1)
- msgbox("template '" + $1 + "' doesn't exist")
- exit
- end
- qte = Marshal.load(Marshal.dump($data_stock_name_tags[$1]))
- qte.id = e.id
- # LOAD TEMPLATE PAGE?
- elsif i.parameters[0] =~ /QTPAGE:[ ]*(.*),[ ]*(.*)/i
- unless $data_stock_name_tags.has_key?($1)
- msgbox("template '" + $1 + "' doesn't exist")
- exit
- end
- unless $data_stock_name_tags[$1].pages.length >= $2.to_i
- msgbox("template page doesn't exist")
- exit
- end
- qte.pages[ind] = $data_stock_name_tags[$1].pages[$2.to_i-1]
- # REPLACE COMMANDS?
- elsif i.parameters[0] =~ /<QTREPLACE:[ ]*(.*)/i
- comm = $1
- repstart = [$1, eci]
- elsif i.parameters[0] =~ /QTREPLACE>/i
- unless repstart.nil?
- # finish replace list
- nec = e.event.pages[ind].list[(repstart[1]+1)..(eci)]
- rstart = 0
- rend = 0
- qte.pages.each{|qtp|
- next if !qtp || !qtp.list || qtp.list.size <= 0
- qtp.list.each_with_index{|evcom,evcomi|
- if evcom && (evcom.code == 108 || evcom.code == 408)
- if evcom.parameters[0] == '<' + repstart[0]
- rstart = evcomi
- elsif evcom.parameters[0] == repstart[0] + '>'
- rend = evcomi
- #slice away object between rstart and rend
- qtp.list.slice!((rstart+1)..(rend-1))
- #insert nec between rstart and rend
- qtp.list.insert(rstart+1, nec)
- qtp.list.flatten!
- repstart = nil
- break
- end
- end
- }
- }
- end
- # CHANGE GRAPHIC ALL PAGES?
- elsif i.parameters[0] =~ /QTGFXALL/i
- # changes graphic on all pages to the graphic on the current page
- qte.pages.each{|qp|
- qp.graphic.tile_id = e.event.pages[ind].graphic.tile_id
- qp.graphic.character_name = e.event.pages[ind].graphic.character_name
- qp.graphic.character_index = e.event.pages[ind].graphic.character_index
- }
- # CHANGE GRAPHIC SAME?
- elsif i.parameters[0] =~ /QTGFXSAME:[ ]*(.*)/i
- # uses graphic on current page for page X and all other pages
- # that use the same graphic as page X
- tid = qte.pages[$1.to_i+1].graphic.tile_id
- cn = qte.pages[$1.to_i+1].graphic.character_name
- ci = qte.pages[$1.to_i+1].graphic.character_index
- qte.pages.each{|qp|
- next if qp.graphic.tile_id != tid || qp.graphic.character_name != cn || qp.graphic.character_index != ci
- qp.graphic.tile_id = e.event.pages[ind].graphic.tile_id
- qp.graphic.character_name = e.event.pages[ind].graphic.character_name
- qp.graphic.character_index = e.event.pages[ind].graphic.character_index
- }
- # CHANGE GRAPHIC SINGLE PAGE?
- elsif i.parameters[0] =~ /QTGFXSINGLE/i
- # retains original graphic for current page
- qte.pages[ind].graphic.tile_id = e.event.pages[ind].graphic.tile_id
- qte.pages[ind].graphic.character_name = e.event.pages[ind].graphic.character_name
- qte.pages[ind].graphic.character_index = e.event.pages[ind].graphic.character_index
- # CHANGE PAGE SWITCH CONDITION
- elsif i.parameters[0] =~ /QTSW1/i
- qte.pages[ind].condition.switch1_valid = e.event.pages[ind].condition.switch1_valid
- qte.pages[ind].condition.switch1_id = e.event.pages[ind].condition.switch1_id
- elsif i.parameters[0] =~ /QTSW2/i
- qte.pages[ind].condition.switch2_valid = e.event.pages[ind].condition.switch2_valid
- qte.pages[ind].condition.switch2_id = e.event.pages[ind].condition.switch2_id
- # CHANGE PAGE VARIABLE CONDITION
- elsif i.parameters[0] =~ /QTVAR/i
- qte.pages[ind].condition.variable_valid = e.event.pages[ind].condition.variable_valid
- qte.pages[ind].condition.variable_id = e.event.pages[ind].condition.variable_id
- qte.pages[ind].condition.variable_value = e.event.pages[ind].condition.variable_value
- # CHANGE PAGE ITEM CONDITION
- elsif i.parameters[0] =~ /QTITEM/i
- qte.pages[ind].condition.item_valid = e.event.pages[ind].condition.item_valid
- qte.pages[ind].condition.item_id = e.event.pages[ind].condition.item_id
- # CHANGE PAGE ACTOR CONDITION
- elsif i.parameters[0] =~ /QTACTOR/i
- qte.pages[ind].condition.actor_valid = e.event.pages[ind].condition.actor_valid
- qte.pages[ind].condition.actor_id = e.event.pages[ind].condition.actor_id
- end
- end
- }
- }
- @events[e.id] = Game_Event.new(@map_id, qte)
- @events[e.id].moveto(ex, ey)
- }
- @events.each do |k, e|
- # Check if event uses template
- next unless e.name
- e.event.pages.each {|p|
- next if !p || !p.list || p.list.size <= 0
- }
- end
- end
- end
- #==============================================================================
- # Game_Event
- #==============================================================================
- class Game_Event < Game_Character
- attr_reader :event
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement