Essentials Docs Wiki

The Essentials wiki has moved and is now at: Essentials Engine wiki

This wiki will no longer be updated.

READ MORE

Essentials Docs Wiki
(Created page with ": ''For how to set up wild encounters on maps, see Wild encounters.'' : ''For triggering an encounter with a specific wild Pokémon, see Event encounters.'' This page descri...")
Tag: Visual edit
 
Maruno (talk | contribs)
mNo edit summary
Tag: Source edit
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
: ''For how to set up wild encounters on maps, see Wild encounters.''
+
{{for|how to set up wild encounters on maps|Wild encounters}}
: ''For triggering an encounter with a specific wild Pokémon, see Event encounters.''
+
{{for|triggering an encounter with a specific wild Pokémon|Event encounters}}
This page describes how to create '''new wild encounter methods'''. An explanation of what an encounter method is can be found on the Wild encounters page.
+
This page describes how to create '''new wild encounter methods'''. An explanation of what an encounter method is can be found on the [[Wild encounters]] page.
   
 
There are two steps to adding a new encounter method:
 
There are two steps to adding a new encounter method:
  +
# Defining it (getting the game to recognise it as an encounter method)
 
# Making it work (changing which wild encounter list to use depending on the new encounter method)
+
# Defining it (getting the game to recognise it as an encounter method).
  +
# Making it work (changing which list of wild encounters to use depending on the new encounter method).
This page will add <code>LandAfternoon</code> as an example. Additional code required to add this encounter method will be highlighted.
 
   
 
== Defining an encounter method ==
 
== Defining an encounter method ==
All encounter methods are defined at the top of the script section '''PField_Encounters''', in <code>module EncounterTypes</code>. Additional information needs to be added to this module in order to define a new encounter method.
 
   
  +
All encounter methods are defined in the script section '''EncounterType'''. Each encounter method is registered in the Game Data separately; you can define additional encounter methods in any script section (you can put all your new ones in a new script section to keep track of the code changes you make).
There are five sets of data in the module.
 
   
 
Examples of definitions of encounter methods are:
=== Internal names and IDs ===
 
The first set of data is a group of internal names for the encounter methods, as well as an ID number for each of them. Each encounter method needs a unique ID number. It is more convenient to not skip numbers. The internal name is how they are referred to in the scripts, e.g. <code>EncounterTypes::RockSmash</code>.
 
   
  +
GameData::EncounterType.register({
It is simple to add another encounter method here:
 
Land = 0
+
:id => :Land,
Cave = 1
+
:type => :land,
  +
:trigger_chance => 21,
Water = 2
 
 
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
RockSmash = 3
 
  +
})
OldRod = 4
 
GoodRod = 5
 
SuperRod = 6
 
HeadbuttLow = 7
 
HeadbuttHigh = 8
 
LandMorning = 9
 
LandDay = 10
 
LandNight = 11
 
BugContest = 12
 
 
   
  +
GameData::EncounterType.register({
=== Display names ===
 
 
:id => :CaveNight,
The <code>Names</code> array contains the names of the encounter methods. These names are used in the PBS file "encounters.txt". For convenience, these names are identical to the internal names above.
 
  +
:type => :cave,
Names = [
 
  +
:trigger_chance => 5,
"Land",
 
 
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
"Cave",
 
  +
})
"Water",
 
"RockSmash",
 
"OldRod",
 
"GoodRod",
 
"SuperRod",
 
"HeadbuttLow",
 
"HeadbuttHigh",
 
"LandMorning",
 
"LandDay",
 
"LandNight",
 
"BugContest"
 
 
]
 
   
  +
GameData::EncounterType.register({
=== Data slots and relative probabilities ===
 
  +
:id => :OldRod,
The <code>EnctypeChances</code> array contains an array of numbers for each encounter method. These numbers define how many data slots each encounter method has (how many numbers are in each array) as well as the relative probability of choosing each data slot (the value of each number).
 
  +
:type => :fishing,
  +
:old_slots => [70, 30]
  +
})
   
  +
GameData::EncounterType.register({
For example, the first entry of this array is for the "Land" encounter method. It contains 12 numbers, which means that it has 12 data slots. The first number is 20, and the last number is 1; this means that the first encounter slot is 20 times as likely to be chosen as the last encounter slot.
 
 
:id => :RockSmash,
  +
:type => :none,
  +
:trigger_chance => 50,
 
:old_slots => [60, 30, 5, 4, 1]
  +
})
   
  +
The properties an encounter method can be given are as follows:
For convenience, the numbers for each existing encounter method add up to 100, so that a number is also a percentage (which is easy to understand). However, the numbers don't have to add up to 100; an encounter method's array could be <code>[1,1,1]</code>, which would mean three data slots of equal probability (33.3% each).
 
EnctypeChances = [
 
[20,20,10,10,10,10,5,5,4,4,1,1],
 
[20,20,10,10,10,10,5,5,4,4,1,1],
 
[60,30,5,4,1],
 
[60,30,5,4,1],
 
[70,30],
 
[60,20,20],
 
[40,40,15,4,1],
 
[30,25,20,10,5,5,4,1],
 
[30,25,20,10,5,5,4,1],
 
[20,20,10,10,10,10,5,5,4,4,1,1],
 
[20,20,10,10,10,10,5,5,4,4,1,1],
 
[20,20,10,10,10,10,5,5,4,4,1,1],
 
[20,20,10,10,10,10,5,5,4,4,1,1]
 
 
]
 
   
  +
{| class="article-table" border="1"
=== Default encounter densities ===
 
  +
! Property
The <code>EnctypeDensities</code> array contains the default encounter density values for each encounter method (one number each). An encounter density is the probability of generating an encounter at all of that encounter method - with no modifications, the probability is the encounter density divided by 180.
 
  +
! Description
  +
! Necessary?
  +
|-
  +
| <code>:id</code>
  +
| The ID of the encounter type, as a symbol.
  +
| Yes
  +
|-
  +
| <code>:type</code>
  +
| The category that this encounter type belongs to. Is one of <code>:land</code>, <code>:cave</code>, <code>:water</code>, <code>:fishing</code>, <code>:contest</code> or <code>:none</code>.
   
  +
The type has several effects. <code>:land</code> is for encounter types that occur when moving in tall grass, [[roaming Pokémon]] can be made to appear only for certain types of encounter, the [[Poké Radar]] only works for <code>:land</code> encounter types, and so on.
A higher number means encounters are more likely to happen. Lower numbers are less likely. For example, "Land" has an encounter density of 25, while "Cave" is only 10. This makes the encounter rate fairer, as "Land" encounters occur only in tall grass (there are tiles you can walk on which aren't tall grass), whereas "Cave" encounters can occur on every single step in a cave (there is no escape from them).
 
  +
| No (default is <code>:none</code>)
  +
|-
  +
| <code>:trigger_chance</code>
  +
| This is the percentage chance that an encounter using this encounter method will happen when prompted (e.g. upon taking a step, upon using Rock Smash). It is used as the default step chance when creating a new set of wild encounters in the [[Debug mode]] feature "Edit Wild Encounters", but is not used by anything else.
   
  +
For encounter methods that are prompted by taking a step (in tall grass, caves, surfing), this number also determines how many steps the player can take after a battle before another another encounter could happen (max. 8, but lower if this trigger chance is higher). Effects that alter the encounter rate also affect the number of "safe" steps (e.g. Cleanse Tag reduces the trigger chance and increases the number of "safe" steps).
Not all encounter methods require an encounter density. Typically only encounter methods used due to moving around use them, whereas triggered encounters such as fishing or using Rock Smash do not. Give the encounter methods that don't need an encounter density a value of 0 here.
 
  +
| No (default is 0)
  +
|-
  +
| <code>:old_slots</code>
  +
| This property is only used for old encounter methods, as part of converting an old format "[[Wild encounters|encounters.txt]]" [[PBS file]] to the current format. It is an array of the relative chances each encounter slot has of being chosen for a generated wild encounter. As they are relative numbers, they do not have to add to 100.
 
| No (only for old encounter methods)
  +
|}
   
  +
All encounter methods are compatible with all other encounter methods. For example, a map could have both :Cave and :Land wild encounters defined, and the :Land encounters would be used if the player walks in tall grass, while the :Cave encounters would be used if the player walks anywhere else.
On top of all that, these values are only used if a map doesn't define its own encounter densities in the PBS file"encounters.txt". If it does, then all "Land"-type encounter methods use the same defined number, all "Cave"-type encounter methods will use one other defined number, and all "Water"-type encounter methods will use the third defined number.
 
EnctypeDensities = [25,10,10,0,0,0,0,0,0,25,25,25,25]
 
   
=== Encounter method types ===
+
== Making the encounter method work ==
Following on from above, if a map defines its own encounter densities, it will need to know which encounter methods are "Land"-type", which are "Cave"-type and which are "Water"-type. That is the purpose of the <code>EnctypeCompileDens</code> array.
 
   
Each encounter method is defined as "Land"-type (1), "Cave"-type (2) or "Water"-type (3), or 0 if it doesn't need a type (i.e. its default encounter density is 0).
+
Once an encounter method is properly defined, scripts need to be altered to make use of it at the appropriate times. This may not be straightforward to do, depending on when exactly it should be used.
   
  +
There are two possible ways to use an encounter method to trigger a wild encounter:
If you want to have a fourth (or fifth, etc.) type of encounter method, you can use 4 and so on here and the code will automatically support it. Remember to ensure that any map in the PBS file "encounters.txt" which defines its own encounter densities has the appropriate number of encounter density values.
 
EnctypeCompileDens = [1,2,3,0,0,0,0,0,0,1,1,1,1]
 
   
 
* Taking a step: The game decides which encounter method needs to be used (in <code>def encounter_type</code> in <code>class PokemonEncounters</code>). This decision can depend on a variety of factors, such as which encounter methods are used by the current map, whether something special is happening (e.g. the player is surfing, there is a [[Bug Catching Contest]] in progress), and/or the [[Time|time of day]]. You can add your own factors too.
== Mutually exclusive encounter methods ==
 
  +
* Direct triggering: A wild encounter is directly triggered by using an item (e.g. fishing rods) or by [[using moves outside battle]] (e.g. Rock Smash, Headbutt). The thing that triggered the wild encounter will determine the encounter method to use.
Some encounter methods have restrictions on how and when they can be used. The only example of this in Essentials is that the "Cave" encounter method cannot be used in the same map as a "Land"-type encounter method (and vice versa).
 
   
  +
When making something that directly triggers a wild encounter, the advice is to copy an existing thing that works similarly.
This mutual exclusivity is defined in <code>def pbCompileEncounters</code> in the script section '''Compiler''':
 
if thisenc && (thisenc[1][EncounterTypes::Land] ||
 
thisenc[1][EncounterTypes::LandMorning] ||
 
thisenc[1][EncounterTypes::LandDay] ||
 
thisenc[1][EncounterTypes::LandNight] ||
 
thisenc[1][EncounterTypes::BugContest]
 
) &&
 
thisenc[1][EncounterTypes::Cave]
 
raise _INTL("Can't define both Land and Cave encounters in the same area (map ID {1})",mapid)
 
end
 
This code checks whether any map has both the "Cave" encounter method and any of the encounter methods used for tall grass. If so, produces an error message.
 
   
 
=== "Taking a step" encounter methods ===
There is similar code in <code>def pbNewEncounterType</code> in the script section '''Editor_Screens'''. In this case, it prevents the user from using the "Set Encounters" debug option to define a map with both incompatible encounter methods.
 
   
 
The game decides which encounter method needs to be used in any given situation. It makes this decision in <code>def encounter_type</code> in <code>class PokemonEncounters</code>.
If a new encounter method you are adding is incompatible with one or more other encounter methods, you should add code like this to make sure a map can't be defined with both encounter methods.
 
   
  +
def encounter_type
== Making the encounter method work ==
 
 
time = pbGetTimeNow
Once the encounter method is properly defined, you then need to alter the scripts to make them use it where appropriate. This may not be straightforward to do, depending on when exactly it should be used.
 
  +
ret = nil
 
if $PokemonGlobal.surfing
  +
ret = find_valid_encounter_type_for_time(:Water, time)
  +
else # Land/Cave (can have both in the same map)
  +
if has_land_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).land_wild_encounters
 
ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest)
  +
ret = find_valid_encounter_type_for_time(:Land, time) if !ret
 
end
  +
if !ret && has_cave_encounters?
  +
ret = find_valid_encounter_type_for_time(:Cave, time)
 
end
  +
end
 
return ret
 
end
   
There are two possible ways to use an encounter method to trigger a wild encounter:
+
The encounter method returned by this code is the ''only'' encounter method attempted.
* Taking a step: The game decides which encounter method needs to be used (via <code>def pbEncounterType</code>). This decision can depend on a variety of factors, such as which encounter methods are used by the current map, whether something special is happening (e.g. the player is surfing, there is a Bug Catching Contest in progress), and/or the time of day. You can add your own factors too.
 
* Triggering an encounter: The thing that triggered the encounter will set the encounter method to use. This can be done by using an item (e.g. fishing rods) or by using moves outside battle (e.g. Rock Smash, Headbutt).
 
Other situations are also possible, but the above are the only things that matter to the encounter methods in Essentials.
 
   
  +
The code <code>has_land_encounters?</code> and <code>has_cave_encounters?</code> checks whether there are wild encounters of those types (see the <code>:type</code> property above) defined for the current map. There is also <code>has_water_encounters?</code>, which is currently unused.
The advice when adding a new encounter method is to find an existing encounter method that works similarly to the way you want your new one to work, and copy it.
 
   
  +
Note the way in which this script is written. For example, if the player is surfing, it will ''only'' check for Water encounter methods, and it checks this first because the current map may have cave-type encounters (triggered upon every step, even while surfing), but it is not appropriate to check for the :Cave encounter methods while surfing. Another example is the :BugContest encounter method, which is checked before the other :Land encounter methods (which are then skipped if the player is in a [[Bug Catching Contest]] and :BugContest encounters are defined for the current map).
=== "Taking a step"-type encounter methods ===
 
  +
The game decides which encounter method needs to be used. It makes this decision in <code>def pbEncounterType</code>, in the script section '''PField_Encounters'''.
 
  +
After deciding whether the player is surfing, or the map has and land- or cave-type encounters defined, or whether the player is in a [[Bug Catching Contest]], the above script calls <code>def find_valid_encounter_type_for_time</code> with an appropriate "base type" (<code>:Land</code>, <code>:Cave</code> or <code>:Water</code>) and the current time.
def pbEncounterType
 
  +
if $PokemonGlobal && $PokemonGlobal.surfing
 
  +
def find_valid_encounter_type_for_time(base_type, time)
return EncounterTypes::Water
 
  +
ret = nil
elsif self.isCave?
 
  +
if PBDayNight.isDay?(time)
return EncounterTypes::Cave
 
  +
try_type = nil
elsif self.isGrass?
 
  +
if PBDayNight.isMorning?(time)
time = pbGetTimeNow
 
  +
try_type = (base_type.to_s + "Morning").to_sym
enctype = EncounterTypes::Land
 
  +
elsif PBDayNight.isAfternoon?(time)
enctype = EncounterTypes::LandNight if self.hasEncounter?(EncounterTypes::LandNight) && PBDayNight.isNight?(time)
 
  +
try_type = (base_type.to_s + "Afternoon").to_sym
enctype = EncounterTypes::LandDay if self.hasEncounter?(EncounterTypes::LandDay) && PBDayNight.isDay?(time)
 
  +
elsif PBDayNight.isEvening?(time)
enctype = EncounterTypes::LandMorning if self.hasEncounter?(EncounterTypes::LandMorning) && PBDayNight.isMorning?(time)
 
  +
