Advertisement
estriole

EST - SIMPLE EVENT PAGES CONTROLLER

Jan 10th, 2013
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.99 KB | None | 0 0
  1. =begin
  2. EST - SIMPLE EVENT PAGES CONTROLLER
  3. v.1.2a
  4. Author: Estriole
  5.  
  6. also credits:
  7. 1) Tsukihime
  8. for giving me inspiration to create this script.
  9. 2) Killozapit
  10. for giving me idea to use actual event pages so it can used by other event
  11.  
  12. Version History
  13. v.1.0  - 2013-01-13 - finish the script
  14. v.1.1  - 2013-01-16 - add ability to change event force page by name using string
  15.                       or regexp.
  16.                       example string: set_event_force_page(4,"test 1",3)
  17.                       this will change all event with the name test 1 (not case sensitive)
  18.                       example regexp: set_event_force_page(4,/test (.*)/i,3)
  19.                       this will change all event that contain test x in name.
  20.                       so event with these name will change it's force page:
  21.                       test 1, test 2, test 3, battle test 1, battle test abc, etc
  22.                       this feature only useful for people who generate event ingame
  23.                       using either event spawner, copier, etc. since they won't know the id
  24.                       of that event until generated.
  25. v.1.2  - 2013-01-18 - add function to use other event pages by setting the force page
  26.                       to RPG::Event:Page object. also added new game interpreter
  27.                       method to make even beginner able to use it. :D(hopefully)
  28. v.1.2a - 2013-01-18 - fix some error with new method if map/event not exist.
  29.                       also renamed the script (change system to controller) to
  30.                       describe this script better. (i decide to stick with simple word :D)
  31.                      
  32. Introduction
  33. Did you have many pages event and have hard time setting it right. this might be
  34. your answer. by default the event page system is like this:
  35. from the last page it check for that page condition. if condition met than use that
  36. page.
  37.  
  38. Imagine if your event pages is 100. and at start it use page 100. then you want by
  39. choosing something in page 100 will make the event goes to page 1.
  40. if default system you need to make ALL the event page 2 to 100 condition to NOT met.
  41. this could cost you a whole lots of Switches...
  42.  
  43. this script make you able to bypass those. now you can just specify the event pages
  44. you want to the event to use. and if not set it still use default event pages system.
  45. if you want simpler explanation. just imagine this as label and go to label command.
  46. but for pages.
  47.  
  48. and i also add that that chosen page also get checked for it's condition. so if that
  49. chosen page condition not met it will be no page selected (blank event)
  50.  
  51. example i have these event pages:
  52. page 1 - condition switch 1 on - set force page to page 2
  53. page 2 - condition none - do something
  54. page 3 - condition none - set force page to page 1
  55.  
  56. the event will be use page 3 (since you havent interact / turn on /off switch and also
  57. because that last page condition is met thus that last page used)
  58.  
  59. then by talking to that event you set force page to page 1.
  60. but you haven't turn on the switch 1 so it will be blank event. then when you
  61. turn on switch 1. that event will use page 1. and by talking to that event will
  62. proceed to page 2. and by talking again to event it will do something
  63. note: should i make demo about this? i think it's clear enough.
  64.  
  65. you could also make all the pages without condition and then treat it like go to page.
  66. just remember the event will pick your last page at the first time
  67.  
  68. How to use
  69. 1) Script call:
  70.  
  71. set_this_event_force_page(page_id)
  72.  
  73. ->this will set current event to that page id
  74.  
  75. 2) Script call:
  76.  
  77. set_event_force_page(map_id,event_id,page_id)
  78.  
  79. ->this will set event id in that map id to that page id
  80. ->from 1.1 above: event_id can be number/event name/ regexp format
  81.  
  82. you could set the page_id to nil for both method to use default event page system
  83.  
  84. *** new from v.1.2 above ***
  85. 3) Script call:
  86.  
  87. event_use_page(map_id,event_id,source_map_id,source_event_id,source_page_id)
  88.  
  89. ->this will set event id in that map id to use page from another event.
  90. ->event_id can be number/event name/ regexp format
  91. ->source_event_id cannot use event name/regexp. it must be number.
  92.  
  93. you could set the page_id to nil for both method to use default event page system
  94.  
  95.  
  96. Compatibility
  97. i think this compatible with most script. and it also don't break existing project.
  98. since existing project event don't have force page set for them thus using default
  99. event page system.
  100.  
  101. =end
  102. class Game_Event < Game_Character
  103.   attr_accessor :force_page  
  104.   attr_reader   :event  
  105.   alias est_force_event_page_find_page find_proper_page
  106.   def find_proper_page
  107.     return [@force_page].find{|page| conditions_met?(page)} if @force_page.is_a?(RPG::Event::Page)
  108.     if @force_page && @force_page > 0 && @force_page <= @event.pages.size
  109.     return [@event.pages[@force_page-1]].find{|page| conditions_met?(page)}
  110.     end
  111.     est_force_event_page_find_page
  112.   end
  113. end
  114.  
  115. class Game_Interpreter
  116.   def set_this_event_force_page(page_id)
  117.     $game_map.force_pages[@map_id] = {} if !$game_map.force_pages[@map_id]
  118.     $game_map.force_pages[@map_id][@event_id] = page_id
  119.     $game_map.events[@event_id].force_page = page_id
  120.     $game_map.refresh
  121.   end
  122.   def set_event_force_page(map_id,event_id,page_id)
  123.     $game_map.force_pages[map_id] = {} if !$game_map.force_pages[map_id]
  124.     $game_map.force_pages[map_id][event_id] = page_id
  125.     if @map_id == map_id
  126.       event_id = $game_map.get_event_id_by_name(event_id) if event_id.is_a?(String) or event_id.is_a?(Regexp)
  127.       event_id = [event_id] if event_id.is_a?(Fixnum)
  128.       event_id = event_id.to_a if !event_id.is_a?(Array)
  129.       return if event_id == nil
  130.       event_id.each do |id|  
  131.         if $game_map.events[id]
  132.         $game_map.events[id].force_page = page_id
  133.         $game_map.refresh
  134.         end #end if
  135.       end #end do
  136.     end #end if
  137.   end #end def
  138.   def event_use_page(map_id,event_id,source_map_id,source_event_id,source_page_id)
  139.     map = load_data(sprintf("Data/Map%03d.rvdata2", source_map_id)) rescue nil
  140.     #event = map.events[source_event_id] rescue nil#if map
  141.     page = map.events[source_event_id].pages[source_page_id-1] rescue nil#if event
  142.     return if !page
  143.     $game_map.force_pages[map_id] = {} if !$game_map.force_pages[map_id]
  144.     $game_map.force_pages[map_id][event_id] = page
  145.     if @map_id == map_id
  146.       event_id = $game_map.get_event_id_by_name(event_id) if event_id.is_a?(String) or event_id.is_a?(Regexp)
  147.       event_id = [event_id] if event_id.is_a?(Fixnum)
  148.       event_id = event_id.to_a if !event_id.is_a?(Array)
  149.       return if event_id == nil
  150.       event_id.each do |id|  
  151.         if $game_map.events[id]
  152.         $game_map.events[id].force_page = page
  153.         $game_map.refresh
  154.         end #end if
  155.       end #end do
  156.     end #end if
  157.   end #end def set event force page pm
  158. end #end class game interpreter
  159.  
  160. class Game_Map
  161.   attr_accessor :force_pages
  162.   alias est_force_event_page_game_map_init initialize
  163.   def initialize
  164.     est_force_event_page_game_map_init
  165.     @force_pages = {}
  166.   end
  167.  
  168.   alias est_force_event_page_setup_events setup_events
  169.   def setup_events
  170.       est_force_event_page_setup_events
  171.       if @force_pages[@map_id]
  172.         @force_pages[@map_id].each do |key,value|
  173.           ids = key
  174.           ids = get_event_id_by_name(key) if ids.is_a?(String) or ids.is_a?(Regexp)
  175.           ids = [ids] if ids.is_a?(Fixnum)
  176.           ids = ids.to_a if !ids.is_a?(Array)
  177.           next if !ids
  178.           ids.each do |id|
  179.             @events[id].force_page = value if @events[id]
  180.           end
  181.         end
  182.       end
  183.       refresh
  184.       refresh_tile_events
  185.   end
  186.  
  187.   def get_event_id_by_name(string)
  188.     event = []
  189.      @events.each do |key,value|
  190.        if string.is_a?(String)
  191.        event.push(value) if value.name.upcase == string.upcase
  192.        else
  193.        event.push(value) if string.match(value.name)
  194.        #event.push(value) if value.name.match(string)
  195.        end
  196.      end
  197.     return false if !event
  198.     return id = event.collect{|ev|ev.id}
  199.   end  
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement