RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Resolved]Modern Algebra's Encounter Range Script help

0 Members and 2 Guests are viewing this topic.

**
Rep: +0/-0Level 84
Okay awhile ago I found this script on a blog somewhere (Honestly, I can't recall it was a random Google search) and have since tried to get it to work so that my game's party doesn't get wiped out on the world map when they first begin, but then aren't bored with how easy it all is later on in the game.  The only problem is I can't figure out how the script works.  So I come and ask if anyone here knows a way or knows of a different script that is possibly easier to understand/implement.

Script:

Code: [Select]
#==============================================================================
# Encounter Range Script
# Version: 2.5b
# Author: Modern Algebra
# Date: August 25, 2007
#------------------------------------------------------------------------------
#  Instructions:
#  Set up the regular map encounter list with all of the global (appear all over
#  the map, regardless of area). Then you can set up areas in one of two ways:
#  1) Upon initialization. If you read down further in the Editable Region of 
#     the Data_Areas class, detailed instructions on how to do this are there.
#  2) In the map. You can add an area to the database very easily. This is
#     useful for two reasons. One, you can look at the map that you are setting
#     areas for, and two, you can set new areas once an event in the game occurs
#     (like a volcano or something erupting). All you need to do is use the
#     Script event command and enter this code:
#
#       range = $game_system.encounter_restrictions
#       range.set_area (x, y, width, height, troops array)
#
#     Unlike setting it to the database, you do not need to set a map id unless
#     you want the area to be set in a map different from the one you are in.
#     For more details on what that stuff means, look below in the Editable
#     Region of the Data_Areas class.
#------------------------------------------------------------------------------
#  Compatibility:
#  It ought to be compatible with any script that does not modify the
#  encounter_list method of Game_Map (and I can't think of any script that would
#  want to besides one like this). It will not initialize for old savefiles,
#  and this WILL cause problems. You must initialize this manually for old
#  savefiles.
#==============================================================================

class Encounter_Restrictions
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader   :troop_levels  # User-edited array containing troop levels
  attr_reader   :areas         # Contains area data
  attr_accessor :level_boolean # Turns on and off the level range function
  attr_accessor :min_level     # The lower limit of the encounter range
  attr_accessor :max_level     # The upper limit of the encounter range
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  def initialize
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    #  Each number in @troop_levels corresponds to a troop in the database,
    #  and it represents the level of that troop. Thus, if you want the 1st
    #  and 2nd troops to be a level 2 battle, then in those slots, you would
    #  put a 2, and if you wanted the 3rd troop in the database to be a level
    #  10 fight, then in the 3rd slot you would put a 10. The array would look
    #  like this:
    #
    #     @troop_levels = [2,2,10,etc...]
    # 
    #  You MUST give each troop in the database a level, at least all the ones
    #  you intend to have as random encounters at any point in the game
    #
    #  As for @min_level and @max_level, these values define the range of
    #  encounters, by level. For instance, if @min_level = -5, then the party
    #  can't encounter any troops that are more than 5 levels below the party
    #  average. If @max_level = 10, then the party can't encounter any troops
    #  that are more than 10 levels above the party average.
    #  To change these values in-game (in order to make certain maps harder
    #  or easier), just use these codes:
    #
    #     $game_system.encounter_restrictions.min_level = x
    #     $game_system.encounter_restrictions.max_level = x
    #
    #  Where x is the value you are changing it to.
    #
    #  You can also turn the levelling feature on and off at will, using
    #  this code:
    #
    #  $game_system.encounter_restrictions.level_boolean = true (to turn it on)
    #  $game_system.encounter_restrictions.level_boolean = false (to turn it off)
    #-----------------------------------------------------------------------
    @troop_levels = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
                     23,24,25,26,27,28,29,30,31,32,15,40,10,15,10,15]
    @min_level = -5
    @max_level = 10
    @level_boolean = true
    #-----------------------------------------------------------------------
    # * END Editable Region
    #-----------------------------------------------------------------------
    @troop_levels.unshift (nil)
    @areas = []
  end
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id = $game_map.map_id)
    area = Encounter_Area.new
    area.set_area (x, y, width, height, array, name, map_id)
    if @areas[map_id] == nil
      @areas[map_id] = []
    end
    @areas[map_id].push (area)
  end
  #-------------------------------------------------------------------------
  # * Update Areas
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def update_areas
    # Set variable to the database object
    data_areas = Data_Areas.new
    # For all areas in the database
    for area in data_areas.areas
      # If this is the first area to be set to that map
      if @areas[area.map_id] == nil
        # Initialize the array
        @areas[area.map_id] = []
      end
      # Set a test variable
      check = false
      # For all areas in the map of that database
      for area2 in @areas[area.map_id]
        # Check if the area is already contained within the @areas array
        check = area2.equals? (area)
        # If so, break the loop
        if check == true
          break
        end
      end
      # If the area is not in the @areas array
      if check == false
        # Add the area
        @areas[area.map_id].push (area)
      end
    end
  end
end
#==============================================================================
# ** Areas Database
#------------------------------------------------------------------------------
#  The object which represents an area
#==============================================================================

class Data_Areas
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader    :areas
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  def initialize
    @areas = []
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    # Set initial areas here. Set them up like this:
    #
    #    set_area (x, y, width, height, monster troop array, name, map_id)
    #
    # In the 1st example area below, we have defined an area at x = 10, y = 6,
    # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
    # in the area. Essentially, this means that on the first map, you can
    # encounter monster troops 2, 3 and 8 if the player coordinates are within
    # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
    # a name, then merely type in nil.
    #
    # You can set as many areas as you like for as many maps as you like.
    #-----------------------------------------------------------------------
    set_area (3,4,4,7,[1,33,34],'Graveyard',2)
    set_area (13,4,4,7,[37,38],'Farm',2)
    #----------------------------------------------------------------------
    # * End Editable Region
    #----------------------------------------------------------------------
  end
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id)
    area = Encounter_Area.new
    area.set_area (x, y, width, height, array, name, map_id)
    @areas.push (area)
  end
end

#==============================================================================
# ** Encounter Area
#------------------------------------------------------------------------------
#  The object which represents an area
#==============================================================================

class Encounter_Area
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader    :map_id
  attr_reader    :rect
  attr_reader    :monster_troops # The monsters within the troop
  attr_reader    :name
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds a Game_Area object to the array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id = $game_map.map_id)
    @rect = Rect.new (x, y, width, height)
    @monster_troops = array
    @name = name
    @map_id = map_id
  end
  #-------------------------------------------------------------------------
  # * Within?
  #     Checks if the position specified is within the area
  #-------------------------------------------------------------------------
  def within? (x, y)
    if x.between? (@rect.x, @rect.x + @rect.width - 1) && y.between? (@rect.y, @rect.y + @rect.height - 1)
      return true
    else
      return false
    end
  end
  #-------------------------------------------------------------------------
  # * Equals?
  #     Determine if two Encounter_Area objects are equal
  #-------------------------------------------------------------------------
  def equals? (other)
    if other.rect == @rect && other.map_id == @map_id
      return true
    else
      return false
    end
  end
end

#==============================================================================
# ** Game_Map
#==============================================================================