try_type = (base_type.to_s + "Evening").to_sym
if pbInBugContest? && self.hasEncounter?(EncounterTypes::BugContest)
 
enctype = EncounterTypes::BugContest
 
 
end
 
end
  +
ret = try_type if try_type && has_encounter_type?(try_type)
return enctype
 
  +
if !ret
  +
try_type = (base_type.to_s + "Day").to_sym
  +
ret = try_type if has_encounter_type?(try_type)
  +
end
  +
else
  +
try_type = (base_type.to_s + "Night").to_sym
  +
ret = try_type if has_encounter_type?(try_type)
 
end
 
end
return -1
+
return ret if ret
  +
return (has_encounter_type?(base_type)) ? base_type : nil
 
end
 
end
The purpose of this method is to decide on the encounter method to check. The encounter method returned by this code is the ''only'' encounter method attempted.
 
   
  +
This script determines the [[Time|time of day]] and looks for time-appropriate encounters defined for the current map. If there are encounters defined for a checked encounter method, this script will return it. If not, it returns <code>nil</code>
As you can see, there are three main sections to this:
 
  +
* Encounters if the player is surfing ("Water"-type)
 
  +
The encounter methods checked for by this script are the "base type" (<code>:Land</code>, <code>:Cave</code> or <code>:Water</code>) with a time period's word added onto the end (e.g. <code>:LandMorning</code>, <code>:LandDay</code>, <code>:LandNight</code>). Some time periods overlap (morning, afternoon and evening are all part of the daytime), so this script will check the shorter time periods (morning, afternoon, evening) before the longer time periods (day).
* Encounters if the current map has defined "Cave"-type encounters (as determined by <code>def isCave?</code> in the same script section)
 
* Encounters if the current map has defined "Land"-type encounters (as determined by <code>def isGrass?</code> in the same script section)
 
As you can see, priority is given to the "Water" encounter method, as the first step is checking whether the player is surfing. If they are, it doesn't matter whether the player is in a cave or outside or elsewhere, as the encounter method chosen will be "Water".
 
   
  +
Because this script adds words onto the end of the "base type" to create new encounter methods to check for, each "base type"'s set of time-related encounter methods need to be named a particular way. If you create a new encounter method and want to make use of this script, you will need to be careful with how you name them. Note that you do not need to create variants of your new encounter method for all these time periods, though; ones that do not exist will just not produce a result, and the script will move on to the next check.
Otherwise, this code chooses either "Cave" (if that encounter method is used by the current map) or one of the tall grass-based encounter methods (if any of them are used by the current map). Remember that "Cave" and tall grass-based encounter methods are mutually exclusive.
 
   
  +
Note that the scripts above do ''not'' check whether a wild encounter should be triggered. That is determined in <code>def encounter_possible_here?</code>. You should not need to change this script.
When adding your own encounter method, you should bear in mind whether it or another encounter method should take priority if both are possible with the same step. For example, both "Land" and "LandNight" could be possible at the same time (if you were playing at night), but the code is written to make "LandNight" take priority (if the current map uses "LandNight"). Similarly, while surfing, the map could also use the "Cave" encounter method, but it is "Water" which is chosen.
 
   
 
=== "Direct Triggering" encounter methods ===
You can include pretty much whatever code you want here, to help decide which encounter method should be checked. The possibilities are endless.
 
   
 
These kinds of wild encounters are currently only possible by either using an item (a fishing rod) or by [[Using moves outside battle|a move outside of battle]] (Rock Smash or Headbutt). In all cases, the effects of these items/moves is to determine which encounter method they want to trigger, and then call <code>def pbEncounter</code> with that encounter method.
Note that the code above does ''not'' perform checks such as whether the player is on a grass tile. This is done later, by <code>def isEncounterPossibleHere?</code>.
 
   
  +
The determination is typically very straightforward (e.g. the Old Rod only ever triggers the :OldRod encounter method), although Headbutt has two encounter methods to choose between, and Rock Smash has a percentage chance of trying to trigger a wild encounter. This is not worth documenting.
=== "Triggering"-type encounter methods ===
 
These kinds of wild encounters are currently only possible by either using an item (a fishing rod) or by a move outside of battle (Rock Smash or Headbutt). In all cases, these call <code>def pbEncounter</code> with a parameter that is the encounter method they want to use. This is how they determine which encounter method to use.
 

Revision as of 18:00, 3 June 2021

For how to set up wild encounters on maps, see Wild encounters.
For triggering an encounter with a specific wild Pokémon, see Event encounters.

This page describes how to create new wild encounter methods. An explanation of what an encounter method is can be found on the Wild encounters page.

There are two steps to adding a new encounter method:

  1. Defining it (getting the game to recognise it as an encounter method).
  2. Making it work (changing which list of wild encounters to use depending on the new encounter method).

Defining an encounter method

All encounter methods are defined in the script section EncounterType. Each encounter method is registered in the Game Data separately; you can define additional encounter methods in any script section (you can put all your new ones in a new script section to keep track of the code changes you make).

Examples of definitions of encounter methods are:

GameData::EncounterType.register({
  :id             => :Land,
  :type           => :land,
  :trigger_chance => 21,
  :old_slots      => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
  :id             => :CaveNight,
  :type           => :cave,
  :trigger_chance => 5,
  :old_slots      => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
  :id             => :OldRod,
  :type           => :fishing,
  :old_slots      => [70, 30]
})
GameData::EncounterType.register({
  :id             => :RockSmash,
  :type           => :none,
  :trigger_chance => 50,
  :old_slots      => [60, 30, 5, 4, 1]
})

The properties an encounter method can be given are as follows:

Property Description Necessary?
:id The ID of the encounter type, as a symbol. Yes
:type The category that this encounter type belongs to. Is one of :land, :cave, :water, :fishing, :contest or :none.

The type has several effects. :land is for encounter types that occur when moving in tall grass, roaming Pokémon can be made to appear only for certain types of encounter, the Poké Radar only works for :land encounter types, and so on.

No (default is :none)
:trigger_chance This is the percentage chance that an encounter using this encounter method will happen when prompted (e.g. upon taking a step, upon using Rock Smash). It is used as the default step chance when creating a new set of wild encounters in the Debug mode feature "Edit Wild Encounters", but is not used by anything else.

For encounter methods that are prompted by taking a step (in tall grass, caves, surfing), this number also determines how many steps the player can take after a battle before another another encounter could happen (max. 8, but lower if this trigger chance is higher). Effects that alter the encounter rate also affect the number of "safe" steps (e.g. Cleanse Tag reduces the trigger chance and increases the number of "safe" steps).

No (default is 0)
:old_slots This property is only used for old encounter methods, as part of converting an old format "encounters.txt" PBS file to the current format. It is an array of the relative chances each encounter slot has of being chosen for a generated wild encounter. As they are relative numbers, they do not have to add to 100. No (only for old encounter methods)

All encounter methods are compatible with all other encounter methods. For example, a map could have both :Cave and :Land wild encounters defined, and the :Land encounters would be used if the player walks in tall grass, while the :Cave encounters would be used if the player walks anywhere else.

Making the encounter method work

Once an encounter method is properly defined, scripts need to be altered to make use of it at the appropriate times. This may not be straightforward to do, depending on when exactly it should be used.

There are two possible ways to use an encounter method to trigger a wild encounter:

  • Taking a step: The game decides which encounter method needs to be used (in def encounter_type in class PokemonEncounters). This decision can depend on a variety of factors, such as which encounter methods are used by the current map, whether something special is happening (e.g. the player is surfing, there is a Bug Catching Contest in progress), and/or the time of day. You can add your own factors too.
  • Direct triggering: A wild encounter is directly triggered by using an item (e.g. fishing rods) or by using moves outside battle (e.g. Rock Smash, Headbutt). The thing that triggered the wild encounter will determine the encounter method to use.

