Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
OverworldEncounter.gif

* Visible Overworld Wild Encounters Version - by derFischae (Credits if used please) *

ADDED BUG FIX FOR POKEMON ESSENTIALS V18.1.
UPDATED TO VERSION 2.0.2 FOR POKEMON ESSENTIALS V18.
UPDATED TO VERSION 2.0.1 FOR POKEMON ESSENTIALS V17 AND 17.2.
DOWNSCALES OF VERSION 1.11.2 AND 1.6 FOR POKEMON ESSENTIALS V16.2 BY ARCHYTHEARC.

This script is for Pokémon Essentials V16.2, V17, V17.2, V18 and V18.1. Originally written for V17 and V17.2 by me. VERSION 1.11.2 and 1.6 downscaled to V16.2 by ArchyTheArc. Additionally, upscaled the script for Pokemon Essentials V18 and V18.1.

As in Pokemon Let's go Pikachu/Eevee or Pokemon Shild and Sword random encounters pop up on the overworld, they move around and you can start the battle with them simply by moving to the pokemon. Clearly, you also can omit the battle by circling around them.

FEATURES INCLUDED:
  • see the pokemon on the overworld before going into battle
  • no forced battling against random encounters
  • plays the pokemon cry while spawning
  • Choose whether encounters occure on all terrains or only on the terrain of the player
  • you can have instant wild battle and overworld spawning at the same time and set the propability of that by default and change it ingame and store it with a $game_variable
  • In caves, pokemon don't spawn on impassable Rock-Tiles, which have the Tile-ID 4
  • If you want to add a procedure that modifies a pokemon only for spawning but not before battling then you can use the Event @@OnWildPokemonCreateForSpawning.
  • You can check if you are battling a spawned pokemon with the global variable $PokemonGlobal.battlingSpawnedPokemon

INSTALLATION: It is as simple as it can be.
  1. You need sprites for the overworld pokemon in your \Graphics\Characters folder named by there number 001.png, 002.png, ..., For instance you can use Gen 1-7 OV SPrites or whatever you want for your fakemon.
    If you want to use shiny overworld sprites for shiny encounters, then make sure to also have the corresponding shiny versions in your \Graphics\Characters folder named by 001s.png, 002s.png, ....
    If you want to use alternative forms as overworld sprites, then make sure that you also have a sprite for each alternative form, e. g. for Unown 201_1.png, 201s_1.png, 201_2.png, 201s_2.png, ...
    Please note that Scatterbug has 18 alternative forms in Pokemon Essentials. But you will only see one form depending on your trainerID. So, you also have to include 664_1.png, ..., 664_19.png and 664s_1.png, ..., 664s_19.png. Same needs to be done for Pokemon Spewpa with number 665 and Vivillon with number 666.
    If you want to use female forms as overworld sprites, then make sure that you also have a female sprite for each pokemon named 001f.png, 001fs.png, 002f.png, 002fs.png, ... (excluding genderless pokemon of course)
  2. Insert a new file in the script editor above main, name it Overworld_Encounters and copy into it the linked code below corresponding to your pokemon essentials version.
  3. Set the properties for your pleasure in the properties section of the script. Most of you don't need to change anything.
  4. If you want, then you can install add-ons or modifications for the script from below.
  5. If you want then you can also install the script always in bush and in water to obtain that the overworld encounter don't stand on water anymore but sink in. You can find it at https://www.pokecommunity.com/showthread.php?p=10109060

ADD-ONS OF THIS SCRIPT: In this thread https://www.pokecommunity.com/showthread.php?t=429019 you will also find add-ons, including
MODIFICATIONS OF THIS SCRIPT: Read this thread https://www.pokecommunity.com/showthread.php?t=429019 for more features and modifications, including
  • adding shiny sparkle animation to spawned overworld shinys, especially useful if you want to sign out the shiny encounters on the map without using overworld shiny sprites
  • removing grass rustle animation on water and in caves
  • instructions on how to change the movement of the overworld encounter
  • "aggressive encounters" only get aggressive when you are 2 tiles away from them, and not before
  • forbidding pokemon to spawn on specific terrain tiles in caves
  • adding new encounter types, eg. desert, shallow water
  • instructions on how to have different encounters for overworld spawning and original encountering on the same map
  • error solutions

CHANGELOG
Spoiler:

NEW FEATURES IN VERSION 1.1:
- less lag
- supports sprites for alternative forms of pokemon

NEW FEATURES IN VERSION 1.2:
- supports sprites for female/male/genderless pokemon

NEW FEATURES IN VERSION 1.3:
- bug fixes for roaming encounter and double battles

NEW FEATURES IN VERSION 1.4:
- more options in settings

NEW FEATURES IN VERSION 1.5:
- roaming encounters working correctly

NEW FEATURES IN VERSION 1.6:
- did some runtime optimization, i.e. faster despawning of pokemon after battle

NEW FEATURES IN VERSION 1.7:
- included automatic spawning of pokemon, i.e. spawning without having to move the player

NEW FEATURES IN VERSION 1.8:
- included vendilys rescue chain, i. e. if pokemon of the same species family spawn in a row and will be battled in a row, then you increase the chance of spawning an evolved pokemon of that species family. Link: https://www.pokecommunity.com/showthread.php?t=415524

NEW FEATURES IN VERSION 1.9:
- removed bug occuring after fainting against wild overworld encounter
- for script-developers, shortened the spawnEvent method for better readablitiy

NEW FEATURES IN VERSION 1.10:
- removed bugs from version 1.9
- added shapes of overworld encounter for rescue chain users
- supports spawning of alternate forms while chaining
- if overworld sprites for alternative, female or shiny forms are missing, then the standard sprite will be displayed instead of an invisible event
- bug fix for shiny encounters

NEW FEATURES IN VERSION 1.11:
- respecting shiny state for normal encounters when using overworld and normal encounters at the same time
- easier chaining concerning Vendilys Rescue chain, i.e. no more resetting of the chain when spawning of a pokemon of different family but when fighting with a pokemon of different family
- Added new Event @@OnPokemonCreateForSpawning which only triggers on spawning
- Added new global variable $PokemonGlobal.battlingSpawnedShiny to check if an active battle is against a spawned pokemon.

NEW FEATURES IN VERSION 1.11.2:
- removed bug to make the features in 1.11 work

NEW FEATURES IN VERSION 2.0:
- reorganised and thin out the code
- removed Vendilys Rescue Chain, Let's Go Shiny Hunting and automatic spawning as hard coded feature and provide it as Add-Ons instead
- Now, using overworld and normal encounters at the same time is a standard feature
- autospawning will not trigger instant battles anymore

NEW FEATURES IN VERSION 2.0.1:
- removed a bug that came from reorganising the code in original code and add-ons concerning Let's go shiny hunting add-on

NEW FEATURES IN VERSION 2.0.2:
- added new $global variable $PokemonGlobal.creatingSpawningPokemon to check during events such as @@OnWildPokemonCreate if that event is triggered for an overworld spawning pokemon or not

NEW FEATURES FROM VERSION 2.0.3:
- bug fix for poke radar, works as usual now


THANKS to BulbasaurLvl5 for the animated gif.
THANKS to ArchyTheArc for downscaling to Pokemon Essentials V16.2.

Please follow the link below to get the script and all informations, including add-ons and modifications.

* VERSION 2.0.3 FOR POKEMON ESSENTIALS V18 and V18.1*
https://www.pokecommunity.com/showthread.php?p=10203908

* VERSION 2.0.1 FOR POKEMON ESSENTIALS V17 and V17.2 *
https://www.pokecommunity.com/showthread.php?p=10202528

* VERSION 1.11.2 FOR POKEMON ESSENTIALS V17 and V17.2 AND DOWNSCALE OF VERSION 1.11.2 FOR POKEMON ESSENTIALS V16.2 *
https://www.pokecommunity.com/showthread.php?p=10202501

* DOWNSCALE OF VERSION 1.6 FOR POKEMON ESSENTIALS V16.2 *
https://www.pokecommunity.com/showthread.php?p=10210917
Seen October 22nd, 2020
Posted September 17th, 2020
115 posts
4.2 Years
This is a beautiful script. I am slightly scared that It can produce some lag ...

Do you think there is any way to make it work only if a switch is activated? Perhaps in this way we can make special maps or items that allow you to see the Pokemon in the grass for a certain amount of time ...

Thank you very much for this great job!
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
This is a beautiful script. I am slightly scared that It can produce some lag ...

Do you think there is any way to make it work only if a switch is activated? Perhaps in this way we can make special maps or items that allow you to see the Pokemon in the grass for a certain amount of time ...

Thank you very much for this great job!
In the second part "SPAWNING THE OVERWORLD ENCOUNTER" of my script, I overwrite the method Kernel.pbOnStepTaken. This method was originally defined in script PField_Field and is used to generate the wild pokemon battle.
To include the switch dependency (as you mentioned above), you have to replace the code of Kernel.pbOnStepTaken in my overworld encounter script by something like that:

def Kernel.pbOnStepTaken(eventTriggered)
  if $game_switches[OVERWORLD_ENCOUNTER_SWITCH]==false
    #Insert the code from Kernel.pbOnStepTaken in script PField_Field
    [...]
  else
    #Insert the code from Kernel.pbOnStepTaken in script Visible Overworld Wild Encounter (see above)
    [...]
  end
end
Here, OVERWORLD_ENCOUNTER_SWITCH denotes your favourite switch you want to use. And the dots [...] stand for the actual code you have to insert. That's it. The rest of the script doesn't have to be changed.

Well, I haven't tested it. So please let us know if it works as suggested.
Seen October 22nd, 2020
Posted September 17th, 2020
115 posts
4.2 Years
I tried it this way, but I only got both types of encounters to work ... But not one or the other ...

#===============================================================================
# * Visible Overworld Encounters - by derFischae (Credits if used please) *
#===============================================================================

# This script is for Pokémon Essentials 17.
# As in Pokemon Let's go Pikachu/Eevee or Pokemon Shild and Sword
# random encounters pop up on the overworld,
# they move around and you can start the battle
# with them simply by moving to the pokemon.
# Clearly, you also can omit the battle by circling around them.
# 
#
# FEATURES INCLUDED:
#   - see the pokemon on the overworld before going into battle
#   - no forced battling against random encounters
#   - plays the pokemon cry while spawning
#   - Choose whether encounters occure on all terrains or only on 
#     the terrain of the player
#   - if you kill the same species in a row, then you increase
#     the chance of spawning a shiny of that species 
#
# INSTALLATION:
# Installation as simple as it can be.
# Step 1) You need sprites for the overworld pokemon in your \Graphics\Characters
# folder named by there number 001.png, 002.png, ...,
# with the corresponding shiny versions 001s.png, 002s.png, ....
# For instance you can use Gen 1-7 OV SPrites or whatever you want for 
# your fakemon
# Step 2) Insert a new file in the script editor above main,
# name it Overworld_Random_Encounters and copy this code into it. 
# 
# PROPERTIES:
# 1) If you want to have water encounters only while surfing,
# you also have to change the value of the
# upcoming parameter RESTRICTENCOUNTERSTOPLAYERMOVEMENT to
#     RESTRICTENCOUNTERSTOPLAYERMOVEMENT = true
# 2) You can choose how many steps the encounter moves before vanishing 
# in parameter
#     STEPSBEFOREVANISHING
# 3) You can choose how many encounters you have to kill to obtain the increased
# Shiny-Chance in parameter
#     CHAINLENGTH
# and the increased Shiny-Chance in parameter
#     SHINYPROBABILITY
#
# NOTE: I have not checked Roaming Encounters. Feel free to test it.

#===============================================================================
#                             Settings            
#===============================================================================

RESTRICTENCOUNTERSTOPLAYERMOVEMENT = false
#true - means that water encounters are popping up
#       if and only if player is surfing
#       (perhaps decreases encounter rate)
#false - means that all encounter types can pop up
#        close to the player (as long as there is a suitable tile)

CHAINLENGTH      = 10 # default 10
#       number describes how many pokemon of the same species
#       you have to kill in a row to increase shiny propability

SHINYPROBABILITY = 100 # default 100 --> 10%
#       increasing this value decreases the probability of spawning a shiny

STEPSBEFOREVANISHING = 6 # default 10
#      STEPSBEFOREVANISHING is the number of steps a wild Encounter goes
#      before vanishing on the map.

OVERWORLD_ENCOUNTER_SWITCH = 97


#===============================================================================
#                              THE SCRIPT
#===============================================================================

          #########################################################
          #                                                       #
          #             1. PART: THE CATCHCOMBO                   #
          #                                                       #
          #########################################################
#===============================================================================
# adding a new instance variable to $PokemonTemp in script PField_Metadata to
# remember which pokemon and how many of that kind were killed in a row
#===============================================================================
class PokemonTemp
  attr_accessor :catchcombo # [chain length, species]
end

#===============================================================================
# adding a new event handler on Battle end to update the catchchain (where the
# pokemon-kill-chain is saved)
#===============================================================================
Events.onWildBattleEnd+=proc {|sender,e|
   species=e[0]
   result=e[2]
   $PokemonTemp.catchcombo = [0,0] if !$PokemonTemp.catchcombo
   if $PokemonTemp.catchcombo[1]!=species
     $PokemonTemp.catchcombo=[0,species]
   end
   if result==1 && species==$PokemonTemp.catchcombo[1]
     $PokemonTemp.catchcombo[0]+=1
     #Kernel.pbMessage(_INTL("You killed {1} {2}",$PokemonTemp.catchcombo[0],$PokemonTemp.catchcombo[1]))
   end
}


          #########################################################
          #                                                       #
          #      2. PART: SPAWNING THE OVERWORLD ENCOUNTER        #
          #                                                       #
          #########################################################
#===============================================================================
# We override the original method "pbOnStepTaken" it was originally used for
# random encounter battles
#===============================================================================

def Kernel.pbOnStepTaken(eventTriggered) 
   if $game_switches[OVERWORLD_ENCOUNTER_SWITCH]==false
    if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
      Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
    end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  
  Events.onStepTaken.trigger(nil)
#  Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    pbBattleOnStepTaken(repel)
  end
end
  else 
  #Should it be possible to search for pokemon nearby?
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    #we choose the tile on which the pokemon appears
    pos = pbChooseTileOnStepTaken
    return if !pos
    #we choose the random encounter
    encounter = pbChooseEncounter(pos[0],pos[1],repel)
    return if !encounter
    #we generate an random encounter overworld event
    pbPlaceEncounter(pos[0],pos[1],encounter)
  end
  end




#===============================================================================
# new method pbChooseTileOnStepTaken to choose the tile on which the pkmn spawns 
#===============================================================================
def pbChooseTileOnStepTaken
  # Choose 1 random tile from 1 random ring around the player
  i = rand(4)
  r = rand((i+1)*8)
  x = $game_player.x
  y = $game_player.y
  if r<=(i+1)*2
    x = $game_player.x-i-1+r
    y = $game_player.y-i-1
  elsif r<=(i+1)*6-2
    x = [$game_player.x+i+1,$game_player.x-i-1][r%2]
    y = $game_player.y-i+((r-1-(i+1)*2)/2).floor
  else
    x = $game_player.x-i+r-(i+1)*6
    y = $game_player.y+i+1
  end
  #check if it is possible to encounter here
  return if x<0 || x>=$game_map.width || y<0 || y>=$game_map.height #check if the tile is on the map
  #check if it's a valid grass, water or cave etc. tile
  return if PBTerrain.isIce?($game_map.terrain_tag(x,y))
  return if PBTerrain.isLedge?($game_map.terrain_tag(x,y))
  return if PBTerrain.isWaterfall?($game_map.terrain_tag(x,y))
  return if PBTerrain.isRock?($game_map.terrain_tag(x,y))
  if RESTRICTENCOUNTERSTOPLAYERMOVEMENT
    return if !PBTerrain.isWater?($game_map.terrain_tag(x,y)) && 
              $PokemonGlobal && $PokemonGlobal.surfing
    return if PBTerrain.isWater?($game_map.terrain_tag(x,y)) && 
              !($PokemonGlobal && $PokemonGlobal.surfing)
  end
  return [x,y]
end

#===============================================================================
# defining new method pbChooseEncounter to choose the pokemon on the tile (x,y)
#===============================================================================
def pbChooseEncounter(x,y,repel=false)
  return if $Trainer.ablePokemonCount==0   #check if trainer has pokemon
  encounterType = $PokemonEncounters.pbEncounterTypeOnTile(x,y)
  $PokemonTemp.encounterType = encounterType
  return if encounterType<0 #check if there are encounters
  return if !$PokemonEncounters.isEncounterPossibleHereOnTile?(x,y)
  for event in $game_map.events.values
    if event.x==x && event.y==y
      return
    end
  end
  encounter = $PokemonEncounters.pbGenerateEncounter(encounterType)
  encounter = EncounterModifier.trigger(encounter)
  if !$PokemonEncounters.pbCanEncounter?(encounter,repel)
    $PokemonTemp.forceSingleBattle = false
    EncounterModifier.triggerEncounterEnd()
    return
  end
  return encounter
end



#===============================================================================
# defining new method pbPlaceEncounter to add/place and visualise the pokemon
# "encounter" on the overworld-tile (x,y)
#===============================================================================
def pbPlaceEncounter(x,y,encounter)
  # Show grass rustling animations
  $scene.spriteset.addUserAnimation(RUSTLE_NORMAL_ANIMATION_ID,x,y,true,1)
  # Play the pokemon cry of encounter
  pbPlayCryOnOverworld(encounter[0])
  # place event with random movement with overworld sprite
  # We define the event, which has the sprite of the pokemon and activates the wildBattle on touch
  if !$MapFactory
    $game_map.spawnEvent(x,y,encounter)
  else
    mapId = $game_map.map_id
    spawnMap = $MapFactory.getMap(mapId)
    spawnMap.spawnEvent(x,y,encounter)
  end
  # For roaming encounters we have to do the following:
  if $PokemonTemp.nowRoaming == true && 
     $PokemonTemp.roamerIndex != nil &&
     $PokemonGlobal.roamEncounter != nil
    $PokemonGlobal.roamEncounter = nil
    $PokemonGlobal.roamedAlready = true
  end
  $PokemonTemp.forceSingleBattle = false
  EncounterModifier.triggerEncounterEnd()
end

#===============================================================================
# adding new Methods pbEncounterTypeOnTile and isEncounterPossibleHereOnTile?
# in Class PokemonEncounters in Script PField_Encounters
#===============================================================================
class PokemonEncounters
  def pbEncounterTypeOnTile(x,y)
    if PBTerrain.isJustWater?($game_map.terrain_tag(x,y))
      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
  
  def isEncounterPossibleHereOnTile?(x,y)
    if PBTerrain.isJustWater?($game_map.terrain_tag(x,y))
      return true
    elsif self.isCave?
      return true
    elsif self.isGrass?
      return PBTerrain.isGrass?($game_map.terrain_tag(x,y))
    end
    return false
  end
end

#===============================================================================
# new Method spawnEvent in Class Game_Map in Script Game_Map
#===============================================================================
class Game_Map
  def spawnEvent(x,y,encounter)
    #------------------------------------------------------------------
    # generating a new event
    event = RPG::Event.new(x,y)
    # naming the event "vanishingEncounter" for PART 3 
    event.name = "vanishingEncounter"
    #setting the nessassary properties
    key_id = (@events.keys.max || -1) + 1
    event.id = key_id
    event.x = x
    event.y = y
    #event.pages[0].graphic.tile_id = 0
    if encounter[0] < 10
      character_name = "00"+encounter[0].to_s
    elsif encounter[0] < 100
      character_name = "0"+encounter[0].to_s
    else
      character_name = encounter[0].to_s
    end
    # use shiny-sprite if probability & killcombo is high or shiny-switch is on
    $PokemonTemp.catchcombo=[0,0] if !$PokemonTemp.catchcombo
    if $game_switches[SHINY_WILD_POKEMON_SWITCH]==true
        character_name = character_name+"s"
        shinysprite=true
    elsif ($PokemonTemp.catchcombo[0]>=CHAINLENGTH && $PokemonTemp.catchcombo[1]==encounter[0])
      if rand(SHINYPROBABILITY)<$PokemonTemp.catchcombo[0]
        character_name = character_name+"s"
        shinysprite=true
      end
    end
    event.pages[0].graphic.character_name = character_name
    event.pages[0].move_type = 1
    event.pages[0].trigger = 2
    #------------------------------------------------------------------
    # we add the event commands to the event of the overworld encounter
    event.pages[0].list[0].code = 355
    event.pages[0].list[0].indent = 0
    if $PokemonGlobal.roamEncounter!=nil
      #[i,species,poke[1],poke[4]]
      parameter1 = $PokemonGlobal.roamEncounter[1].to_s
      parameter2 = $PokemonGlobal.roamEncounter[2].to_s
      parameter3 = $PokemonGlobal.roamEncounter[3].to_s
      $PokemonGlobal.roamEncounter[4] != nil ? (parameter4 = '"'+$PokemonGlobal.roamEncounter[4].to_s+'"') : (parameter4 = "nil")
      parameter = " $PokemonGlobal.roamEncounter = ["+parameter1+","+parameter2+","+parameter3+","+parameter4+"] "
    else
      parameter = " $PokemonGlobal.roamEncounter = nil "
    end
    event.pages[0].list[0].parameters = [parameter]
    event.pages[0].list[1] = RPG::EventCommand.new
    #
    event.pages[0].list[1].code = 355
    event.pages[0].list[1].indent = 0
    if $PokemonTemp.nowRoaming!=nil
      parameter =" $PokemonTemp.nowRoaming = "+$PokemonTemp.nowRoaming.to_s
    else
      parameter =" $PokemonTemp.nowRoaming = nil "
    end
    event.pages[0].list[1].parameters = [parameter]
    event.pages[0].list[2] = RPG::EventCommand.new
    #
    event.pages[0].list[2].code = 355
    event.pages[0].list[2].indent = 0
    if $PokemonTemp.roamerIndex!=nil
      parameter = " $PokemonTemp.roamerIndex = "+$PokemonTemp.roamerIndex.to_s
    else
      parameter = " $PokemonTemp.roamerIndex = nil "
    end
    event.pages[0].list[2].parameters = [parameter]
    event.pages[0].list[3] = RPG::EventCommand.new
    #
    event.pages[0].list[3].code = 355
    event.pages[0].list[3].indent = 0
    if $PokemonGlobal.nextBattleBGM!=nil
      parameter = " $PokemonGlobal.nextBattleBGM = "+PokemonGlobal.nextBattleBGM.to_s
    else
      parameter = " $PokemonGlobal.nextBattleBGM = nil "    
    end
    event.pages[0].list[3].parameters = [parameter]
    event.pages[0].list[4] = RPG::EventCommand.new
    #
    event.pages[0].list[4].code = 355
    event.pages[0].list[4].indent = 0
    if $PokemonTemp.forceSingleBattle!=nil
      parameter = " $PokemonTemp.forceSingleBattle = "+$PokemonTemp.forceSingleBattle.to_s
    else
      parameter = " $PokemonTemp.forceSingleBattle = nil "
    end
    event.pages[0].list[4].parameters = [parameter]
    event.pages[0].list[5] = RPG::EventCommand.new
    #
    event.pages[0].list[5].code = 355
    event.pages[0].list[5].indent = 0
    if $PokemonTemp.encounterType!=nil
      parameter = " $PokemonTemp.encounterType = "+$PokemonTemp.encounterType.to_s
    else
      parameter = " $PokemonTemp.encounterType = nil "
    end
    event.pages[0].list[5].parameters = [parameter]
    event.pages[0].list[6] = RPG::EventCommand.new
    #
    # setting shiny switch on if sprite is a shiny-sprite
    oldShinySwitchStatus=$game_switches[SHINY_WILD_POKEMON_SWITCH]
    if shinysprite == true
      parameter = " $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]=true"
    else
      parameter = " $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]=false"
    end
    event.pages[0].list[6].code = 355
    event.pages[0].list[6].indent = 0
    event.pages[0].list[6].parameters = [parameter]
    event.pages[0].list[7] = RPG::EventCommand.new
    #
    #pbSingleOrDoubleWildBattle(encounter[0],encounter[1])
    event.pages[0].list[7].code = 355
    event.pages[0].list[7].indent = 0
    parameter = " pbSingleOrDoubleWildBattle("+encounter[0].to_s+","+encounter[1].to_s+", $game_map.events["+key_id.to_s+"].map.map_id, $game_map.events["+key_id.to_s+"].x, $game_map.events["+key_id.to_s+"].y)"
    event.pages[0].list[7].parameters = [parameter]
    event.pages[0].list[8] = RPG::EventCommand.new
    #
    # setting shiny switch back to previous state
    parameter=" $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]="+oldShinySwitchStatus.to_s
    event.pages[0].list[8].code = 355
    event.pages[0].list[8].indent = 0
    event.pages[0].list[8].parameters = [parameter]
    event.pages[0].list[9] = RPG::EventCommand.new
    #
    event.pages[0].list[9].code = 355
    event.pages[0].list[9].indent = 0
    event.pages[0].list[9].parameters = ["$PokemonTemp.encounterType = -1"]
    event.pages[0].list[10] = RPG::EventCommand.new
    #
    event.pages[0].list[10].code = 355
    event.pages[0].list[10].indent = 0
    event.pages[0].list[10].parameters = ["$PokemonTemp.forceSingleBattle = false"]
    event.pages[0].list[11] = RPG::EventCommand.new
    #
    event.pages[0].list[11].code = 355
    event.pages[0].list[11].indent = 0
    event.pages[0].list[11].parameters = ["EncounterModifier.triggerEncounterEnd()"]
    event.pages[0].list[12] = RPG::EventCommand.new
    #
    event.pages[0].list[12].code = 355
    event.pages[0].list[12].indent = 0
    event.pages[0].list[12].parameters = ["$game_map.events.delete("+key_id.to_s+")"]
    event.pages[0].list[13] = RPG::EventCommand.new
    #
    event.pages[0].list[13].code = 355
    event.pages[0].list[13].indent = 0
    event.pages[0].list[13].parameters = ["$scene.disposeSpritesets"]
    event.pages[0].list[14] = RPG::EventCommand.new
    #
    event.pages[0].list[14].code = 355
    event.pages[0].list[14].indent = 0
    event.pages[0].list[14].parameters = ["$scene.createSpritesets"]
    event.pages[0].list[15] = RPG::EventCommand.new
    #------------------------------------------------------------------
    # creating and adding the Game_Event
    gameEvent = Game_Event.new(@map_id, event,self)
    key_id = (@events.keys.max || -1) + 1
    gameEvent.id = key_id
    gameEvent.moveto(x,y)
    @events[key_id] = gameEvent
    #updating the sprites (copied from transferPlayer in Scene_Map)
    $scene.disposeSpritesets
    $scene.createSpritesets
  end
end

#===============================================================================
# adding new Method pbSingleOrDoubleWildBattle to reduce the code in spawnEvent
#===============================================================================
def pbSingleOrDoubleWildBattle(species,level,map_id,x,y)
  if $MapFactory
    terrainTag = $MapFactory.getTerrainTag(map_id,x,y)
  else
    terrainTag = $game_map.terrain_tag(x,y)
  end
  if !$PokemonTemp.forceSingleBattle && ($PokemonGlobal.partner ||
      ($Trainer.ablePokemonCount>1 &&
      PBTerrain.isDoubleWildBattle?(terrainTag) &&
      rand(100)<30))
    encounter2 = $PokemonEncounters.pbEncounteredPokemon($PokemonTemp.encounterType)
    encounter2 = EncounterModifier.trigger(encounter2)
    pbDoubleWildBattle(species,level,encounter2[0],encounter2[1])
  else
    pbWildBattle(species,level)
  end
end


#===============================================================================
# adding new method PBTerrain.isRock? to module PBTerrain in script PBTerrain
# to check if the terrainTag "tag" is rock
#===============================================================================
module PBTerrain
  def PBTerrain.isRock?(tag)
    return tag==PBTerrain::Rock
  end
end

#===============================================================================
# adding new method pbPlayCryOnOverworld to load/play Pokémon cry files 
# SPECIAL THANKS TO "Ambient Pokémon Cries" - by Vendily
# actually it's not used, but that code helped to include the pkmn cries faster
#===============================================================================
def pbPlayCryOnOverworld(pokemon,volume=90,pitch=nil)
  return if !pokemon
  if pokemon.is_a?(Numeric)
    pbPlayCrySpecies(pokemon,0,volume,pitch)
  elsif !pokemon.egg?
    if pokemon.respond_to?("chatter") && pokemon.chatter
      pokemon.chatter.play
    else
      pkmnwav = pbCryFile(pokemon)
      if pkmnwav
        pbBGSPlay(RPG::AudioFile.new(pkmnwav,volume,
           (pitch) ? pitch : (pokemon.hp*25/pokemon.totalhp)+75)) rescue nil
      end
    end
  end
end


          #########################################################
          #                                                       #
          #      3. PART: VANISHING OF OVERWORLD ENCOUNTER        #
          #                                                       #
          #########################################################
#===============================================================================
# adding a new variable stepCount and replacing the method increase_steps
# in class Game_Event in script Game_Event to count the steps of
# overworld encounter and to make them disappear after taking more then
# STEPSBEFOREVANISHING steps
#===============================================================================
class Game_Event < Game_Character
  attr_accessor :event
  attr_accessor :stepCount #counts the steps of an overworld encounter
  
  alias original_increase_steps increase_steps
  def increase_steps
    if self.name=="vanishingEncounter" && @stepCount && @stepCount>=STEPSBEFOREVANISHING
      if $game_map.events.has_key?(@id) and $game_map.events[@id]==self
        $game_map.events.delete(@id)
      else
        if $MapFactory
          for map in $MapFactory.maps
            if map.events.has_key?(@id) and map.events[@id]==self
              map.events.delete(@id)
              break
            end
          end
        else
          #Kernel.pbMessage("Actually, this should not be possible")
        end
      end
      $scene.disposeSpritesets
      $scene.createSpritesets
    else
      @stepCount=0 if ([email protected] || @stepCount<0)
      @stepCount+=1
      original_increase_steps
    end
  end
end

Diegou18

Forever Chandelure lover.

Age 21
Male
Seen 21 Hours Ago
Posted September 2nd, 2020
75 posts
2.7 Years
I tried it this way, but I only got both types of encounters to work ... But not one or the other ...

Spoiler:
          #########################################################
          #                                                       #
          #      2. PART: SPAWNING THE OVERWORLD ENCOUNTER        #
          #                                                       #
          #########################################################
#===============================================================================
# We override the original method "pbOnStepTaken" it was originally used for
# random encounter battles
#===============================================================================

def Kernel.pbOnStepTaken(eventTriggered) 
   if $game_switches[OVERWORLD_ENCOUNTER_SWITCH]==false
    if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
      Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
    end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  
  Events.onStepTaken.trigger(nil)
#  Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    pbBattleOnStepTaken(repel)
  end
end
  else 
  #Should it be possible to search for pokemon nearby?
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    #we choose the tile on which the pokemon appears
    pos = pbChooseTileOnStepTaken
    return if !pos
    #we choose the random encounter
    encounter = pbChooseEncounter(pos[0],pos[1],repel)
    return if !encounter
    #we generate an random encounter overworld event
    pbPlaceEncounter(pos[0],pos[1],encounter)
  end
  end
end
You should remove the end before "else" and add one more at the final of the def. Be careful.
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
There is a way to let overworld encounter appear only if a switch (denoted by OVERWORLD_ENCOUNTER_SWITCH) is activated. Simply replace the method "Kernel.pbOnStepTaken(eventTriggered)" in my script above by the following:

def Kernel.pbOnStepTaken(eventTriggered)
  #Should it be possible to search for pokemon nearby?
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    if $game_switches[OVERWORLD_ENCOUNTER_SWITCH]==false
      #STANDARD WILDBATTLE
      pbBattleOnStepTaken(repel)
    else  
      #OVERWORLD ENCOUNTERS
      #we choose the tile on which the pokemon appears
      pos = pbChooseTileOnStepTaken
      return if !pos
      #we choose the random encounter
      encounter,gender,form = pbChooseEncounter(pos[0],pos[1],repel)
      return if !encounter
      #we generate an random encounter overworld event
      pbPlaceEncounter(pos[0],pos[1],encounter,gender,form)
    end
  end
end
Make sure to also include something like the following in the settings section of my script:

OVERWORLD_ENCOUNTER_SWITCH = 97 # choose your preferred $game_switch
Edit: Updated for version 1.2.
Seen October 22nd, 2020
Posted September 17th, 2020
115 posts
4.2 Years
There is a way to let overworld encounter appear only if a switch (denoted by OVERWORLD_ENCOUNTER_SWITCH) is activated. Simply replace the method "Kernel.pbOnStepTaken(eventTriggered)" in my script above by the following:

def Kernel.pbOnStepTaken(eventTriggered) 
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
#  Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    if $game_switches[OVERWORLD_ENCOUNTER_SWITCH]==false
      #STANDARD WILDBATTLE
      pbBattleOnStepTaken(repel)
    else  
      #OVERWORLD ENCOUNTERS
      #we choose the tile on which the pokemon appears
      pos = pbChooseTileOnStepTaken
      return if !pos
      #we choose the random encounter
      encounter = pbChooseEncounter(pos[0],pos[1],repel)
      return if !encounter
      #we generate an random encounter overworld event
      pbPlaceEncounter(pos[0],pos[1],encounter)
    end
  end
end
I tested it and it worked.
It worked! Thank you so much for your amazing work!

#Not Important

All hail the wishmaker

He/Him
Hoenn
Seen 7 Hours Ago
Posted 7 Hours Ago
829 posts
1 Years
Love the Script !
I used it to make a Randomize !
How did you randomize it?!

Zeak6464

Zeak #3205 - Discord

Age 27
Male
USA
Seen 1 Week Ago
Posted 3 Weeks Ago
808 posts
7.7 Years
How did you randomize it?!
Had to encounter[0] = rand(890)+1 if $game_switches[227]

above these lines !
    if encounter[0] < 10
      character_name = "00"+encounter[0].to_s
    elsif encounter[0] < 100
      character_name = "0"+encounter[0].to_s 
    else
      character_name = encounter[0].to_s
    end
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
Can we do both wild encounters?
Normal Encounters set and Overworld Encounters.

This script is awesome.
If you want overworld encounters and the thrilling excitement of instant wild battles at the same time, then you have to do the following:

1) Add a new parameter to the settings. This parameter represents the propability of gaining an instant battle. It is an integer given in thousanth, i. e. 0 means 0% and 1000 means 100%. Feel free to find the best ratio for you.
INSTANT_WILD_BATTLE_PROPABILITY = 100 # Propability of gaining an instant battle in thousanth, i. e. 0,1,2,...,1000
2) Replace the method "Kernel.pbOnStepTaken(eventTriggered)" in my script in post 1 above by
def Kernel.pbOnStepTaken(eventTriggered) 
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
#  Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    if rand(1000)<INSTANT_WILD_BATTLE_PROPABILITY
      #STANDARD WILDBATTLE
      pbBattleOnStepTaken(repel)
    else  
      #OVERWORLD ENCOUNTERS
      #we choose the tile on which the pokemon appears
      pos = pbChooseTileOnStepTaken
      return if !pos
      #we choose the random encounter
      encounter,gender,form = pbChooseEncounter(pos[0],pos[1],repel)
      return if !encounter
      #we generate an random encounter overworld event
      pbPlaceEncounter(pos[0],pos[1],encounter,gender,form)
    end
  end
end
I haven't tested it, yet. Feel free to let us know if it works the desired way.

Edit: updated the code for version 1.2
Male
Seen 1 Day Ago
Posted 3 Days Ago
62 posts
2.9 Years
If you want overworld encounters and the thrilling excitement of instant wild battles at the same time, then you have to do the following:

1) Add a new parameter to the settings. This parameter represents the propability of gaining an instant battle. It is an integer given in thousanth, i. e. 0 means 0% and 1000 means 100%. Feel free to find the best ratio for you.
INSTANT_WILD_BATTLE_PROPABILITY = 100 # Propability of gaining an instant battle in thousanth, i. e. 0,1,2,...,1000
2) Replace the method "Kernel.pbOnStepTaken(eventTriggered)" in my script in post 1 above by
def Kernel.pbOnStepTaken(eventTriggered) 
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
#  Events.onStepTakenFieldMovement.trigger(nil,$game_player)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    if rand(1000)<INSTANT_WILD_BATTLE_PROPABILITY
      #STANDARD WILDBATTLE
      pbBattleOnStepTaken(repel)
    else  
      #OVERWORLD ENCOUNTERS
      #we choose the tile on which the pokemon appears
      pos = pbChooseTileOnStepTaken
      return if !pos
      #we choose the random encounter
      encounter = pbChooseEncounter(pos[0],pos[1],repel)
      return if !encounter
      #we generate an random encounter overworld event
      pbPlaceEncounter(pos[0],pos[1],encounter)
    end
  end
end
I haven't tested it, yet. Feel free to let us know if it works the desired way.
Thank you!
Male
Seen 13 Hours Ago
Posted 1 Day Ago
8 posts
5.3 Years
My progress didn't work...

---------------------------

Exception: NoMethodError
Message: undefined method `isIce?' for PBTerrain:Module
Visable Pokemon:163:in `pbChooseTileOnStepTaken'
Visable Pokemon:131:in `pbOnStepTaken'
Game_Player:484:in `update_old'
Walk_Run:78:in `update'
Scene_Map:104:in `update'
Scene_Map:101:in `loop'
Scene_Map:114:in `update'
Scene_Map:68:in `main'
Scene_Map:65:in `loop'
Scene_Map:72:in `main'
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
My progress didn't work...

---------------------------

Exception: NoMethodError
Message: undefined method `isIce?' for PBTerrain:Module
Visable Pokemon:163:in `pbChooseTileOnStepTaken'
Visable Pokemon:131:in `pbOnStepTaken'
Game_Player:484:in `update_old'
Walk_Run:78:in `update'
Scene_Map:104:in `update'
Scene_Map:101:in `loop'
Scene_Map:114:in `update'
Scene_Map:68:in `main'
Scene_Map:65:in `loop'
Scene_Map:72:in `main'
Try adding the following code:
module PBTerrain
  Ice             = 12

  def PBTerrain.isIce?(tag)
    return tag==PBTerrain::Ice
  end
end
It's recommanded to include the tag "Ice = 12" and the whole method "PBTerrain.isIce?(tag)" in the already existing module "PBTerrain", which you can find in the script section "PBTerrain". But anyway, it's also fine to simply copy the code above and paste it at the end of the visible overworld encounter script. What version of Pokemon essentials do you use? Normally, I thought that the code above is already included in Pokemon essentials 17.

WolfPP

Discord: Wolf#1235

Male
Brazil
Seen 1 Week Ago
Posted 3 Weeks Ago
1,242 posts
2.3 Years
If you want the Wild Pokémon has step animation/ Stop Animation (animated like follower pokémon from HGSS) just add 'event.pages[0].step_anime = true' below 'event.pages[0].trigger = 2':
    event.pages[0].graphic.character_name = character_name
    event.pages[0].move_type = 1
    event.pages[0].trigger = 2
    event.pages[0].step_anime = true
    #------------------------------------------------------------------
    # we add the event commands to the event of the overworld encounter
Also I tested now and... Why give me a little bit lag? Is it possible to "fix" that? Or only if I change my laptop/hardware? :o

Again, amazing script! Congratz!
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
Also I tested now and... Why give me a little bit lag? Is it possible to "fix" that? Or only if I change my laptop/hardware? :o

Again, amazing script! Congratz!
After spawning and despawning of the overworld encounters we have to update the spriteset. Therefor, I used

    $scene.disposeSpritesets
    $scene.createSpritesets
in the method "increase_steps" and in "spawnEvent(x,y,encounter)". I would say that this way of updating the sprites causes your lag. If you or anyone else finds a better solution for updating the spriteset (which probabily exists) we can reduce some lag. Any suggests are welcome.
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
your script is wonderful, does it work with alternative forms?
Well, I'm not quite sure what you mean with alternate forms and actually I don't know how you implemented that alternative versions of pokemon. But I would say the following:

As long as your alternative form of your pokemon has
* its own entry in \PBS\pokemon.txt and
* an overworld sprite placed in the folder \Graphics\Characters and named by the same number as the entry in pokemon.txt
it will work. Of course, your alternative form has to be set as an encounter on some map in PBS\encounters.txt.

If you implemented alternative forms in another way, then we have to look on how you did that first.

Zeak6464

Zeak #3205 - Discord

Age 27
Male
USA
Seen 1 Week Ago
Posted 3 Weeks Ago
808 posts
7.7 Years
I mean, when testing the script using pokemon with multiple forms, only the default form appeared, shellos is an example.
You will need to edit this section of the code to allow for Alt forms

"s" this looks for a shiny pokemon

character_name is the pokemon number or name

# use shiny-sprite if probability & killcombo is high or shiny-switch is on
    $PokemonTemp.catchcombo=[0,0] if !$PokemonTemp.catchcombo
    if $game_switches[SHINY_WILD_POKEMON_SWITCH]==true
        character_name = character_name+"s"
        shinysprite=true
    elsif ($PokemonTemp.catchcombo[0]>=CHAINLENGTH && $PokemonTemp.catchcombo[1]==encounter[0])
      if rand(SHINYPROBABILITY)<$PokemonTemp.catchcombo[0]
        character_name = character_name+"s"
        shinysprite=true
      end
    end
Male
Germany
Seen 1 Day Ago
Posted 3 Days Ago
140 posts
329 Days
Also I tested now and... Why give me a little bit lag? Is it possible to "fix" that? Or only if I change my laptop/hardware? :o

Again, amazing script! Congratz!
After spawning and despawning of the overworld encounters we have to update the spriteset. Therefor, I used

$scene.disposeSpritesets
$scene.createSpritesets

in the method "increase_steps" and in "spawnEvent(x,y,encounter)". I would say that this way of updating the sprites causes your lag. If you or anyone else finds a better solution for updating the spriteset (which probabily exists) we can reduce some lag. Any suggests are welcome.
As mentioned above there is some lag coming from the way how the character_sprites are updated. However, I changed some code to reduce this lag. you can find the new code in the following spoiler section:

Spoiler:

#===============================================================================
# * Visible Overworld Encounters - by derFischae (Credits if used please) *
#===============================================================================

# This script is for Pokémon Essentials 17.
# As in Pokemon Let's go Pikachu/Eevee or Pokemon Shild and Sword
# random encounters pop up on the overworld,
# they move around and you can start the battle
# with them simply by moving to the pokemon.
# Clearly, you also can omit the battle by circling around them.
# 
#
# FEATURES INCLUDED:
#   - see the pokemon on the overworld before going into battle
#   - no forced battling against random encounters
#   - plays the pokemon cry while spawning
#   - Choose whether encounters occure on all terrains or only on 
#     the terrain of the player
#   - if you kill the same species in a row, then you increase
#     the chance of spawning a shiny of that species 
#
# INSTALLATION:
# Installation as simple as it can be.
# Step 1) You need sprites for the overworld pokemon in your \Graphics\Characters
# folder named by there number 001.png, 002.png, ...,
# with the corresponding shiny versions 001s.png, 002s.png, ....
# For instance you can use Gen 1-7 OV SPrites or whatever you want for 
# your fakemon
# Step 2) Insert a new file in the script editor above main,
# name it Overworld_Random_Encounters and copy this code into it. 
# 
# PROPERTIES:
# 1) If you want to have water encounters only while surfing,
# you also have to change the value of the
# upcoming parameter RESTRICTENCOUNTERSTOPLAYERMOVEMENT to
#     RESTRICTENCOUNTERSTOPLAYERMOVEMENT = true
# 2) You can choose how many steps the encounter moves before vanishing 
# in parameter
#     STEPSBEFOREVANISHING
# 3) You can choose how many encounters you have to kill to obtain the increased
# Shiny-Chance in parameter
#     CHAINLENGTH
# and the increased Shiny-Chance in parameter
#     SHINYPROBABILITY
#
# NOTE: I have not checked Roaming Encounters. Feel free to test it.

#===============================================================================
#                             Settings            
#===============================================================================

RESTRICTENCOUNTERSTOPLAYERMOVEMENT = false
#true - means that water encounters are popping up
#       if and only if player is surfing
#       (perhaps decreases encounter rate)
#false - means that all encounter types can pop up
#        close to the player (as long as there is a suitable tile)

CHAINLENGTH      = 10 # default 10
#       number describes how many pokemon of the same species
#       you have to kill in a row to increase shiny propability

SHINYPROBABILITY = 100 # default 100 --> 10%
#       increasing this value decreases the probability of spawning a shiny

STEPSBEFOREVANISHING = 6 # default 10
#      STEPSBEFOREVANISHING is the number of steps a wild Encounter goes
#      before vanishing on the map.


#===============================================================================
#                              THE SCRIPT
#===============================================================================

          #########################################################
          #                                                       #
          #             1. PART: THE CATCHCOMBO                   #
          #                                                       #
          #########################################################
#===============================================================================
# adding a new instance variable to $PokemonTemp in script PField_Metadata to
# remember which pokemon and how many of that kind were killed in a row
#===============================================================================
class PokemonTemp
  attr_accessor :catchcombo # [chain length, species]
end

#===============================================================================
# adding a new event handler on Battle end to update the catchchain (where the
# pokemon-kill-chain is saved)
#===============================================================================
Events.onWildBattleEnd+=proc {|sender,e|
   species=e[0]
   result=e[2]
   $PokemonTemp.catchcombo = [0,0] if !$PokemonTemp.catchcombo
   if $PokemonTemp.catchcombo[1]!=species
     $PokemonTemp.catchcombo=[0,species]
   end
   if result==1 && species==$PokemonTemp.catchcombo[1]
     $PokemonTemp.catchcombo[0]+=1
     #Kernel.pbMessage(_INTL("You killed {1} {2}",$PokemonTemp.catchcombo[0],$PokemonTemp.catchcombo[1]))
   end
}


          #########################################################
          #                                                       #
          #      2. PART: SPAWNING THE OVERWORLD ENCOUNTER        #
          #                                                       #
          #########################################################
#===============================================================================
# We override the original method "pbOnStepTaken" it was originally used for
# random encounter battles
#===============================================================================
def Kernel.pbOnStepTaken(eventTriggered)
  #Should it be possible to search for pokemon nearby?
  if $game_player.move_route_forcing || pbMapInterpreterRunning? || !$Trainer
    Events.onStepTakenFieldMovement.trigger(nil,$game_player)
    return
  end
  $PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
  $PokemonGlobal.stepcount += 1
  $PokemonGlobal.stepcount &= 0x7FFFFFFF
  repel = ($PokemonGlobal.repel>0)
  Events.onStepTaken.trigger(nil)
  handled = [nil]
  Events.onStepTakenTransferPossible.trigger(nil,handled)
  return if handled[0]
  if !eventTriggered
    #we choose the tile on which the pokemon appears
    pos = pbChooseTileOnStepTaken
    return if !pos
    #we choose the random encounter
    encounter = pbChooseEncounter(pos[0],pos[1],repel)
    return if !encounter
    #we generate an random encounter overworld event
    pbPlaceEncounter(pos[0],pos[1],encounter)
  end
end

#===============================================================================
# new method pbChooseTileOnStepTaken to choose the tile on which the pkmn spawns 
#===============================================================================
def pbChooseTileOnStepTaken
  # Choose 1 random tile from 1 random ring around the player
  i = rand(4)
  r = rand((i+1)*8)
  x = $game_player.x
  y = $game_player.y
  if r<=(i+1)*2
    x = $game_player.x-i-1+r
    y = $game_player.y-i-1
  elsif r<=(i+1)*6-2
    x = [$game_player.x+i+1,$game_player.x-i-1][r%2]
    y = $game_player.y-i+((r-1-(i+1)*2)/2).floor
  else
    x = $game_player.x-i+r-(i+1)*6
    y = $game_player.y+i+1
  end
  #check if it is possible to encounter here
  return if x<0 || x>=$game_map.width || y<0 || y>=$game_map.height #check if the tile is on the map
  #check if it's a valid grass, water or cave etc. tile
  return if PBTerrain.isIce?($game_map.terrain_tag(x,y))
  return if PBTerrain.isLedge?($game_map.terrain_tag(x,y))
  return if PBTerrain.isWaterfall?($game_map.terrain_tag(x,y))
  return if PBTerrain.isRock?($game_map.terrain_tag(x,y))
  if RESTRICTENCOUNTERSTOPLAYERMOVEMENT
    return if !PBTerrain.isWater?($game_map.terrain_tag(x,y)) && 
              $PokemonGlobal && $PokemonGlobal.surfing
    return if PBTerrain.isWater?($game_map.terrain_tag(x,y)) && 
              !($PokemonGlobal && $PokemonGlobal.surfing)
  end
  return [x,y]
end

#===============================================================================
# defining new method pbChooseEncounter to choose the pokemon on the tile (x,y)
#===============================================================================
def pbChooseEncounter(x,y,repel=false)
  return if $Trainer.ablePokemonCount==0   #check if trainer has pokemon
  encounterType = $PokemonEncounters.pbEncounterTypeOnTile(x,y)
  $PokemonTemp.encounterType = encounterType
  return if encounterType<0 #check if there are encounters
  return if !$PokemonEncounters.isEncounterPossibleHereOnTile?(x,y)
  for event in $game_map.events.values
    if event.x==x && event.y==y
      return
    end
  end
  encounter = $PokemonEncounters.pbGenerateEncounter(encounterType)
  encounter = EncounterModifier.trigger(encounter)
  if !$PokemonEncounters.pbCanEncounter?(encounter,repel)
    $PokemonTemp.forceSingleBattle = false
    EncounterModifier.triggerEncounterEnd()
    return
  end
  return encounter
end



#===============================================================================
# defining new method pbPlaceEncounter to add/place and visualise the pokemon
# "encounter" on the overworld-tile (x,y)
#===============================================================================
def pbPlaceEncounter(x,y,encounter)
  # place event with random movement with overworld sprite
  # We define the event, which has the sprite of the pokemon and activates the wildBattle on touch
  if !$MapFactory
    $game_map.spawnEvent(x,y,encounter)
  else
    mapId = $game_map.map_id
    spawnMap = $MapFactory.getMap(mapId)
    #Kernel.pbMessage(_INTL("{1}",spawnMap.map_id))
    spawnMap.spawnEvent(x,y,encounter)
  end
  # Show grass rustling animations
  $scene.spriteset.addUserAnimation(RUSTLE_NORMAL_ANIMATION_ID,x,y,true,1)
  # Play the pokemon cry of encounter
  pbPlayCryOnOverworld(encounter[0])
  # For roaming encounters we have to do the following:
  if $PokemonTemp.nowRoaming == true && 
     $PokemonTemp.roamerIndex != nil &&
     $PokemonGlobal.roamEncounter != nil
    $PokemonGlobal.roamEncounter = nil
    $PokemonGlobal.roamedAlready = true
  end
  $PokemonTemp.forceSingleBattle = false
  EncounterModifier.triggerEncounterEnd()
end

#===============================================================================
# adding new Methods pbEncounterTypeOnTile and isEncounterPossibleHereOnTile?
# in Class PokemonEncounters in Script PField_Encounters
#===============================================================================
class PokemonEncounters
  def pbEncounterTypeOnTile(x,y)
    if PBTerrain.isJustWater?($game_map.terrain_tag(x,y))
      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
  
  def isEncounterPossibleHereOnTile?(x,y)
    if PBTerrain.isJustWater?($game_map.terrain_tag(x,y))
      return true
    elsif self.isCave?
      return true
    elsif self.isGrass?
      return PBTerrain.isGrass?($game_map.terrain_tag(x,y))
    end
    return false
  end
end

#===============================================================================
# new Method spawnEvent in Class Game_Map in Script Game_Map
#===============================================================================
class Game_Map
  def spawnEvent(x,y,encounter)
    #------------------------------------------------------------------
    # generating a new event
    event = RPG::Event.new(x,y)
    # naming the event "vanishingEncounter" for PART 3 
    event.name = "vanishingEncounter"
    #setting the nessassary properties
    key_id = (@events.keys.max || -1) + 1
    event.id = key_id
    event.x = x
    event.y = y
    #event.pages[0].graphic.tile_id = 0
    if encounter[0] < 10
      character_name = "00"+encounter[0].to_s
    elsif encounter[0] < 100
      character_name = "0"+encounter[0].to_s
    else
      character_name = encounter[0].to_s
    end
    # use shiny-sprite if probability & killcombo is high or shiny-switch is on
    $PokemonTemp.catchcombo=[0,0] if !$PokemonTemp.catchcombo
    if $game_switches[SHINY_WILD_POKEMON_SWITCH]==true
        character_name = character_name+"s"
        shinysprite=true
    elsif ($PokemonTemp.catchcombo[0]>=CHAINLENGTH && $PokemonTemp.catchcombo[1]==encounter[0])
      if rand(SHINYPROBABILITY)<$PokemonTemp.catchcombo[0]
        character_name = character_name+"s"
        shinysprite=true
      end
    end
    event.pages[0].graphic.character_name = character_name
    event.pages[0].move_type = 1
    event.pages[0].trigger = 2
    #------------------------------------------------------------------
    # we add the event commands to the event of the overworld encounter
    event.pages[0].list[0].code = 355
    event.pages[0].list[0].indent = 0
    if $PokemonGlobal.roamEncounter!=nil
      #[i,species,poke[1],poke[4]]
      parameter1 = $PokemonGlobal.roamEncounter[1].to_s
      parameter2 = $PokemonGlobal.roamEncounter[2].to_s
      parameter3 = $PokemonGlobal.roamEncounter[3].to_s
      $PokemonGlobal.roamEncounter[4] != nil ? (parameter4 = '"'+$PokemonGlobal.roamEncounter[4].to_s+'"') : (parameter4 = "nil")
      parameter = " $PokemonGlobal.roamEncounter = ["+parameter1+","+parameter2+","+parameter3+","+parameter4+"] "
    else
      parameter = " $PokemonGlobal.roamEncounter = nil "
    end
    event.pages[0].list[0].parameters = [parameter]
    event.pages[0].list[1] = RPG::EventCommand.new
    #
    event.pages[0].list[1].code = 355
    event.pages[0].list[1].indent = 0
    if $PokemonTemp.nowRoaming!=nil
      parameter =" $PokemonTemp.nowRoaming = "+$PokemonTemp.nowRoaming.to_s
    else
      parameter =" $PokemonTemp.nowRoaming = nil "
    end
    event.pages[0].list[1].parameters = [parameter]
    event.pages[0].list[2] = RPG::EventCommand.new
    #
    event.pages[0].list[2].code = 355
    event.pages[0].list[2].indent = 0
    if $PokemonTemp.roamerIndex!=nil
      parameter = " $PokemonTemp.roamerIndex = "+$PokemonTemp.roamerIndex.to_s
    else
      parameter = " $PokemonTemp.roamerIndex = nil "
    end
    event.pages[0].list[2].parameters = [parameter]
    event.pages[0].list[3] = RPG::EventCommand.new
    #
    event.pages[0].list[3].code = 355
    event.pages[0].list[3].indent = 0
    if $PokemonGlobal.nextBattleBGM!=nil
      parameter = " $PokemonGlobal.nextBattleBGM = "+PokemonGlobal.nextBattleBGM.to_s
    else
      parameter = " $PokemonGlobal.nextBattleBGM = nil "    
    end
    event.pages[0].list[3].parameters = [parameter]
    event.pages[0].list[4] = RPG::EventCommand.new
    #
    event.pages[0].list[4].code = 355
    event.pages[0].list[4].indent = 0
    if $PokemonTemp.forceSingleBattle!=nil
      parameter = " $PokemonTemp.forceSingleBattle = "+$PokemonTemp.forceSingleBattle.to_s
    else
      parameter = " $PokemonTemp.forceSingleBattle = nil "
    end
    event.pages[0].list[4].parameters = [parameter]
    event.pages[0].list[5] = RPG::EventCommand.new
    #
    event.pages[0].list[5].code = 355
    event.pages[0].list[5].indent = 0
    if $PokemonTemp.encounterType!=nil
      parameter = " $PokemonTemp.encounterType = "+$PokemonTemp.encounterType.to_s
    else
      parameter = " $PokemonTemp.encounterType = nil "
    end
    event.pages[0].list[5].parameters = [parameter]
    event.pages[0].list[6] = RPG::EventCommand.new
    #
    # setting shiny switch on if sprite is a shiny-sprite
    oldShinySwitchStatus=$game_switches[SHINY_WILD_POKEMON_SWITCH]
    if shinysprite == true
      parameter = " $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]=true"
    else
      parameter = " $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]=false"
    end
    event.pages[0].list[6].code = 355
    event.pages[0].list[6].indent = 0
    event.pages[0].list[6].parameters = [parameter]
    event.pages[0].list[7] = RPG::EventCommand.new
    #
    #pbSingleOrDoubleWildBattle(encounter[0],encounter[1])
    event.pages[0].list[7].code = 355
    event.pages[0].list[7].indent = 0
    parameter = " pbSingleOrDoubleWildBattle("+encounter[0].to_s+","+encounter[1].to_s+", $game_map.events["+key_id.to_s+"].map.map_id, $game_map.events["+key_id.to_s+"].x, $game_map.events["+key_id.to_s+"].y)"
    event.pages[0].list[7].parameters = [parameter]
    event.pages[0].list[8] = RPG::EventCommand.new
    #
    # setting shiny switch back to previous state
    parameter=" $game_switches["+SHINY_WILD_POKEMON_SWITCH.to_s+"]="+oldShinySwitchStatus.to_s
    event.pages[0].list[8].code = 355
    event.pages[0].list[8].indent = 0
    event.pages[0].list[8].parameters = [parameter]
    event.pages[0].list[9] = RPG::EventCommand.new
    #
    event.pages[0].list[9].code = 355
    event.pages[0].list[9].indent = 0
    event.pages[0].list[9].parameters = ["$PokemonTemp.encounterType = -1"]
    event.pages[0].list[10] = RPG::EventCommand.new
    #
    event.pages[0].list[10].code = 355
    event.pages[0].list[10].indent = 0
    event.pages[0].list[10].parameters = ["$PokemonTemp.forceSingleBattle = false"]
    event.pages[0].list[11] = RPG::EventCommand.new
    #
    event.pages[0].list[11].code = 355
    event.pages[0].list[11].indent = 0
    event.pages[0].list[11].parameters = ["EncounterModifier.triggerEncounterEnd()"]
    event.pages[0].list[12] = RPG::EventCommand.new
    #
    event.pages[0].list[12].code = 355
    event.pages[0].list[12].indent = 0
    event.pages[0].list[12].parameters = ["$game_map.events.delete("+key_id.to_s+")"]
    event.pages[0].list[13] = RPG::EventCommand.new
    #
    event.pages[0].list[13].code = 355
    event.pages[0].list[13].indent = 0
    event.pages[0].list[13].parameters = ["$scene.disposeSpritesets"]
    event.pages[0].list[14] = RPG::EventCommand.new
    #
    event.pages[0].list[14].code = 355
    event.pages[0].list[14].indent = 0
    event.pages[0].list[14].parameters = ["$scene.createSpritesets"]
    event.pages[0].list[15] = RPG::EventCommand.new
    #------------------------------------------------------------------
    # creating and adding the Game_Event
    gameEvent = Game_Event.new(@map_id, event,self)
    key_id = (@events.keys.max || -1) + 1
    gameEvent.id = key_id
    gameEvent.moveto(x,y)
    @events[key_id] = gameEvent
    #-------------------------------------------------------------------------
    #updating the sprites
    sprite = Sprite_Character.new(Spriteset_Map.viewport,@events[key_id])
    $scene.spritesets[self.map_id].character_sprites.push(sprite)
  end
end

#===============================================================================
# adding new Method pbSingleOrDoubleWildBattle to reduce the code in spawnEvent
#===============================================================================
def pbSingleOrDoubleWildBattle(species,level,map_id,x,y)
  if $MapFactory
    terrainTag = $MapFactory.getTerrainTag(map_id,x,y)
  else
    terrainTag = $game_map.terrain_tag(x,y)
  end
  if !$PokemonTemp.forceSingleBattle && ($PokemonGlobal.partner ||
      ($Trainer.ablePokemonCount>1 &&
      PBTerrain.isDoubleWildBattle?(terrainTag) &&
      rand(100)<30))
    encounter2 = $PokemonEncounters.pbEncounteredPokemon($PokemonTemp.encounterType)
    encounter2 = EncounterModifier.trigger(encounter2)
    pbDoubleWildBattle(species,level,encounter2[0],encounter2[1])
  else
    pbWildBattle(species,level)
  end
end


#===============================================================================
# adding new method PBTerrain.isRock? to module PBTerrain in script PBTerrain
# to check if the terrainTag "tag" is rock
#===============================================================================
module PBTerrain
  def PBTerrain.isRock?(tag)
    return tag==PBTerrain::Rock
  end
end

#===============================================================================
# adding new method pbPlayCryOnOverworld to load/play Pokémon cry files 
# SPECIAL THANKS TO "Ambient Pokémon Cries" - by Vendily
# actually it's not used, but that code helped to include the pkmn cries faster
#===============================================================================
def pbPlayCryOnOverworld(pokemon,volume=90,pitch=nil)
  return if !pokemon
  if pokemon.is_a?(Numeric)
    pbPlayCrySpecies(pokemon,0,volume,pitch)
  elsif !pokemon.egg?
    if pokemon.respond_to?("chatter") && pokemon.chatter
      pokemon.chatter.play
    else
      pkmnwav = pbCryFile(pokemon)
      if pkmnwav
        pbBGSPlay(RPG::AudioFile.new(pkmnwav,volume,
           (pitch) ? pitch : (pokemon.hp*25/pokemon.totalhp)+75)) rescue nil
      end
    end
  end
end

#===============================================================================
# adding a new method attr_reader to the Class Spriteset_Map in Script
# Spriteset_Map to get access to the variable @character_sprites of a
# Spriteset_Map
#===============================================================================
class Spriteset_Map
  attr_reader :character_sprites
end

#===============================================================================
# adding a new method attr_reader to the Class Scene_Map in Script
# Scene_Map to get access to the Spriteset_Maps listed in the variable 
# @spritesets of a Scene_Map
#===============================================================================
class Scene_Map
  attr_reader :spritesets
end

          #########################################################
          #                                                       #
          #      3. PART: VANISHING OF OVERWORLD ENCOUNTER        #
          #                                                       #
          #########################################################
#===============================================================================
# adding a new variable stepCount and replacing the method increase_steps
# in class Game_Event in script Game_Event to count the steps of
# overworld encounter and to make them disappear after taking more then
# STEPSBEFOREVANISHING steps
#===============================================================================
class Game_Event < Game_Character
  attr_accessor :event
  attr_accessor :stepCount #counts the steps of an overworld encounter
  
  alias original_increase_steps increase_steps
  def increase_steps
    if self.name=="vanishingEncounter" && @stepCount && @stepCount>=STEPSBEFOREVANISHING
      if $game_map.events.has_key?(@id) and $game_map.events[@id]==self
        #-------------------------------------------------------------------------
        # added to reduce lag by derFischae
        for sprite in $scene.spritesets[$game_map.map_id].character_sprites
          if sprite.character==self
            $scene.spritesets[$game_map.map_id].character_sprites.delete(sprite)
            sprite.dispose
            break
          end
        end
        #-------------------------------------------------------------------------
        $game_map.events.delete(@id)        
      else
        if $MapFactory
          for map in $MapFactory.maps
            if map.events.has_key?(@id) and map.events[@id]==self
              #-------------------------------------------------------------------------
              # added to reduce lag by derFischae
              for sprite in $scene.spritesets[self.map_id].character_sprites
                if sprite.character==self
                  $scene.spritesets[map.map_id].character_sprites.delete(sprite)
                  sprite.dispose
                  break
                end
              end
              #-------------------------------------------------------------------------
              map.events.delete(@id)
              break
            end
          end
        else
          Kernel.pbMessage("Actually, this should not be possible")
        end
      end
      #-------------------------------------------------------------------------
      # added some code above to reduce lag by derFischae
      # Original Code was
      #$scene.disposeSpritesets
      #$scene.createSpritesets
      #-------------------------------------------------------------------------
    else
      @stepCount=0 if ([email protected] || @stepCount<0)
      @stepCount+=1
      original_increase_steps
    end
  end
end