class Game_Map
  #-------------------------------------------------------------------------
  # * Get Area Encounter List
  #       Returns the encounter list, with modifications based on area
  #-------------------------------------------------------------------------
  def get_area_encounters
    encounter_list = @map.encounter_list.dup
    range = $game_system.encounter_restrictions
    # Add monsters from each area the player is within
    for area in range.areas[@map_id] # Areas
      # If the player is, in fact, within the area
      if area.within? ($game_player.x, $game_player.y)
        # Add all unique elements from the area to the encounter_list
        encounter_list |= area.monster_troops
      end
    end
    return encounter_list
  end
  #-------------------------------------------------------------------------
  # * Encounter List
  #       Returns the encounter list, with modifications based on level
  #-------------------------------------------------------------------------
  def encounter_list
    range = $game_system.encounter_restrictions
    true_encounter_list = get_area_encounters
    # If level range is being taken into account
    if range.level_boolean == true
      encounter_list = []
      # Calculate Party Level Average
      average_level = 0
      for actor in $game_party.actors
        average_level += actor.level
      end
      average_level /= $game_party.actors.size
      # Test average agains all troops in the list
      for i in 0...true_encounter_list.size
        troop_level = range.troop_levels[true_encounter_list[i]]
        # Set Range
        minimum = [average_level + range.min_level,1].max
        maximum = [average_level + range.max_level,99].min
        # If actor level within range
        if troop_level.between? (minimum, maximum)
          # Add to the returning array
          encounter_list.push (true_encounter_list[i])
        end
      end
    else
      # Return the full encounter list, taking into account areas
      encounter_list = true_encounter_list
    end
    return encounter_list
  end
end

#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  Aliases command_new_game method to initialize $game_system.encounter_restrictions
#  and aliases main method to initialize $data_areas
#==============================================================================

class Scene_Title
  alias encounter_restrictions_update main
  def main
    # Run original method
    encounter_restrictions_update
    # Merge the database areas with the game areas
    $game_system.encounter_restrictions.update_areas
  end
end

#==============================================================================
# ** Game_System (Encounter Restrictions)
#------------------------------------------------------------------------------
# Adds an instance variable for access to the Script
#==============================================================================

class Game_System
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader   :encounter_restrictions
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  alias encounter_restrictions_initialize initialize
  def initialize
    encounter_restrictions_initialize
    @encounter_restrictions = Encounter_Restrictions.new
  end
end

Edit:  If I used the wrong forum section I'm sorry.  I wasn't sure if this could be considered a request or help ... sorry, if I am wrong then I will willing accept any repercussion of this action.
« Last Edit: September 25, 2008, 07:10:40 PM by shadowmimiiru »

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
couldn't you just manually make the later level monsters harder?
the script would keep difficulty always at the same level, instead of getting progressively harder as the game goes on, which would remove the aspect of challenge from late-game.

that and it'd be one less script to worry about.

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Well, he can't really. If he has one world map to which he returns at level 1 and then level 8 and then level 30, and he wants battles to occur by random encounter, then he would have to put the level 30 monsters in the list with the level 1 monsters. He could do it if he set monsters not by random encounter but as events on the map.

Anyway, it's not hard to set up shadowmimiiru.

Go down to this area of the script:

Code: [Select]
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    # Set initial areas here. Set them up like this:
    #
    #    set_area (x, y, width, height, monster troop array, name, map_id)
    #
    # In the 1st example area below, we have defined an area at x = 10, y = 6,
    # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
    # in the area. Essentially, this means that on the first map, you can
    # encounter monster troops 2, 3 and 8 if the player coordinates are within
    # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
    # a name, then merely type in nil.
    #
    # You can set as many areas as you like for as many maps as you like.
    #-----------------------------------------------------------------------
    set_area (3,4,4,7,[1,33,34],'Graveyard',2)
    set_area (13,4,4,7,[37,38],'Farm',2)
    #----------------------------------------------------------------------
    # * End Editable Region
    #----------------------------------------------------------------------
I can see why you're confused - the example referred to in the description is not the actual first one.

So, anyway, to set an area, write this code:

set_area (x, y, width, height, monster_array, name, map_id)

So, set_area (0, 0, 20, 15, [1, 4, 8], nil, 3)

Would set an area on Map 3, and the monster troops with IDs 1, 4, and 8 would appear on the map if the player is within the rectangle defined with x within 0 and 19 and y within 0 and 14.

If the map happened to be 20 x 15, then that would be the entire map. If the map were 80 x 60, then it would be in the upper left corner of the map.

Is that understandable?

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
my bad, I totally forgot XP doesn't have proper world map functions.

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
Well, he can't really. If he has one world map to which he returns at level 1 and then level 8 and then level 30, and he wants battles to occur by random encounter, then he would have to put the level 30 monsters in the list with the level 1 monsters. He could do it if he set monsters not by random encounter but as events on the map.

Anyway, it's not hard to set up shadowmimiiru.

Go down to this area of the script:

Code: [Select]
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    # Set initial areas here. Set them up like this:
    #
    #    set_area (x, y, width, height, monster troop array, name, map_id)
    #
    # In the 1st example area below, we have defined an area at x = 10, y = 6,
    # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
    # in the area. Essentially, this means that on the first map, you can
    # encounter monster troops 2, 3 and 8 if the player coordinates are within
    # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
    # a name, then merely type in nil.
    #
    # You can set as many areas as you like for as many maps as you like.
    #-----------------------------------------------------------------------
    set_area (3,4,4,7,[1,33,34],'Graveyard',2)
    set_area (13,4,4,7,[37,38],'Farm',2)
    #----------------------------------------------------------------------
    # * End Editable Region
    #----------------------------------------------------------------------
I can see why you're confused - the example referred to in the description is not the actual first one.

So, anyway, to set an area, write this code:

set_area (x, y, width, height, monster_array, name, map_id)

So, set_area (0, 0, 20, 15, [1, 4, 8], nil, 3)

Would set an area on Map 3, and the monster troops with IDs 1, 4, and 8 would appear on the map if the player is within the rectangle defined with x within 0 and 19 and y within 0 and 14.

If the map happened to be 20 x 15, then that would be the entire map. If the map were 80 x 60, then it would be in the upper left corner of the map.

Is that understandable?

I think it does ...

so should it look like this then?

Code: [Select]
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id)
    area = Encounter_Area.new
    area.set_area (0, 0, 10, 7, [1, 2, 3], nil, 1)
    area.set_area (11, 8, 20, 15, [3, 4, 5], nil, 1)
    @areas.push (area)
  end
end


I'm sorry.  I'm not much good with this kind of thing.


*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Well, it should look like that but you're at the wrong place.

Leave that part alone entirely.

The part you are editing is here:

Code: [Select]
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    # Set initial areas here. Set them up like this:
    #
    #    set_area (x, y, width, height, monster troop array, name, map_id)
    #
    # In the 1st example area below, we have defined an area at x = 10, y = 6,
    # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
    # in the area. Essentially, this means that on the first map, you can
    # encounter monster troops 2, 3 and 8 if the player coordinates are within
    # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
    # a name, then merely type in nil.
    #
    # You can set as many areas as you like for as many maps as you like.
    #-----------------------------------------------------------------------
    set_area (3,4,4,7,[1,33,34],'Graveyard',2)
    set_area (13,4,4,7,[37,38],'Farm',2)
    #----------------------------------------------------------------------
    # * End Editable Region
    #----------------------------------------------------------------------

Where the

    set_area (3,4,4,7,[1,33,34],'Graveyard',2)
    set_area (13,4,4,7,[37,38],'Farm',2)

parts are, replace that with:

    set_area (0, 0, 10, 7, [1, 2, 3], nil, 1)
    set_area (11, 8, 20, 15, [3, 4, 5], nil, 1)

And the part of the code you edited will have to be restored to normal:

Code: [Select]

  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id)
    area = Encounter_Area.new
    area.set_area (x, y, width, height, array, name, map_id)
    @areas.push (area)
  end

**
Rep: +0/-0Level 84
Okay, I made the fix and tried the game.  I get an error before the title screen on line 327 which is the very last line in the script.

Code: [Select]

  alias encounter_restrictions_initialize initialize
  def initialize
    encounter_restrictions_initialize
    @encounter_restrictions = Encounter_Restrictions.new
  end


also, I want to thank you for the help so far.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
What does the error message say?

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
most likely "syntax error"
pointing to a missing end statement somewhere.

Given that it's the last line of code, and he's been modifying stuff near 'end' statements, I mean.
I could easily be wrong n_n;;

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
Nope, you're right.  Sorry for the late statement, I was asked to do a double shift.  Yeah, I was missing another "end" there, so now everything works, and I have the wonderfully daunting task of setting this up for my world map.

Thanks for all the help.

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
actually I think you might have been missing an 'end' statement earlier in the script, and it just doesn't catch until the final line.

could you post in code tags, what your script is?

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
actually I think you might have been missing an 'end' statement earlier in the script, and it just doesn't catch until the final line.

could you post in code tags, what your script is?

Sure, this is the edited one using MA's second response to my question:

Code: [Select]

#==============================================================================
# Encounter Range Script
# Version: 2.5b
# Author: Modern Algebra
# Date: August 25, 2007
#------------------------------------------------------------------------------
#  Instructions:
#  Set up the regular map encounter list with all of the global (appear all over
#  the map, regardless of area). Then you can set up areas in one of two ways:
#  1) Upon initialization. If you read down further in the Editable Region of 
#     the Data_Areas class, detailed instructions on how to do this are there.
#  2) In the map. You can add an area to the database very easily. This is
#     useful for two reasons. One, you can look at the map that you are setting
#     areas for, and two, you can set new areas once an event in the game occurs
#     (like a volcano or something erupting). All you need to do is use the
#     Script event command and enter this code:
#
#       range = $game_system.encounter_restrictions
#       range.set_area (x, y, width, height, troops array)
#
#     Unlike setting it to the database, you do not need to set a map id unless
#     you want the area to be set in a map different from the one you are in.
#     For more details on what that stuff means, look below in the Editable
#     Region of the Data_Areas class.
#------------------------------------------------------------------------------
#  Compatibility:
#  It ought to be compatible with any script that does not modify the
#  encounter_list method of Game_Map (and I can't think of any script that would
#  want to besides one like this). It will not initialize for old savefiles,
#  and this WILL cause problems. You must initialize this manually for old
#  savefiles.
#==============================================================================

class Encounter_Restrictions
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader   :troop_levels  # User-edited array containing troop levels
  attr_reader   :areas         # Contains area data
  attr_accessor :level_boolean # Turns on and off the level range function
  attr_accessor :min_level     # The lower limit of the encounter range
  attr_accessor :max_level     # The upper limit of the encounter range
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  def initialize
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    #  Each number in @troop_levels corresponds to a troop in the database,
    #  and it represents the level of that troop. Thus, if you want the 1st
    #  and 2nd troops to be a level 2 battle, then in those slots, you would
    #  put a 2, and if you wanted the 3rd troop in the database to be a level
    #  10 fight, then in the 3rd slot you would put a 10. The array would look
    #  like this:
    #
    #     @troop_levels = [2,2,10,etc...]
    # 
    #  You MUST give each troop in the database a level, at least all the ones
    #  you intend to have as random encounters at any point in the game
    #
    #  As for @min_level and @max_level, these values define the range of
    #  encounters, by level. For instance, if @min_level = -5, then the party
    #  can't encounter any troops that are more than 5 levels below the party
    #  average. If @max_level = 10, then the party can't encounter any troops
    #  that are more than 10 levels above the party average.
    #  To change these values in-game (in order to make certain maps harder
    #  or easier), just use these codes:
    #
    #     $game_system.encounter_restrictions.min_level = x
    #     $game_system.encounter_restrictions.max_level = x
    #
    #  Where x is the value you are changing it to.
    #
    #  You can also turn the levelling feature on and off at will, using
    #  this code:
    #
    #  $game_system.encounter_restrictions.level_boolean = true (to turn it on)
    #  $game_system.encounter_restrictions.level_boolean = false (to turn it off)
    #-----------------------------------------------------------------------
    @troop_levels = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
                     23,24,25,26,27,28,29,30,31,32,15,40,10,15,10,15]
    @min_level = -5
    @max_level = 10
    @level_boolean = true
    #-----------------------------------------------------------------------
    # * END Editable Region
    #-----------------------------------------------------------------------
    @troop_levels.unshift (nil)
    @areas = []
  end
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id = $game_map.map_id)
    area = Encounter_Area.new
    area.set_area (x, y, width, height, array, name, map_id)
    if @areas[map_id] == nil
      @areas[map_id] = []
    end
    @areas[map_id].push (area)
  end
  #-------------------------------------------------------------------------
  # * Update Areas
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def update_areas
    # Set variable to the database object
    data_areas = Data_Areas.new
    # For all areas in the database
    for area in data_areas.areas
      # If this is the first area to be set to that map
      if @areas[area.map_id] == nil
        # Initialize the array
        @areas[area.map_id] = []
      end
      # Set a test variable
      check = false
      # For all areas in the map of that database
      for area2 in @areas[area.map_id]
        # Check if the area is already contained within the @areas array
        check = area2.equals? (area)
        # If so, break the loop
        if check == true
          break
        end
      end
      # If the area is not in the @areas array
      if check == false
        # Add the area
        @areas[area.map_id].push (area)
      end
    end
  end
end
#==============================================================================
# ** Areas Database
#------------------------------------------------------------------------------
#  The object which represents an area
#==============================================================================

class Data_Areas
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader    :areas
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  def initialize
    @areas = []
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    # Set initial areas here. Set them up like this:
    #
    #    set_area (x, y, width, height, monster troop array, name, map_id)
    #
    # In the 1st example area below, we have defined an area at x = 10, y = 6,
    # width = 4, height = 5, in the 1st map with monsters 2, 3, and 8 appearing
    # in the area. Essentially, this means that on the first map, you can
    # encounter monster troops 2, 3 and 8 if the player coordinates are within
    # (10-13, 6-10). The name is 'Lies'. If you do not want to give the area
    # a name, then merely type in nil.
    #
    # You can set as many areas as you like for as many maps as you like.
    #-----------------------------------------------------------------------
    set_area (0, 0, 10, 7, [1, 2, 3], nil, 1)
    set_area (11, 8, 20, 15, [3, 4, 5], nil, 1)
    #----------------------------------------------------------------------
    # * End Editable Region
    #----------------------------------------------------------------------
  end
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id)
    area = Encounter_Area.new
    area.set_area (x, y, width, height, array, name, map_id)
    @areas.push (area)
  end
end

#==============================================================================
# ** Encounter Area
#------------------------------------------------------------------------------
#  The object which represents an area
#==============================================================================

class Encounter_Area
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader    :map_id
  attr_reader    :rect
  attr_reader    :monster_troops # The monsters within the troop
  attr_reader    :name
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds a Game_Area object to the array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id = $game_map.map_id)
    @rect = Rect.new (x, y, width, height)
    @monster_troops = array
    @name = name
    @map_id = map_id
  end
  #-------------------------------------------------------------------------
  # * Within?
  #     Checks if the position specified is within the area
  #-------------------------------------------------------------------------
  def within? (x, y)
    if x.between? (@rect.x, @rect.x + @rect.width - 1) && y.between? (@rect.y, @rect.y + @rect.height - 1)
      return true
    else
      return false
    end
  end
  #-------------------------------------------------------------------------
  # * Equals?
  #     Determine if two Encounter_Area objects are equal
  #-------------------------------------------------------------------------
  def equals? (other)
    if other.rect == @rect && other.map_id == @map_id
      return true
    else
      return false
    end
  end
end

#==============================================================================
# ** Game_Map
#==============================================================================

class Game_Map
  #-------------------------------------------------------------------------
  # * Get Area Encounter List
  #       Returns the encounter list, with modifications based on area
  #-------------------------------------------------------------------------
  def get_area_encounters
    encounter_list = @map.encounter_list.dup
    range = $game_system.encounter_restrictions
    # Add monsters from each area the player is within
    for area in range.areas[@map_id] # Areas
      # If the player is, in fact, within the area
      if area.within? ($game_player.x, $game_player.y)
        # Add all unique elements from the area to the encounter_list
        encounter_list |= area.monster_troops
      end
    end
    return encounter_list
  end
  #-------------------------------------------------------------------------
  # * Encounter List
  #       Returns the encounter list, with modifications based on level
  #-------------------------------------------------------------------------
  def encounter_list
    range = $game_system.encounter_restrictions
    true_encounter_list = get_area_encounters
    # If level range is being taken into account
    if range.level_boolean == true
      encounter_list = []
      # Calculate Party Level Average
      average_level = 0
      for actor in $game_party.actors
        average_level += actor.level
      end
      average_level /= $game_party.actors.size
      # Test average agains all troops in the list
      for i in 0...true_encounter_list.size
        troop_level = range.troop_levels[true_encounter_list[i]]
        # Set Range
        minimum = [average_level + range.min_level,1].max
        maximum = [average_level + range.max_level,99].min
        # If actor level within range
        if troop_level.between? (minimum, maximum)
          # Add to the returning array
          encounter_list.push (true_encounter_list[i])
        end
      end
    else
      # Return the full encounter list, taking into account areas
      encounter_list = true_encounter_list
    end
    return encounter_list
  end
end

#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  Aliases command_new_game method to initialize $game_system.encounter_restrictions
#  and aliases main method to initialize $data_areas
#==============================================================================

class Scene_Title
  alias encounter_restrictions_update main
  def main
    # Run original method
    encounter_restrictions_update
    # Merge the database areas with the game areas
    $game_system.encounter_restrictions.update_areas
  end
end

#==============================================================================
# ** Game_System (Encounter Restrictions)
#------------------------------------------------------------------------------
# Adds an instance variable for access to the Script
#==============================================================================

class Game_System
  #------------------------------------------------------------------------
  # * Public Instance Variables
  #------------------------------------------------------------------------
  attr_reader   :encounter_restrictions
  #------------------------------------------------------------------------
  # * Object Initialization
  #------------------------------------------------------------------------
  alias encounter_restrictions_initialize initialize
  def initialize
    encounter_restrictions_initialize
    @encounter_restrictions = Encounter_Restrictions.new
  end
end


********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
k, they all seem to be in place :)

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
Cool, and I have one final question.  Again, thank you all for the help so far.  How does the Troop level area work?

I'm not sure, but is this how it'd work?

Code: [Select]
    @troop_levels = [1,2,3,4,5,6,7,8,9,10,11]
    @min_level = -5
    @max_level = 10
    @troop_levels = [23,24,25,26,27,28,29,30,31,32,15,40,10,15,10,15]
    @min_level = 11
    @max_level = 20
    @level_boolean = true

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
you don't need multiple @troop_levels.

each spot on the array is a troop id in the database.
the level you want that troop to be read as is what you put there.

so say troop ID 1 is a pair of ghosts, and you want it to be level 1
troop ID 2 is a sahuagin, and you want it to be lv5
and troop 3 is a vampire you want at level 10
you'd make it look as follows

Code: [Select]
@troop_levels = [1, 5, 10]

add more as you need for every troop in the database.
I assume that EVERY troop must have a level as well

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
you don't need multiple @troop_levels.

each spot on the array is a troop id in the database.
the level you want that troop to be read as is what you put there.

so say troop ID 1 is a pair of ghosts, and you want it to be level 1
troop ID 2 is a sahuagin, and you want it to be lv5
and troop 3 is a vampire you want at level 10
you'd make it look as follows

Code: [Select]
@troop_levels = [1, 5, 10]

add more as you need for every troop in the database.
I assume that EVERY troop must have a level as well

Okay, but then I think that opens another problem which goes back to my original question.

what troop array is being used then in this:

Code: [Select]
  #-------------------------------------------------------------------------
  # * Set Area
  #     Adds an Encounter_Area object to the areas array.
  #-------------------------------------------------------------------------
  def set_area (x, y, width, height, array, name, map_id)
    area = Encounter_Area.new
    area.set_area (0, 0, 10, 7, [1, 2, 3], nil, 1)
    area.set_area (11, 8, 20, 15, [3, 4, 5], nil, 1)
    @areas.push (area)
  end
end

does it relate to the troop levels thing or is it different?

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
that just sets the area size and position, and which enemies show up in there.
it has nothing to do with enemy levels

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
Okay, so troop levels indicate what level in a range of -5 to +10 a character needs to be for a monster in an array to appear.  While the array mentioned in the area set section refers to the troop ID.  So for instance:

Code: [Select]
@troop_levels = [2, 5, 7]

Where Ghost*2 is ID 1, Ghost*3 is ID 2, and Basilisk*2 is ID 3.

This means that Ghost*2 is a level 2 encounter, Ghost*3 is a level 5 encounter, and Basilisk*2 is a level 7 encounter.

and then

Code: [Select]
area.set_area (0, 0, 20, 15, [1, 2, 3], nil, 1)

Means that while in that area any of these monsters can attack you but if you are level 2 and walking through the area only Ghost*2 will attack, and if level 7 only the Basilisk*2 will attack.

Of course these example doesn't take into account the

Spoiler for:
    @min_level = -5
    @max_level = 10

but trying to work that into my immediate need for understanding would get confusing.

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
minimum level is the level of the troop -5
maximum level is the level of the troop +10

if the party level falls between those, then the enemies will appear

so if basilisk is lv7
then party levels 2-17 will cause it to appear.

(I believe)

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Okay, so troop levels indicate what level in a range of -5 to +10 a character needs to be for a monster in an array to appear.  While the array mentioned in the area set section refers to the troop ID.  So for instance:

Code: [Select]
@troop_levels = [2, 5, 7]

Where Ghost*2 is ID 1, Ghost*3 is ID 2, and Basilisk*2 is ID 3.

This means that Ghost*2 is a level 2 encounter, Ghost*3 is a level 5 encounter, and Basilisk*2 is a level 7 encounter.

and then

Code: [Select]
area.set_area (0, 0, 20, 15, [1, 2, 3], nil, 1)

Means that while in that area any of these monsters can attack you

All correct. However, the min level and max level are crucial to what monsters you can fight at what level.

but if you are level 2 and walking through the area only Ghost*2 will attack, and if level 7 only the Basilisk*2 will attack.

would be right if @min_level = 0 and @max_level = 0

What NAM has said about min and max level is pretty much correct, except min and max level are in relation to the party and not the troop. With @min_level = -5 and @max_level = 10 it means that the party will face monsters that are between 5 levels lower than the party and 10 levels higher than the party. This means that if an enemy's troop level is 12, then the party will be able to face it between levels 2 and 17. (2 because 2 + 10 (@max_level) = 12 and 17 because 17 - 5 (@min_level) = 12). So, the party will face that troop as long as they are at least level 2 and at most level 17.

********
Hungry
Rep:
Level 96
Mawbeast
2013 Best ArtistParticipant - GIAW 11Secret Santa 2013 ParticipantFor the great victory in the Breakfast War.2012 Best Game Creator (Non-RM Programs)~Bronze - GIAW 9Project of the Month winner for December 2009Project of the Month winner for August 20082011 Best Game Creator (Non RM)Gold - GIAW Halloween
hehe, whoops :P

FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: Bandcamp | Twitter | Patreon

**
Rep: +0/-0Level 84
Understood across the board then.  Thanks again for the help you two.  I guess baring any unseen problems I'll mark this as resolved.  Modern, this is a great script btw, no brown nosing intended.