When making something that directly triggers a wild encounter, the advice is to copy an existing thing that works similarly.

"Taking a step" encounter methods

The game decides which encounter method needs to be used in any given situation. It makes this decision in def encounter_type in class PokemonEncounters.

def encounter_type
  time = pbGetTimeNow
  ret = nil
  if $PokemonGlobal.surfing
    ret = find_valid_encounter_type_for_time(:Water, time)
  else   # Land/Cave (can have both in the same map)
    if has_land_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).land_wild_encounters
      ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest)
      ret = find_valid_encounter_type_for_time(:Land, time) if !ret
    end
    if !ret && has_cave_encounters?
      ret = find_valid_encounter_type_for_time(:Cave, time)
    end
  end
  return ret
end

The encounter method returned by this code is the only encounter method attempted.

The code has_land_encounters? and has_cave_encounters? checks whether there are wild encounters of those types (see the :type property above) defined for the current map. There is also has_water_encounters?, which is currently unused.

Note the way in which this script is written. For example, if the player is surfing, it will only check for Water encounter methods, and it checks this first because the current map may have cave-type encounters (triggered upon every step, even while surfing), but it is not appropriate to check for the :Cave encounter methods while surfing. Another example is the :BugContest encounter method, which is checked before the other :Land encounter methods (which are then skipped if the player is in a Bug Catching Contest and :BugContest encounters are defined for the current map).

After deciding whether the player is surfing, or the map has and land- or cave-type encounters defined, or whether the player is in a Bug Catching Contest, the above script calls def find_valid_encounter_type_for_time with an appropriate "base type" (:Land, :Cave or :Water) and the current time.

def find_valid_encounter_type_for_time(base_type, time)
  ret = nil
  if PBDayNight.isDay?(time)
    try_type = nil
    if PBDayNight.isMorning?(time)
      try_type = (base_type.to_s + "Morning").to_sym
    elsif PBDayNight.isAfternoon?(time)
      try_type = (base_type.to_s + "Afternoon").to_sym
    elsif PBDayNight.isEvening?(time)
      try_type = (base_type.to_s + "Evening").to_sym
    end
    ret = try_type if try_type && has_encounter_type?(try_type)
    if !ret
      try_type = (base_type.to_s + "Day").to_sym
      ret = try_type if has_encounter_type?(try_type)
    end
  else
    try_type = (base_type.to_s + "Night").to_sym
    ret = try_type if has_encounter_type?(try_type)
  end
  return ret if ret
  return (has_encounter_type?(base_type)) ? base_type : nil
end

This script determines the time of day and looks for time-appropriate encounters defined for the current map. If there are encounters defined for a checked encounter method, this script will return it. If not, it returns nil

The encounter methods checked for by this script are the "base type" (:Land, :Cave or :Water) with a time period's word added onto the end (e.g. :LandMorning, :LandDay, :LandNight). Some time periods overlap (morning, afternoon and evening are all part of the daytime), so this script will check the shorter time periods (morning, afternoon, evening) before the longer time periods (day).

Because this script adds words onto the end of the "base type" to create new encounter methods to check for, each "base type"'s set of time-related encounter methods need to be named a particular way. If you create a new encounter method and want to make use of this script, you will need to be careful with how you name them. Note that you do not need to create variants of your new encounter method for all these time periods, though; ones that do not exist will just not produce a result, and the script will move on to the next check.

Note that the scripts above do not check whether a wild encounter should be triggered. That is determined in def encounter_possible_here?. You should not need to change this script.

"Direct Triggering" encounter methods

These kinds of wild encounters are currently only possible by either using an item (a fishing rod) or by a move outside of battle (Rock Smash or Headbutt). In all cases, the effects of these items/moves is to determine which encounter method they want to trigger, and then call def pbEncounter with that encounter method.

The determination is typically very straightforward (e.g. the Old Rod only ever triggers the :OldRod encounter method), although Headbutt has two encounter methods to choose between, and Rock Smash has a percentage chance of trying to trigger a wild encounter. This is not worth documenting.