pigu_6

Yanfly| Common Event Tiles

Nov 24th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Common Event Tiles v1.01
  4. # -- Last Updated: 2011.12.06
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-CommonEventTiles"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2011.12.06 - Bugfix that prevented on touch events from triggering.
  17. # 2011.12.04 - Started Script and Finished.
  18. #
  19. #==============================================================================
  20. # ▼ Introduction
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # Rather than flooding the entire map with events just to run a single common
  23. # event, bind common events to terrain tags that trigger upon stepping on them.
  24. # This will cause all of the tiles marked by those terrain tags to spring up
  25. # the common event when the player steps over them.
  26. #
  27. #==============================================================================
  28. # ▼ Instructions
  29. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. # To install this script, open up your script editor and copy/paste this script
  31. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  32. #
  33. # -----------------------------------------------------------------------------
  34. # Tileset Notetags - These notetags go in the tileset notebox in the database.
  35. # -----------------------------------------------------------------------------
  36. # <event x: y>
  37. # <event x: y, y>
  38. # Sets the tiles marked with terrain tag y to trigger common event x. The
  39. # common event will run each time the player steps over a tile with the
  40. # respective terrain tags.
  41. #
  42. #==============================================================================
  43. # ▼ Compatibility
  44. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  46. # it will run with RPG Maker VX without adjusting.
  47. #
  48. #==============================================================================
  49. # ▼ Editting anything past this point may potentially result in causing
  50. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  51. # halitosis so edit at your own risk.
  52. #==============================================================================
  53.  
  54. module YEA
  55. module REGEXP
  56. module TILESET
  57.  
  58. COMMON_EVENT = /<(?:EVENT|event)[ ]*(\d+):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  59.  
  60. end # TILESET
  61. end # REGEXP
  62. end # YEA
  63.  
  64. #==============================================================================
  65. # ■ DataManager
  66. #==============================================================================
  67.  
  68. module DataManager
  69.  
  70. #--------------------------------------------------------------------------
  71. # alias method: load_database
  72. #--------------------------------------------------------------------------
  73. class <<self; alias load_database_cet load_database; end
  74. def self.load_database
  75. load_database_cet
  76. load_notetags_cet
  77. end
  78.  
  79. #--------------------------------------------------------------------------
  80. # new method: load_notetags_cet
  81. #--------------------------------------------------------------------------
  82. def self.load_notetags_cet
  83. groups = [$data_tilesets]
  84. for group in groups
  85. for obj in group
  86. next if obj.nil?
  87. obj.load_notetags_cet
  88. end
  89. end
  90. end
  91.  
  92. end # DataManager
  93.  
  94. #==============================================================================
  95. # ■ RPG::Tileset
  96. #==============================================================================
  97.  
  98. class RPG::Tileset
  99.  
  100. #--------------------------------------------------------------------------
  101. # public instance variables
  102. #--------------------------------------------------------------------------
  103. attr_accessor :cevents
  104. attr_accessor :cevent_tiles
  105.  
  106. #--------------------------------------------------------------------------
  107. # common cache: load_notetags_st
  108. #--------------------------------------------------------------------------
  109. def load_notetags_cet
  110. @cevents = {}
  111. @cevent_tiles = []
  112. #---
  113. self.note.split(/[\r\n]+/).each { |line|
  114. case line
  115. #---
  116. when YEA::REGEXP::TILESET::COMMON_EVENT
  117. @cevents[$1.to_i] = []
  118. array = @cevents[$1.to_i]
  119. $2.scan(/\d+/).each { |num|
  120. array.push(num.to_i) if num.to_i > 0
  121. @cevent_tiles.push(num.to_i) if num.to_i > 0 }
  122. #---
  123. end
  124. } # self.note.split
  125. #---
  126. end
  127.  
  128. end # RPG::Tileset
  129.  
  130. #==============================================================================
  131. # ■ Game_Map
  132. #==============================================================================
  133.  
  134. class Game_Map
  135.  
  136. #--------------------------------------------------------------------------
  137. # new method: common_event_floor?
  138. #--------------------------------------------------------------------------
  139. def common_event_floor?(dx, dy)
  140. return (valid?(dx, dy) and common_event_tag?(dx, dy))
  141. end
  142.  
  143. #--------------------------------------------------------------------------
  144. # new method: common_event_tag?
  145. #--------------------------------------------------------------------------
  146. def common_event_tag?(dx, dy)
  147. return tileset.cevent_tiles.include?(terrain_tag(dx, dy))
  148. end
  149.  
  150. #--------------------------------------------------------------------------
  151. # new method: tile_common_event
  152. #--------------------------------------------------------------------------
  153. def tile_common_event(dx, dy)
  154. for key in tileset.cevents
  155. return key[0] if key[1].include?(terrain_tag(dx, dy))
  156. end
  157. end
  158.  
  159. end # Game_Map
  160.  
  161. #==============================================================================
  162. # ■ Game_Player
  163. #==============================================================================
  164.  
  165. class Game_Player < Game_Character
  166.  
  167. #--------------------------------------------------------------------------
  168. # alias method: check_touch_event
  169. #--------------------------------------------------------------------------
  170. alias check_touch_event_cet check_touch_event
  171. def check_touch_event
  172. return false if in_airship?
  173. check_tile_common_event
  174. check_touch_event_cet
  175. end
  176.  
  177. #--------------------------------------------------------------------------
  178. # new method: check_tile_common_event
  179. #--------------------------------------------------------------------------
  180. def check_tile_common_event
  181. return unless $game_map.common_event_floor?(@x, @y)
  182. $game_temp.reserve_common_event($game_map.tile_common_event(@x, @y))
  183. end
  184.  
  185. end # Game_Player
  186.  
  187. #==============================================================================
  188. #
  189. # ▼ End of File
  190. #
  191. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment