Fandom

Pokémon Essentials Wiki

Adding new encounter methods

228pages on
this wiki
Add New Page
Talk15 Share
For how to set up wild encounters on maps, see Wild encounters.

This page describes how to create new wild encounter methods.

There are two parts 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 wild encounter list to use depending on the new encounter method)

This page will add LandAfternoon as an example. Additional code required to add this encounter method will be highlighted.

Defining an encounter method

All encounter methods are defined at the top of the script section PField_Encounters, in module EncounterTypes. Additional information needs to be added to this module in order to define a new encounter method.

Each part of the module lists all the encounter methods, or have values associated with each encounter method. The methods must be listed in the same order each time.

The first part is straightforward - this is a list of the existing encounter methods, each with their own unique number. The words here are how they are referred to in the scripts, typically as EncounterTypes::RockSmash.

Land         = 0
Cave         = 1
Water        = 2
RockSmash    = 3
OldRod       = 4
GoodRod      = 5
SuperRod     = 6
HeadbuttLow  = 7
HeadbuttHigh = 8
LandMorning  = 9
LandDay      = 10
LandNight    = 11
BugContest   = 12
LandAfternoon = 13

The second part is also straightforward. These are the names of the encounter methods as they are written in the PBS file "encounters.txt". These names are typically identical to the script names of the encounter methods above.

Names=[
   "Land",
   "Cave",
   "Water",
   "RockSmash",
   "OldRod",
   "GoodRod",
   "SuperRod",
   "HeadbuttLow",
   "HeadbuttHigh",
   "LandMorning",
   "LandDay",
   "LandNight",
   "BugContest",
   "LandAfternoon"
]

Next is the definition of how many encounter slots are available for each encounter method, as well as each slot's relative probability. The number of encounter slots is how many numbers there are in the line, and the probability of each encounter slot being chosen is the value of each number in that line.

For example, the first entry of this array is for the "Land" encounter method. It contains 12 numbers, which means that it expects there to be exactly 12 encounter slots for it each time you use it. 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.

For convenience, every existing encounter method has a set of numbers which adds up to 100, meaning that each individual number can also be viewed as the percentage chance of that slot being chosen. They don't have to add up to 100, though; you could have an encounter method with a line that reads [1,1,1], which would have 3 encounter slots, each of which have the same probability of being chosen (33.3%).

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],
   [20,20,10,10,10,10,5,5,4,4,1,1]
]

The next part sets the default encounter densities for each encounter method. These values will be used if a map does not define its own set of encounter densities in the PBS file "encounters.txt".

An encounter density is how likely it is for a wild encounter to occur each step. Without any modifying effects, the probability is the encounter density divided by 180. A higher number means more frequent encounters. "Land"-type encounter methods have higher encounter densities than "Water" or "Cave"-type encounter methods, because "Land"-type wild encounters can only happen in tall grass (which you can step out of), while wild encounters for the other types can occur at any time (there is nowhere you can be while surfing/in a cave to ensure you cannot run into a wild encounter).

Obviously this is irrelevant for certain encounter methods, i.e. the ones that aren't triggered by moving around (RockSmash, fishing, etc.). For these encounter methods, use a value of 0.

Each value can be different. However, if a map defines its own set of encounter densities, it will use the same one number for all "Land"-type encounter methods, the same one number for all "Cave"-type encounter methods, and the same one number for all "Water-type" encounter methods.

EnctypeDensities=[25,10,10,0,0,0,0,0,0,25,25,25,25,25]

The final part is related to the previous part about encounter densities. This array defines whether each encounter method is "Land"-type (1), "Cave"-type (2) or "Water"-type (3). 0 is for encounter methods which don't use encounter densities.

If a map defines its own set of encounter densities, it will have three numbers. The first number is for all "Land"-type encounter methods (1), the second number is for all "Cave"-type encounter methods (2), and the third number is for all "Water"-type encounter methods (3).

By default, a map only defines its own encounter densities with three numbers. However, there can be more than three (there can't be fewer, though). In this final part, if you set an encounter method to be type 4 (for example), and then add a fourth number to the defined set of encounter densities for a map in the PBS file "encounters.txt", only encounter methods of type 4 will use that fourth number as their encounter density. You could use this to, say, make "LandNight" have a different encounter density to "Land", by setting "LandNight" to type 4 and setting its encounter density separately.

EnctypeCompileDens=[1,2,3,0,0,0,0,0,0,1,1,1,1,1]

Mutually exclusive encounter methods

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).

This mutual exclusivity is defined in def pbCompileEncounters 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::LandEvening]) &&
               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 "Cave" and a "Land"-type encounter method defined for it, and if so, produces an error message.

There is similar code in def pbNewEncounterType in the script section Editor. In this case, it prevents the user from using the "Set Encounters" debug option to define a map with both incompatible encounter methods.

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.

Making the encounter method work

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.

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 (via def pbEncounterType). This decision can depend on a variety of factors, such as what kind of tile the player is standing on (e.g. tall grass), which map they're in (e.g. caves), 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.
  • 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.

As always, 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.

"Taking a step"-type encounter methods

The game decides which encounter method needs to be used here. It makes this decision in def pbEncounterType, in the script section PField_Encounters.

def pbEncounterType
  if $PokemonGlobal && $PokemonGlobal.surfing
    return EncounterTypes::Water
  elsif self.isCave?
    return EncounterTypes::Cave
  elsif self.isGrass?
    time=pbGetTimeNow
    enctype=EncounterTypes::Land
    enctype=EncounterTypes::LandNight if self.hasEncounter?(EncounterTypes::LandNight) && PBDayNight.isNight?(time)
    enctype=EncounterTypes::LandDay if self.hasEncounter?(EncounterTypes::LandDay) && PBDayNight.isDay?(time)
    enctype=EncounterTypes::LandMorning if self.hasEncounter?(EncounterTypes::LandMorning) && PBDayNight.isMorning?(time)
    if pbInBugContest? && self.hasEncounter?(EncounterTypes::BugContest)
      enctype=EncounterTypes::BugContest
    end
    return enctype
  end
  return -1
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.

As you can see, there are three main sections to this:

  • Encounters if the player is surfing ("Water"-type)
  • Encounters if the player is in a cave map ("Cave"-type)
  • Encounters if the player is standing on a grass tile ("Land"-type)

As described above, "Land"-type and "Cave"-type encounters are mutually exclusive. By definition, "Land"-type and "Water"-type encounters are also mutually exclusive, as you cannot be both on land and surfing at the same time. However, you can be in a cave and surfing. This method gives priority to surfing. 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.

You can include pretty much whatever code you want here, to help decide which encounter method should be checked. The possibilities are endless.

The code self.isCave? and self.isGrass? check whether there are any "Cave"-type or "Land"-type encounters defined for the map respectively. Similarly, self.hasEncounter?(EncounterTypes::LandNight) checks whether there are any "LandNight" encounters defined for the map. However, it is not necessary here to ensure that encounters are defined for the encounter method returned; the "Water" encounter method is returned without ensuring this, for instance.

Note that this does not perform checks such as whether the player is on a grass tile. This is done later, by def isEncounterPossibleHere?. This method also doesn't necessarily care whether there are any defined encounters for the encounter type it will use. All this method does is say whether it could be at all possible to have a wild encounter in the current location (e.g. you cannot have wild encounters while sliding on ice).

"Triggering"-type encounter methods

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.