Help adding Terrain tag options to this enounter script

I have this script i have been using for some time now for RMXP made by Modern Algebra, it has different options already, one for making a square and within the square you can tell it what troops will show up and on what map, but i am wanting to add terrain tag options, so that within that square, a troop will only show up while over specific terrain tags.

Content Hidden Spoiler
  1. #==============================================================================
  2. # Encounter Area Restriction
  3. # Version: 1.1
  4. # Author: Modern Algebra  (rmrk.net)
  5. # Date: February 5, 2008
  6. #------------------------------------------------------------------------------
  7. #  Instructions:
  8. #    See inside the editable region at line 48 for instructions on setting up
  9. #    the database.
  10. #    You can also add a new region at any time in the game by using this code
  11. #    in a call script:
  12. #
  13. #     $game_system.set_area(x, y, width, height, monster troop array, map_id, name)
  14. #
  15. #    In order to make it fit, it may be easier to first assign each value to a
  16. #    variable, like so:
  17. #
  18. #      x = starting x coordinate for area
  19. #      y = starting y coordinate for area
  20. #      w = width of area
  21. #      h = height of area
  22. #      t = [1st troop ID, 2nd Troop ID, ...] for all troops in the area
  23. #      m = map id to set the new area in
  24. #      n = 'name' of area
  25. #      $game_system.set_area (x,y,w,h,t,m,n)
  26. #
  27. #    If you ever want to disable or enable an area (for instance, if the player
  28. #    comes back to the map after a major event and you no longer want him to
  29. #    fight the troops held in an old array), then you can use these codes:
  30. #  
  31. #    $game_system.area(name, map ID).active = true
  32. #    $game_system.area(name, map ID).active = true
  33. #
  34. #     If you do not specify map ID, then it will be assumed to be the map you
  35. #     are currently located on.
  36. #==============================================================================
  37. # *** Encounter_Regions
  38. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. #  Stores all pertinent data regarding encounters
  40. #==============================================================================
  41.  
  42. module Encounter_Regions
  43.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44.   # * Regions
  45.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46.   def self.areas
  47.     @areas = []
  48.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49.     # * Editable Region
  50.     #----------------------------------------------------------------------
  51.     # Set initial areas here. Set them up like this:
  52.     #
  53.     #    self.set_area (x, y, width, height, monster troop array, map_id, name)
  54.     #
  55.     # In the 1st example area below, we have defined an area at x = 10, y = 6,
  56.     # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
  57.     # in the area. Essentially, this means that on the first map, you can
  58.     # encounter monster troops 2, 3 and 8 if the player coordinates are within
  59.     # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
  60.     # a name, then merely type in nil.
  61.     #
  62.     # You can set as many areas as you like for as many maps as you like.
  63.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64.     self.set_area (2, 1, 26, 13, [2,3,4,5,6,7], 2, 'First Area')
  65.     self.set_area (1, 15, 33, 20,[2,3,4], 2, 'Second Area')
  66.     self.set_area (29, 23, 1, 4,[30,31], 2, 'Second Area beach')
  67.     self.set_area (29, 23, 3, 1,[30,31], 2, 'Second Area beach')
  68.     self.set_area (22, 29, 6, 1,[30,31], 2, 'Second Area beach')
  69.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70.     # * End Editable Region                                                                                    
  71.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72.     return @areas
  73.   end
  74.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75.   # * Set Area
  76.   #     Adds an Encounter_Area object to the areas array.
  77.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78.   def self.set_area (x, y, width, height, array, map_id, name = '')
  79.     # Initialize array if this is the first map for which there is an area
  80.     @areas[map_id] = [] if @areas[map_id].nil?
  81.     id = @areas[map_id].size
  82.     area = Encounter_Area.new (x, y, width, height, array, map_id, name)
  83.     @areas[map_id].push (area)
  84.   end
  85.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86.   # ** Encounter Area  
  87.   #--------------------------------------------------------------------------
  88.   #  The object which represents an area
  89.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90.   class Encounter_Area
  91.     #----------------------------------------------------------------------
  92.     # * Public Instance Variables                                                              
  93.     #----------------------------------------------------------------------
  94.     attr_reader   :map_id
  95.     attr_reader   :rect
  96.     attr_reader   :monster_troops # The monsters within the troop
  97.     attr_reader   :name
  98.     attr_accessor :active
  99.     #----------------------------------------------------------------------
  100.     # * Initialize                                          
  101.     #     Adds a Game_Area object to the array.      
  102.     #----------------------------------------------------------------------
  103.     def initialize (x, y, width, height, array, map_id, name)
  104.       @rect = Rect.new (x, y, width, height)
  105.       @monster_troops = array
  106.       @name = name
  107.       @map_id = map_id
  108.       @active = true
  109.     end
  110.     #----------------------------------------------------------------------
  111.     # * Within?                                                      
  112.     #     Checks if the position specified is within the area                
  113.     #----------------------------------------------------------------------
  114.     def within? (x, y)
  115.       return x.between? (@rect.x, @rect.x + @rect.width - 1) &&
  116.                 y.between? (@rect.y, @rect.y + @rect.height - 1)
  117.     end
  118.     #----------------------------------------------------------------------
  119.     # * Equals?                                          
  120.     #     Determine if two Encounter_Area objects are equal    
  121.     #----------------------------------------------------------------------
  122.     def == (other)
  123.       return other.map_id == @map_id && other.rect == @rect
  124.     end
  125.   end
  126. end
  127.  
  128. #==============================================================================
  129. # ** Game_System
  130. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131. #  Summary of Changes:
  132. #       aliased methods - initialize
  133. #       new methods - set_area, update_regions
  134. #       new instance variables - regions
  135. #==============================================================================
  136.  
  137. class Game_System
  138.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  139.   # * Public Instance Variables
  140.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141.   attr_reader :regions              # Contains area data
  142.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143.   # * Object Initialization
  144.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145.   alias ma_encounter_areas_init initialize
  146.   def initialize
  147.     ma_encounter_areas_init
  148.     @regions = []
  149.   end
  150.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  151.   # * Set Area
  152.   #     Adds an Encounter_Area object to the areas array.
  153.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154.   def set_area (x, y, width, height, array, name = '', map_id = $game_map.map_id)
  155.     area = Encounter_Regions::Encounter_Area.new  (x, y, width, height, array, map_id, name)
  156.     # If first area in the map, initialize array
  157.     @regions[map_id] = [] if @regions[map_id].nil?
  158.     @regions[map_id].push (area) unless @regions[map_id].include? (area)
  159.   end
  160.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  161.   # * Update Areas
  162.   #     Adds an Encounter_Area object to the areas array.
  163.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164.   def update_regions
  165.     # For all areas in the database
  166.     Encounter_Regions.areas.each {|regions|
  167.       next if regions.nil?
  168.       regions.each {|area|
  169.         # Initialize the array if this is the first area to be set to that map
  170.         @regions[area.map_id] = [] if @regions[area.map_id].nil?
  171.         # Add the area to the regions if it does not already exist
  172.         @regions[area.map_id].push (area) unless @regions.include? (area)
  173.       }
  174.     }
  175.   end
  176.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.   # * Retrieve Area by name and map_id
  178.   #       map_id : the ID of the map
  179.   #       name    : the name of the area you want
  180.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  181.   def area (name = '', map_id = $game_map.map_id)
  182.     @regions[map_id].each {|i| return i if i.name == name}
  183.     return false
  184.   end
  185. end
  186.  
  187. #==============================================================================
  188. # ** Game_Map
  189. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  190. #  Summary of Changes:
  191. #      aliased methods - encounter_list
  192. #==============================================================================
  193.  
  194. class Game_Map
  195.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196.   # * Encounter List
  197.   #       Returns the encounter list, with modifications based on level
  198.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199.   alias ma_encounter_areas_encounter_list encounter_list
  200.   def encounter_list
  201.     # Run original method
  202.     encounters = ma_encounter_areas_encounter_list
  203.     return encounters if $game_system.regions[@map_id].nil?
  204.     # Add monsters from each area the player is within
  205.     $game_system.regions[@map_id].each { |area|
  206.       next unless area.active
  207.       # Add all unique elements from the area to the encounter_list
  208.       encounters |= area.monster_troops if area.within? ($game_player.x, $game_player.y)
  209.     }
  210.     return encounters
  211.   end
  212. end
  213.  
  214. #======================================================================
  215. # ** Scene_Title
  216. #------------------------------------------------------------------------------
  217. #  Summary of Changes:
  218. #       aliased method - main
  219. #======================================================================
  220.  
  221. class Scene_Title
  222.   alias ma_encounter_regions_main_update main
  223.   def main
  224.     # Run original method
  225.     ma_encounter_regions_main_update
  226.     # Merge new database entries with the game areas
  227.     $game_system.update_regions
  228.   end
  229. end
Expand to see the code.


If anyone could help, that would be awesome!

um.... after some thinking, i figured out a way to use this script with events to get the effect i want.
But if someone still wants to add the options to this script.. that's fine with me, might make it easier.. but i noticed just now the script has a call script option for setting up areas.. i could use terrain tag options with it in events to get it.. *slaps self on the forehead*

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76954