Advertisement
Zetu

Z21 :: Eventeer v1.01

Jul 13th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. #======================#
  2. # Z-Systems by: Zetu #
  3. #===========================#======================#===========================#
  4. # * * * Z 21 :: Eventeer v1.01 * * * #
  5. #=#==========================================================================#=#
  6. # Version 1.01 #
  7. # Scripted Event Conditions #
  8. # * (In Event Comment) Place <bool: *> to add a scripted condition to #
  9. # event page. #
  10. # Sprite Offset #
  11. # * (In Event Comment) Place <x/y += *> to add/subtract displayed x/y #
  12. # coordinate of page's sprite. #
  13. # Event Area Expander #
  14. # * (In Area Name) Place <event ext: *> to cause event id *'s event #
  15. # trigger (player touch and action button) to be in area, instead of #
  16. # the event's x/y coordinate. #
  17. # Self Variable #
  18. # * Now events can have self variables (not just switches). Use #
  19. # self_var in script call (or (EVENT).self_var) to access an event's #
  20. # self variable. #
  21. #==========================================================================#
  22.  
  23. module Z21
  24.  
  25. module REGEXP
  26. BOOL = /<(?:bool|condition)[ :]*(.*)>/i
  27. OFFSET = /<(x|y)[: ]*(.*)>/i
  28. AREAEVENT = /<event *ext[: ]*(.*)>/
  29. end
  30.  
  31. end
  32.  
  33. class Game_Event
  34.  
  35. alias z21conditions_met? conditions_met? unless $@
  36. def conditions_met?(page)
  37. return false unless z21regexp_conditions_met?(page)
  38. return z21conditions_met?(page)
  39. end
  40.  
  41. def z21regexp_conditions_met?(page)
  42. for line in page.list
  43. next unless line.code == 108
  44. line.parameters[0].scan(Z21::REGEXP::BOOL){|condition|
  45. return false unless eval(condition[0])
  46. }
  47. end
  48. return true
  49. end
  50.  
  51. end
  52.  
  53. class Game_Interpreter
  54. def event
  55. return $game_map.events[@event_id]
  56. end
  57. def self_var
  58. return event.self_var
  59. end
  60. end
  61.  
  62. class Game_Event
  63.  
  64. def self_var
  65. return $self_var[@event.id, @map.map_id]
  66. end
  67.  
  68. def self_var=(new_value)
  69. $self_var[@event.id, @map.map_id] = new_value
  70. end
  71.  
  72. end
  73.  
  74. class Game_SelfVariables
  75.  
  76. def initialize
  77. @data = {}
  78. end
  79.  
  80. def [](key)
  81. return @data[key].nil? ? 0 : @data[key]
  82. end
  83.  
  84. def []=(key, value)
  85. @data[key] = value
  86. end
  87.  
  88. end
  89.  
  90. class Scene_Title < Scene_Base
  91.  
  92. alias z21create_game_objects create_game_objects unless $@
  93. def create_game_objects
  94. z21create_game_objects
  95. $self_var = Game_SelfVariables.new
  96. end
  97.  
  98. end
  99.  
  100. class Scene_File < Scene_Base
  101.  
  102. alias z21write_save_data write_save_data unless $@
  103. def write_save_data(file)
  104. z21write_save_data(file)
  105. Marshal.dump($game_player, file)
  106. end
  107.  
  108. alias z21read_save_data read_save_data
  109. def read_save_data(file)
  110. z21read_save_data(file)
  111. $self_var = Marshal.load(file)
  112. end
  113.  
  114. end
  115.  
  116. class Game_Character
  117.  
  118. alias z21screen_x screen_x unless $@
  119. def screen_x
  120. return z21screen_x + z21_offset_x
  121. end
  122.  
  123. alias z21screen_y screen_y unless $@
  124. def screen_y
  125. return z21screen_y + z21_offset_y
  126. end
  127.  
  128. def z21_offset_x
  129. return 0 unless self.is_a?(Game_Event)
  130. return z21_offset[0]
  131. end
  132.  
  133. def z21_offset_y
  134. return 0 unless self.is_a?(Game_Event)
  135. return z21_offset[1]
  136. end
  137.  
  138. def z21_offset
  139. param = [0, 0]
  140. return param if @page.nil?
  141. for line in @page.list
  142. next unless line.code == 108
  143. line.parameters[0].scan(Z21::REGEXP::OFFSET){|matches|
  144. for match in matches
  145. case $1.upcase
  146. when "X"
  147. param[0] += $2.to_i
  148. when "Y"
  149. param[1] += $2.to_i
  150. end
  151. end
  152. }
  153. end
  154. return param
  155. end
  156.  
  157. end
  158.  
  159. class Game_Player < Game_Character
  160.  
  161. alias z21check_event_trigger_touch check_event_trigger_touch unless $@
  162. def check_event_trigger_touch(x, y)
  163. if area_bind.size != 0
  164. return false if $game_map.interpreter.running?
  165. for id in area_bind
  166. event = $game_map.events[id]
  167. next if event.nil?
  168. event.start
  169. end
  170. else
  171. return z21check_event_trigger_touch(x, y)
  172. end
  173. end
  174.  
  175. alias z21check_event_trigger_here check_event_trigger_here unless $@
  176. def check_event_trigger_here(triggers)
  177. if area_bind.size != 0
  178. return false if $game_map.interpreter.running?
  179. result = false
  180. for id in area_bind
  181. event = $game_map.events[id]
  182. next if event.nil?
  183. next unless triggers.include?(event.trigger)
  184. next if event.priority_type == 1
  185. event.start
  186. result = true if event.starting
  187. end
  188. return result
  189. else
  190. return z21check_event_trigger_here(triggers)
  191. end
  192. end
  193.  
  194. def area_control?(test_id)
  195. area.name.scan(Z21::REGEXP::AREAEVENT){
  196. id = $1.to_s
  197. }
  198. return id == test_id
  199. end
  200.  
  201. def area_bind
  202. for area in $data_areas.values
  203. id = area_event_id(area)
  204. if in_area?(area) and id != 0
  205. return id
  206. end
  207. end
  208. end
  209.  
  210. def area_event_id(area)
  211. result = []
  212. for area in $data_areas.values
  213. area.name.scan(Z21::REGEXP::AREAEVENT){
  214. result.push($1.to_i)
  215. }
  216. end
  217. return result
  218. end
  219.  
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement