TheoAllen

Theo - Terrain Tag as Passabilty (ENG)

Jun 30th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.82 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Terrain Tag as Passability
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_TagPassability] = true
  8. # =============================================================================
  9. # CHANGE LOGS:
  10. # -----------------------------------------------------------------------------
  11. # 2013.06.21 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   This script can make terrain tag as passability instead of use X or O
  17.  
  18.   Cara penggunaan :
  19.   Put this script below material but above main
  20.   Setting terrain tag in database, use this comment in event  
  21.  
  22.   <terrain tag: n>
  23.   <terrain tag: m,n>
  24.   <terrain tag: m,n, ...>
  25.  
  26.   Which n and m is a terrain tag number. You can also add multiple terrain tag
  27.   such as <terrain tag: 1,2,3,4,5,6>
  28.  
  29.   Remember, if the event's terrain tag is determined, the event won't able to
  30.   move to other tile with different terrain tag even if the tile passability
  31.   is O
  32.  
  33.   Terms of use :
  34.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  35.   as you don't claim it yours. For commercial purpose, don't forget to give me
  36.   a free copy of the game.
  37.  
  38.  
  39. =end
  40. # =============================================================================
  41. # No configuration. Better don't touch anything unless you know what to do
  42. # =============================================================================
  43. module THEO
  44.   module MAP
  45.   module REGEXP
  46.     TAGS = /<(?:TERRAIN_TAG|terrain tag):[ ]*[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  47.   end
  48.   end
  49. end
  50.  
  51. class Game_Event < Game_Character
  52.  
  53.   alias ori_passable? map_passable?
  54.   def map_passable?(x,y,d)
  55.     return ori_passable?(x,y,d) if @tag_passable.empty?
  56.     return tag_passable?(x,y,d)
  57.   end  
  58.  
  59.  
  60.   def read_tag_passability
  61.     @tag_passable = []
  62.     @list.each do |command|
  63.       next unless command.code == 108 || command.code == 408
  64.       case command.parameters[0]
  65.       when THEO::MAP::REGEXP::TAGS
  66.         $1.scan(/\d+/).each do |num|
  67.           puts num.to_i
  68.           @tag_passable.push(num.to_i)
  69.         end
  70.       end
  71.     end
  72.   end
  73.  
  74.   def tag_passable?(x,y,d)
  75.     x2 = $game_map.round_x_with_direction(x, d)
  76.     y2 = $game_map.round_y_with_direction(y, d)
  77.     @tag_passable.include?($game_map.terrain_tag(x2,y2))
  78.   end
  79.  
  80. end
  81.  
  82. class Game_Map
  83.  
  84.   alias pre_tag_setup setup
  85.   def setup(map_id)
  86.     pre_tag_setup(map_id)
  87.     setup_event_passability
  88.   end
  89.  
  90.   def setup_event_passability
  91.     @events.values.each do |event|
  92.       event.read_tag_passability
  93.     end
  94.   end
  95.  
  96. end
Advertisement
Add Comment
Please, Sign In to add comment