OverusedNameHere
Head Dev - Pokémon Throne
- 23
- Posts
- 5
- Years
- he/she/they
- Florida, USA
- Seen May 25, 2023
is this planned to be updated to v19?
View attachment 90535
* Visible Overworld Wild Encounters Version - by derFischae (Credits if used please) *
Is there anyone who wants to update this script for Pokemon Essentials V19?
please i really do :D
The script is wonderful, but I just ran into an issue as an aggressive encounter spawned just before I started an event cutscene. The player has forced movement in it and the encounter blocked the path. I have prevented this with "ignore if can't move", but the cutscene looks ugly with the encounter interfering. Is it possible to pause the overworld encounters until an event is over?
My first idea to stop spawning during dialogues would be to set the pause flag to true
in the first command of the event (and back to false in the last command of the event). This is definitely not a final solution. But even if there is no spawning during dialogues then there still could be such softlocking produced by overworld encounters that spawned before the dialogue started. So it will be still important to keep an eye on the map design (for example not to small places) as it is also always important if there are other NPCs on the map.Code:$game_temp.in_menu = true
Thank you for the suggestion. I didn't know about the pause flag, but setting it to true also causes the "set move route" actions in the event to be blocked. I have solved it instead by giving them the "Through ON" command as they go past both encounters and moving trainers.My first idea to stop spawning during dialogues would be to set the pause flag to true
please do go right ahead 😩🙏
#===============================================================================
# * Visible Overworld Wild Encounters V19.0.10 for PEv19.1 - by derFischae and TrankerGolD (Credits if used please) *
#===============================================================================
#
# UPDATED TO VERSION 19.0.10 BY TrankerGolD
#
# As in Pokemon Let's go Pikachu/Eevee or Pokemon Shield 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.
#
# This script is for Pokémon Essentials v19 and v19.1 (for short PEv19).
#
# FEATURES INCLUDED for PEv19:
# - You can manage different appear animations in pbPlaceEncounter depending on encounter type
# - Choose whether you can battle water pokemon while not surfing or not with BATTLE_WATER_ONGROUND
# - Stop more PokeEvent from spawning with the MAX_SPAWN parameter
# - Choose to remove PokeEvent distanced on screen from the player with REMOVE_DISTANCED
# - The distance (steps) is edited in DISTANCE_VANISH and DISTANCE_VANISH_SHINY
# - Water pokemon won't spawn above other tiles, which made them stuck or walk on ground
# - Shiny animation while PokeEvent is visible on screen
# - Remove by time chronometer with REMOVE_PROLONGED
# - Use your own chance in VISIBLE_ENCOUNTER_PROBABILITY
# - Agressive pokemon encounters are allways restricted to player movements
# IDEAS for PEv19:
# - don't keep events when saving and quiting the game
# (Currently, there is no need for this)
# - plugin script format?
# - more in the future?
#
# Updated to PEv19.1 by TrankerGolD
#
# FEATURES INCLUDED from PEv18:
# - 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
# - You can check during the events @@OnWildPokemonCreate, @@OnStartBattle, ... if you are battling a spawned pokemon with
# the global variable $PokemonGlobal.battlingSpawnedPokemon
# - You can check during the event @@OnWildPokemonCreate if the pokemon is created for spawning on the map or created for a different
# reason with the Global variable $PokemonGlobal.creatingSpawningPokemon
# - 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.
#
#=====================================================================
# Installation:
#=====================================================================
# Installation as simple as it can be.
# Step 1:
# Get the resources from Gen 8 Project https://reliccastle.com/resources/670/
# You only need to install the "Graphic/Character" folder in your game file system.
# Step 2:
# Insert new line in scripts above Main and name it "Overworld_VisibleEncounters", then copy and paste the code below inside.
# Step 3:
# Enjoy!
# Notes:
# - If you want to use fakemon, then you have to organize the corresponding graphics similarly as in the Gen 8 Project.
# - Try to install updates, Add-ons or modifications for this script.
# - Create new animation in database and edit animation_id in settings script (line 199),
# (if the id number is bigger than the database number of animations it will crash the game).
# - There are a lot of parameter settings for your personal optimal solution. So, edit parameters in settings to your liking.
# - Some parameter combinations can produce lag, e.g. a high spawning rate without a spawning cap "MAX_SPAWN=0", or e.g. "SEARCH_POSSIBLE_TILE=true" with "REROLLS_POSSIBLE_TILE<=0" (or too high) when having other scripts like Pokemon Following.
# - If you use any other script that triggers on change of direction of the player, then these scripts have to be below this visible overworld wild encounter script.
#
#=====================================================================
# Changelog
#=====================================================================
# NEW FEATURES FROM VERSION 19.0.10 FOR PEv19:
# - fixed water pokemon spawning in platform above water tile
# - water pokemon won't appear in the border
# - choose wether battling water pokemon from ground or not with BATTLE_WATER_ONGROUND parameter
# - stop more pokemon from spawning with the MAX_SPAWN parameter
# - choose wether remove distanced spawned pokemon or not with REMOVE_DISTANCED parameter
# - shiny animation while PokeEvent is visible on screen
# - choose wether remove by time chronometer or not with REMOVE_PROLONGED
# - added to add your own chance with VISIBLE_ENCOUNTER_PROBABILITY
# - agressive ecounters restricted to player movements
#
# NEW FEATURES FROM VERSION 19.0.9 FOR PEv19:
# - updated script to work with PEv19.1
# - used $PokemonTemp.encounterType to trigger diferent appear animations
# - added alternative stepcount before vanishining for shiny pokemon
#
# NEW FEATURES FROM VERSION 18.0.8 FOR PEv18:
# - tiny bug fix for $PokemonTemp.encounterType
#
# NEW FEATURES FROM VERSION 18.0.7 FOR PEv18:
# - removed a bug concerning changing the standard form when goining into battle
#
# NEW FEATURES FROM VERSION 18.0.6 FOR PEv18:
# - (hopefully) removed a rare crash concerning character_sprites
#
# NEW FEATURES FROM VERSION 2.0.5 FOR PEv18:
# - removed bug that makes all water encounter vanish
#
# NEW FEATURES FROM VERSION 2.0.4 FOR PEv18:
# - encounters dont spawn on impassable tiles in caves
#
# NEW FEATURES FROM VERSION 2.0.3 FOR PEv18:
# - poke radar works as usual
#
# NEW FEATURES FROM VERSION 2.0.2 FOR PEv18:
# - added new global variable $PokemonGlobal.creatingSpawningPokemon to check during the event @@OnWildPokemonCreate if the pokemon is created for spawning on the map or created for a different reason
#
# UPSCALED FEATURES FROM VERSION 2.0.1 FOR PEv17.2:
# - less lag
# - supports sprites for alternative forms of pokemon
# - supports sprites for female/male/genderless pokemon
# - bug fixes for roaming encounter and double battles
# - more options in settings
# - roaming encounters working correctly
# - more lag reduction
# - included automatic spawning of pokemon, i.e. spawning without having to move the player
# - 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
# - removed bug occuring after fainting against wild overworld encounter
# - for script-developers, shortened the spawnPokeEvent method for better readablitiy
# - 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
# - 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.
# - removed bug to make the new features in version 1.11 work
# - reorganised and thin out the code to organise code as add-ons
# - 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
# - removed a bug that came from reorganising the code in original code and add-ons concerning Let's go shiny hunting add-on
#
#===============================================================================
# Settings
#===============================================================================
module VisibleEncounterSettings
# Animation IDs from visible encounters
SHINY_ANIMATION_ID = 8 #Appear shiny animation
SHINY_NOSOUND_ANIMATION_ID = 9 #Update shiny animation
WATER_ANIMATION_ID = 10 #Appear water animation
ANGRY_ANIMATION_ID = 11 #Appear angry animation
# Create your own animation in database, then uncomment and edit the number id
OVERWORLD_ENCOUNTER_VARIABLE = 26 # default is an ID which is not used anywhere else
# This parameter stores the ID of the $game_variable which holds the propability
# of normal to overworld encountering.
# Make sure that no other script uses the $game_variable with this ID,
# except for the visible overworld wild encounter script itself and its add-ons.
#
# The $game_variable with the ID equal to OVERWORLD_ENCOUNTER_VARIABLE is used
# to store the propability of an instant (normal) wild battle.
# You can modify the value of that $game_variable during game or with events as usual. It is similar to use
# game switches. See the Pokemon Essentials manual for more informations.
# The propability is stored the following way
# $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 0
# - the propability of instant battle to spawning will be equal to the value
# of INSTANT_WILD_BATTLE_PROPABILITY in percentage, see below
# $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] < 0
# - means only overworld encounters, no instant battles
# $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] > 0 and < 100
# - means overworld encounters and normal encounters at the same time,
# where the value equals the propability of normal encounters in percentage
# $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] >= 100
# - means only normal encounters and instant battles as usual, no overworld spawning
INSTANT_WILD_BATTLE_PROPABILITY = 0 # default 0.
# It will be used when starting the game the first time. Changing this value later on will not affect the propability anymore.
# However, you can still change the propability stored in the $game_variable with ID above during runtime.
# This parameter holds the DEFAULT propability of normal to overworld encountering.
# The propability is stored in percentage with possible values 0,1,2,...,100.
# <= 0 - means only overworld encounters, no instant battles
# > 0 and < 100 - means overworld encounters and normal encounters at the same time.
# >= 100 - means only normal encounters and instant battles as usual, no overworld spawning
# You can still change the propability stored in the $game_variable with ID above during runtime.
# But if you don't change the propability ingame, then it will be this INSTANT_WILD_BATTLE_PROPABILITY
# Note that, if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 0 then the propability stored in that $game_variable will be reset to
# the value of INSTANT_WILD_BATTLE_PROPABILITY, unless this is also 0.
VISIBLE_ENCOUNTER_PROBABILITY = 0 #default 0
# The PokeEvent will spawn according to this probability if the value is greater than 0
# <= 0 - means only using the default PEv19.1 encounter chance calculator
# > 0 (1..100) - means using this probabilty out of 100 instead of normal chance
MAX_SPAWN = 0 # default 0
# MAX_SPAWN is the max number of wild Encounters Events that can be
# spawned on the map at the same time.
#<=0 - means infinite (no maximum)
SEARCH_POSSIBLE_TILE = false # default false
#true - means that it will store all tile position around the player
# and proceed to use REROLLS_POSSIBLE_TILE until no more rerolls
# are left
#false - means that only one random tile around the player will be
# chosen
REROLLS_POSSIBLE_TILE = 2 # default 2
# This is only used when SEARCH_POSSIBLE_TILE=true
# Grabs a random tile around the player making sure the reroll is
# diferent each time
#<=0 - means that it will choose a random tile until one of them
# is possible to spawn a pokemon
# (this will increase the spawm probability)
# (may cause lag with other scripts)
# > 0 - number of reroll to find a possible tile
# (the more you use, more performance needed)
SPWAN_RANGE = 4 #default 4
# this is the range from the player a PokeEvent will be able to spawn
RESTRICT_ENCOUNTERS_TO_PLAYER_MOVEMENT = false # default 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)
BATTLE_WATER_FROMGROUND = true #default true
# this is used if you want to battle water pokemon without surfing
# (default is true but I think is better in false)
#false - means the battle wont start if not surfing
#true - means you can battle from the ground a pokemon from the water
STEPS_BEFORE_VANISH = 10 # default 10
# STEPS_BEFORE_VANISH is the number of steps a wild Encounter
# goes before vanishing on the map.
STEPS_BEFORE_VANISH_SHINY = 18 # default 18
# STEPS_BEFORE_VANISH_SHINY is the number of steps a SHINY wild Encounter
# goes before vanishing on the map.
USESHINYSPRITES = true # default true
#false - means that you don't use shiny sprites for your overworld encounter
#true - means that a shiny encounter will have a its special shiny overworld sprite
# make sure that you have the shiny sprites named with an "s" (e.g. 001s.png)
# for the shiny forms in your \Graphics\Characters folder
USEALTFORMS = true # default true
#false - means that you don't use alternative forms for your overworld sprite
#true - means that the sprite of overworld encounter varies by the form of that pokemon
# make sure that you have the sprites with the right name
# for your alternative forms in your \Graphics\Characters folder
USEFEMALESPRITES = true # default true
#false - means that you use always a neutral overworld sprite
#true - means that female pokemon have there own female overworld sprite
# make sure that you have the sprites with the right name 001f.png,
# 001fs.png, ... for the female forms in your \Graphics\Characters folder
USESTOPANIMATION = true # default true
#false - means that overworld encounters don't have a stop- animation
#true - means that overworld encounters have a stop- animation similar as
# following pokemon
ENCMOVESPEED = 3 # default 3
# this is the movement speed (compare to autonomous movement of events) of an overworld encounter
#1 - means lowest movement
#6 - means highest movement
ENCMOVEFREQ = 3 # default 3
# this is the movement frequenzy (compare to autonomous movement of events) of an overworld encounter
#1 - means lowest movement
#6 - means highest movement
AGGRESSIVEENCOUNTERPROBABILITY = 20 # default 20
#this is the probability in percent of spawning of an agressive encounter
#0 - means that there are no aggressive encounters
#100 - means that all encounter are aggressive
AGGRENCMOVESPEED = 3 # default 3
# this is the movement speed (compare to autonomous movement of events) of an aggressive encounter
#1 - means lowest movement
#6 - means highest movement
AGGRENCMOVEFREQ = 5 # default 5
# this is the movement frequenzy (compare to autonomous movement of events) of an aggressive encounter
#1 - means lowest movement
#6 - means highest movement
#------------(SCREEN DISTANCE DESPAWNING)-------------------
REMOVE_DISTANCED = false #default false
# this is used if you want a mechanic that removes PokeEvents when
# distancing from them
#false - means nothing happens
#true - means distanced PokeEvent will disappear
# (regardless of this parameter PokeEvents will despawn when being
# completely in another map)
DISTANCE_VANISH = 12 # default 12
# DISTANCE_VANISH is the max distance on screen a wild Encounter can be
# from the player before vanishing on the map.
#<=0 - means infinite distance (wont disappear from distance)
DISTANCE_VANISH_SHINY = 30 # default 30 (or 0 ?)
# DISTANCE_VANISH_SHINY is the max distance on screen a shiny wild Encounter can be
# from the player before vanishing on the map.
#<=0 - means infinite distance (wont disappear from distance)
#------------------------------------------------------------
#------------(SECONDS PROLONGED DESPAWNING)-------------------
REMOVE_PROLONGED = false #default false
# this is used if you want a mechanic that removes PokeEvents when
# being a prolonged time active
#false - means nothing happens
#true - means prolonged PokeEvent will disappear
SECONDS_VARIATION = 5 # default 5
# SECONDS_VARIATION is the maximum time in seconds randomized
# that will be added or substracted to the actual seconds
# (5 seconds variation to 25 will be 20-30 seconds randomly)
SECONDS_BEFORE_VANISH = 25 # default 25
# SECONDS_BEFORE_VANISH is the max time in secons a wild Encounter can be
# active before vanishing on the map.
#<=0 - means infinite time (wont disappear from time)
SECONDS_BEFORE_VANISH_SHINY = 50 # default 50 (or 0 ?)
# SECONDS_BEFORE_VANISH_SHINY is the max time in secons a shiny wild Encounter can be
# active before vanishing on the map.
#<=0 - means infinite time (wont disappear from time)
#------------------------------------------------------------
end
#===============================================================================
# THE SCRIPT
#===============================================================================
#########################################################
# #
# 1. PART: SPAWNING THE OVERWORLD ENCOUNTER #
# #
#########################################################
#===============================================================================
# (Bug Fix for Events.onChangeDirection)
# - ChangeDirection won't update visible pokemon
# - ChangeDirection will trigger instant battle only if
# OVERWORLD_ENCOUNTER_VARIABLE > 0
#===============================================================================
Events.onChangeDirection.clear
# Notice that this will clear everything related to onChangeDirection
# (on PEv19.1 there is only one proc, so this entire script must be above
# any other script by the community that uses it)
Events.onChangeDirection += proc {
repel_active = ($PokemonGlobal.repel > 0)
setInstantChance if getInstantChance == 0
if (rand(100) < getInstantChance)
pbBattleOnStepTaken(repel_active) if !$game_temp.in_menu
end
}
#===============================================================================
# Method shortcut for variable from OVERWORLD_ENCOUNTER_VARIABLE
#===============================================================================
def getInstantChance
return $game_variables[VisibleEncounterSettings::OVERWORLD_ENCOUNTER_VARIABLE]
end
def setInstantChance(value=nil)
value = VisibleEncounterSettings::INSTANT_WILD_BATTLE_PROPABILITY if !value
value = -1 if value <= 0
value = 100 if value >= 100
$game_variables[VisibleEncounterSettings::OVERWORLD_ENCOUNTER_VARIABLE] = value
end
#===============================================================================
# We override the original method "pbOnStepTaken" in Script Overworld it was
# originally used for random encounter battles
#===============================================================================
def pbOnStepTaken(eventTriggered)
if $game_player.move_route_forcing || pbMapInterpreterRunning?
Events.onStepTakenFieldMovement.trigger(nil,$game_player)
return
end
$PokemonGlobal.stepcount = 0 if !$PokemonGlobal.stepcount
$PokemonGlobal.stepcount += 1
$PokemonGlobal.stepcount &= 0x7FFFFFFF
repel_active = ($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 && !$game_temp.in_menu
setInstantChance if getInstantChance == 0
if (rand(100) < getInstantChance)
#STANDARD WILDBATTLE
pbBattleOnStepTaken(repel_active)
else
#OVERWORLD ENCOUNTERS
pbSpawnOnStepTaken(repel_active)
end
end
$PokemonTemp.encounterTriggered = false # This info isn't needed here
end
#===============================================================================
# new method pbSpawnOnStepTaken working almost like pbBattleOnStepTaken
#===============================================================================
def pbSpawnOnStepTaken(repel_active)
return if $Trainer.able_pokemon_count == 0 #check if trainer has pokemon
#First we decide if there are too many PokeEvents encounters in current map
if VisibleEncounterSettings::MAX_SPAWN>0
return if pbCountPokeEvent >= VisibleEncounterSettings::MAX_SPAWN
end
pos = pbChooseTileOnStepTaken
return if !pos
encounter_type = $PokemonEncounters.encounter_type_on_tile(pos[0],pos[1])
return if !encounter_type
#chance of encountertype reduced if too high
if VisibleEncounterSettings::VISIBLE_ENCOUNTER_PROBABILITY>0
if !encounter_type || !GameData::EncounterType.exists?(encounter_type)
raise ArgumentError.new(_INTL("Encounter type {1} does not exist", encounter_type))
end
return false if $game_system.encounter_disabled
return false if !$Trainer
return false if $DEBUG && Input.press?(Input::CTRL)
return if !(rand(100) < VisibleEncounterSettings::VISIBLE_ENCOUNTER_PROBABILITY)
else
return if !$PokemonEncounters.encounter_triggered?(encounter_type, repel_active, true)
end
$PokemonTemp.encounterType = encounter_type
encounter = $PokemonEncounters.choose_wild_pokemon(encounter_type)
encounter = EncounterModifier.trigger(encounter)
if $PokemonEncounters.allow_encounter?(encounter, repel_active)
form = nil
gender = nil
$PokemonGlobal.creatingSpawningPokemon = true
pokemon = pbGenerateWildPokemon(encounter[0],encounter[1])
# trigger event on spawning of pokemon
Events.onWildPokemonCreateForSpawning.trigger(nil,pokemon)
$PokemonGlobal.creatingSpawningPokemon = false
encounter = [pokemon.species,pokemon.level]
gender = pokemon.gender
form = pokemon.form
isShiny = pokemon.shiny?
pbPlaceEncounter(pos[0],pos[1],encounter,gender,form,isShiny)
$PokemonTemp.encounterType = nil
$PokemonTemp.encounterTriggered = true
end
$PokemonTemp.forceSingleBattle = false
EncounterModifier.triggerEncounterEnd
end
#===============================================================================
# new methods to count pkmn spawned
#===============================================================================
#Count all spawned events
def pbCountPokeEvent
currentCountPokeEvent = 0
if $MapFactory
for map in $MapFactory.maps
for event in map.events.values
if event.name.include? "vanishingEncounter"
currentCountPokeEvent = currentCountPokeEvent + 1
end
end
end
end
return currentCountPokeEvent
end
#Count spawned events in current map
def pbCountPokeEventInMap
currentCountPokeEvent = 0
$game_map.events.values.each { |event|
if event.name.include? "vanishingEncounter"
currentCountPokeEvent = currentCountPokeEvent + 1
end
}
return currentCountPokeEvent
end
#===============================================================================
# new method pbChooseTileOnStepTaken to choose the tile on which the pkmn spawns
#===============================================================================
def pbChooseTileOnStepTaken
x=$game_player.x
y=$game_player.y
range=VisibleEncounterSettings::SPWAN_RANGE
if(VisibleEncounterSettings::SEARCH_POSSIBLE_TILE)
positions = []
for i in 0...range+1
for j in 0...range+1
next if i==0 && j==0
positions.push([x+i,y+j])
positions.push([x+i,y-j])
positions.push([x-i,y-j])
positions.push([x-i,y+j])
end
end
positions = positions.uniq
rerolls = VisibleEncounterSettings::REROLLS_POSSIBLE_TILE + 1
rerolls = positions.length if rerolls > positions.length
rerolls = positions.length if rerolls <= 0
while rerolls > 0
r = rand(positions.length)
pos = positions[r]
return pos if pbTileIsPossible(pos[0],pos[1])
positions.delete(pos)
rerolls-=1
end
else
pos = randomTileFromPosition(x,y, range)
return pos if pbTileIsPossible(pos[0],pos[1])
end
return
end
#===============================================================================
# new method randomTileFromPosition to return a position
#===============================================================================
def randomTileFromPosition(x,y, distance)
i = rand(distance)
r = rand((i+1)*8)
new_x = x
new_y = y
if r<=(i+1)*2
new_x = x-i-1+r
new_y = y-i-1
elsif r<=(i+1)*6-2
new_x = [x+i+1,x-i-1][r%2]
new_y = y-i+((r-1-(i+1)*2)/2).floor
else
new_x = x-i+r-(i+1)*6
new_y = y+i+1
end
return [new_x,new_y]
end
#===============================================================================
# new method pbTileIsPossible to check is tile is good to spawn
#===============================================================================
def pbTileIsPossible(x,y)
if !$game_map.valid?(x,y) #check if the tile is on the map
return false
else
tile_terrain_tag = $game_map.terrain_tag(x,y)
end
for event in $game_map.events.values
if event.x==x && event.y==y
return false
end
end
return false if !tile_terrain_tag
#check if it's a valid grass, water or cave etc. tile
return false if tile_terrain_tag.ice
return false if tile_terrain_tag.ledge
return false if tile_terrain_tag.waterfall
return false if tile_terrain_tag.waterfall_crest
return false if tile_terrain_tag.id == :Rock
if VisibleEncounterSettings::RESTRICT_ENCOUNTERS_TO_PLAYER_MOVEMENT
return false if !tile_terrain_tag.can_surf &&
$PokemonGlobal && $PokemonGlobal.surfing
return false if tile_terrain_tag.can_surf &&
!($PokemonGlobal && $PokemonGlobal.surfing)
end
if tile_terrain_tag.can_surf
for i in [2, 1, 0]
tile_id = $game_map.data[x, y, i]
return false if !tile_id || tile_id < 0
next if tile_id == 0
terrain = GameData::TerrainTag.try_get($game_map.terrain_tags[tile_id])
passage = $game_map.passages[tile_id]
priority = $game_map.priorities[tile_id]
break if terrain.can_surf
# Ignore if tile above water
return false if passage!=0
return false if priority==0 && !terrain.ignore_passability
end
else
return false if !$game_map.passableStrict?(x, y, 0)
end
return false if !$PokemonEncounters.encounter_possible_here_on_tile?(x,y)
return true
end
#===============================================================================
# defining new method pbPlaceEncounter to add/place and visualise the pokemon
# "encounter" on the overworld-tile (x,y)
#===============================================================================
def pbPlaceEncounter(x,y,encounter,gender = nil,form = nil,isShiny = nil)
# 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.spawnPokeEvent(x,y,encounter,gender,form,isShiny)
else
mapId = $game_map.map_id
spawnMap = $MapFactory.getMap(mapId)
spawnMap.spawnPokeEvent(x,y,encounter,gender,form,isShiny)
end
#Appear Animation
encType = GameData::EncounterType.try_get($PokemonTemp.encounterType)
if !encType
# Show default animation
$scene.spriteset.addUserAnimation(Settings::RUSTLE_NORMAL_ANIMATION_ID,x,y,true,1)
else
if encType.type == :water
# Show water swirl animation
water_anim_id = VisibleEncounterSettings::WATER_ANIMATION_ID if defined?(VisibleEncounterSettings::WATER_ANIMATION_ID)
if water_anim_id && $data_animations[water_anim_id]
$scene.spriteset.addUserAnimation(water_anim_id,x,y,true,1)
end
elsif encType.type == :cave
# Show dust animation
$scene.spriteset.addUserAnimation(Settings::DUST_ANIMATION_ID,x,y,true,1)
elsif encType.type == :land
# Show grass rustling animation
$scene.spriteset.addUserAnimation(Settings::RUSTLE_NORMAL_ANIMATION_ID,x,y,true,1)
end
end
#Appear Shiny Animation
if isShiny
# Show shiny animation with sound
shiny_anim_id = VisibleEncounterSettings::SHINY_ANIMATION_ID if defined?(VisibleEncounterSettings::SHINY_ANIMATION_ID)
if shiny_anim_id && $data_animations[shiny_anim_id]
$scene.spriteset.addUserAnimation(shiny_anim_id,x,y,true,1)
end
end
# Play the pokemon cry of encounter
pbPlayCryOnOverworld(encounter[0], form)
# For roaming encounters we have to do the following:
if $PokemonTemp.roamerIndex != nil &&
$PokemonGlobal.roamEncounter != nil
$PokemonGlobal.roamEncounter = nil
$PokemonGlobal.roamedAlready = true
end
$PokemonTemp.encounterType = -1
$PokemonTemp.forceSingleBattle = false
EncounterModifier.triggerEncounterEnd()
end
#===============================================================================
# adding new Methods encounter_type_on_tile and encounter_possible_here_on_tile?
# in Class PokemonEncounters
#===============================================================================
class PokemonEncounters
def encounter_type_on_tile(x,y)
time = pbGetTimeNow
ret = nil
if $game_map.terrain_tag(x,y).can_surf_freely
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(x, 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
def encounter_possible_here_on_tile?(x,y)
tile_terrain_tag = $game_map.terrain_tag(x,y)
if tile_terrain_tag.can_surf_freely
#pokemon on water won't appear in the border if you uncomment this four lines
#return false if !$game_map.terrain_tag(x+1,y).can_surf_freely
#return false if !$game_map.terrain_tag(x-1,y).can_surf_freely
#return false if !$game_map.terrain_tag(x,y+1).can_surf_freely
#return false if !$game_map.terrain_tag(x,y-1).can_surf_freely
return true
end
return true if tile_terrain_tag.can_surf_freely
return false if tile_terrain_tag.ice
return true if has_cave_encounters? # i.e. this map is a cave
return true if has_land_encounters? && tile_terrain_tag.land_wild_encounters
return false
end
# Returns whether a wild encounter should be turned into a double wild
# encounter depending on tile.
def have_double_wild_battle_on_tile?(x,y)
return false if $PokemonTemp.forceSingleBattle
return false if pbInSafari?
return true if $PokemonGlobal.partner
return false if $Trainer.able_pokemon_count <= 1
return true if $game_map.terrain_tag(x,y).double_wild_encounters && rand(100) < 30
return false
end
end
#===============================================================================
# new Method spawnPokeEvent in Class Game_Map in Script Game_Map
#===============================================================================
class Game_Map
def spawnPokeEvent(x,y,encounter,gender = nil,form = nil, isShiny = nil)
#------------------------------------------------------------------
# generating a new event
event = RPG::Event.new(x,y)
# naming the event "vanishingEncounter" for PART 3
event.name = "vanishingEncounter"
event.name = "vanishingEncounter_Shiny" if isShiny
#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
#Graphic of the event
graphic_gender = (VisibleEncounterSettings::USEFEMALESPRITES && gender!=nil) ? gender : 0
graphic_form = (VisibleEncounterSettings::USEALTFORMS && form!=nil) ? form : 0
graphic_shiny = (VisibleEncounterSettings::USESHINYSPRITES && isShiny!=nil) ? isShiny : false
fname = GameData::Species.ow_sprite_filename(encounter[0].to_s, graphic_form, graphic_gender, graphic_shiny)
fname.gsub!("Graphics/Characters/","")
event.pages[0].graphic.character_name = fname
#------------------------------------------------------------------
encType = GameData::EncounterType.try_get($PokemonTemp.encounterType)
#------------------------------------------------------------------
canBeAgressive = true
if encType
#agressive Pokemon on water only when surfing
canBeAgressive = false if !$PokemonGlobal.surfing && encType.type == :water
#agressive Pokemon on land only when not surfing
canBeAgressive = false if $PokemonGlobal.surfing && encType.type != :water
end
# we configure the movement of the overworld encounter
if canBeAgressive && rand(100) < VisibleEncounterSettings::AGGRESSIVEENCOUNTERPROBABILITY
event.pages[0].move_type = 3
event.pages[0].move_speed = VisibleEncounterSettings::AGGRENCMOVESPEED
event.pages[0].move_frequency = VisibleEncounterSettings::AGGRENCMOVEFREQ
event.pages[0].move_route.list[0].code = 10
event.pages[0].move_route.list[1] = RPG::MoveCommand.new
# Show water swirl animation
angry_anim_id = VisibleEncounterSettings::ANGRY_ANIMATION_ID if defined?(VisibleEncounterSettings::WATER_ANIMATION_ID)
if angry_anim_id && $data_animations[angry_anim_id]
$scene.spriteset.addUserAnimation(angry_anim_id,x,y,true,1)
end
else
event.pages[0].move_type = 1
event.pages[0].move_speed = VisibleEncounterSettings::ENCMOVESPEED
event.pages[0].move_frequency = VisibleEncounterSettings::ENCMOVEFREQ
end
event.pages[0].step_anime = true if VisibleEncounterSettings::USESTOPANIMATION
event.pages[0].trigger = 2
#------------------------------------------------------------------
# we add the event commands to the event of the overworld encounter
# set roamer
if $PokemonGlobal.roamEncounter!=nil
#[i,species,poke[1],poke[4]]
parameter1 = $PokemonGlobal.roamEncounter[0].to_s
parameter2 = $PokemonGlobal.roamEncounter[1].to_s
parameter3 = $PokemonGlobal.roamEncounter[2].to_s
$PokemonGlobal.roamEncounter[3] != nil ? (parameter4 = '"'+$PokemonGlobal.roamEncounter[3].to_s+'"') : (parameter4 = "nil")
parameter = " $PokemonGlobal.roamEncounter = ["+parameter1+","+parameter2+","+parameter3+","+parameter4+"] "
else
parameter = " $PokemonGlobal.roamEncounter = nil "
end
Compiler::push_script(event.pages[0].list,sprintf(parameter))
parameter = ($PokemonTemp.roamerIndex!=nil) ? " $PokemonTemp.roamerIndex = "+$PokemonTemp.roamerIndex.to_s : " $PokemonTemp.roamerIndex = nil "
Compiler::push_script(event.pages[0].list,sprintf(parameter))
#parameter = ($PokemonGlobal.nextBattleBGM!=nil) ? " $PokemonGlobal.nextBattleBGM = '"+$PokemonGlobal.nextBattleBGM.to_s+"'" : " $PokemonGlobal.nextBattleBGM = nil "
#pbPushScript(event.pages[0].list,sprintf(parameter))
parameter = ($PokemonTemp.forceSingleBattle!=nil) ? " $PokemonTemp.forceSingleBattle = "+$PokemonTemp.forceSingleBattle.to_s : " $PokemonTemp.forceSingleBattle = nil "
Compiler::push_script(event.pages[0].list,sprintf(parameter))
parameter = ($PokemonTemp.encounterType!=nil) ? " $PokemonTemp.encounterType = :"+$PokemonTemp.encounterType.to_s : " $PokemonTemp.encounterType = nil "
Compiler::push_script(event.pages[0].list,sprintf(parameter))
# setting $PokemonGlobal.battlingSpawnedPokemon = true
Compiler::push_script(event.pages[0].list,sprintf(" $PokemonGlobal.battlingSpawnedPokemon = true"))
#pbSingleOrDoubleWildBattle(encounter[0],encounter[1])
gender = "nil" if gender==nil
form = "nil" if form==nil
#shinysprite = (isShiny==true) ? true : nil
shinysprite = isShiny
shinysprite = "nil" if shinysprite==nil
#Battle (used branch to handle water pokemon when player on ground)
Compiler::push_branch(event.pages[0].list,sprintf(" 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,"+gender.to_s+","+form.to_s+","+shinysprite.to_s+")"))
# setting $PokemonGlobal.battlingSpawnedPokemon = false
Compiler::push_script(event.pages[0].list,sprintf(" $PokemonGlobal.battlingSpawnedPokemon = false"),1)
if !$MapFactory
parameter = "$game_map.removeThisEventfromMap(#{key_id})"
else
mapId = $game_map.map_id
parameter = "$MapFactory.getMap("+mapId.to_s+").removeThisEventfromMap(#{key_id})"
end
Compiler::push_script(event.pages[0].list,sprintf(parameter),1)
Compiler::push_branch_end(event.pages[0].list,1)
Compiler::push_end(event.pages[0].list)
#------------------------------------------------------------------
# creating and adding the Game_PokeEvent
gameEvent = Game_PokeEvent.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]=Spriteset_Map.new(self) if $scene.spritesets[self.map_id]==nil
$scene.spritesets[self.map_id].character_sprites.push(sprite)
# alternatively: updating the sprites (old and slow but working):
#$scene.disposeSpritesets
#$scene.createSpritesets
end
end
#-------------------------------------------------------------------------------
# New method for easily get the appropriate Pokemon Graphic (copied from Folowing Pokemon EX)
#-------------------------------------------------------------------------------
module GameData
class Species
def self.ow_sprite_filename(species, form = 0, gender = 0, shiny = false, shadow = false)
ret = self.check_graphic_file("Graphics/Characters/", species, form,
gender, shiny, shadow, "Followers")
ret = "Graphics/Characters/Followers/000" if nil_or_empty?(ret)
return ret
end
end
end
#===============================================================================
# adding new Method pbSingleOrDoubleWildBattle to reduce the code in spawnPokeEvent
#===============================================================================
def pbSingleOrDoubleWildBattle(species,level,map_id,x,y,gender = nil,form = nil,shinysprite = nil)
if !VisibleEncounterSettings::BATTLE_WATER_FROMGROUND
#the pokemon encounter battle won't happen
#if it is in the water and the player is not surfing
encType = GameData::EncounterType.try_get($PokemonTemp.encounterType)
waterpokemon = encType.type == :water
return false if (!$PokemonGlobal.surfing && waterpokemon)
end
if $MapFactory
terrainTag = $MapFactory.getTerrainTag(map_id,x,y)
else
terrainTag = $game_map.terrain_tag(x,y)
end
if $PokemonEncounters.have_double_wild_battle_on_tile?(x,y)
encounter2 = $PokemonEncounters.choose_wild_pokemon($PokemonTemp.encounterType)
encounter2 = EncounterModifier.trigger(encounter2)
pbDoubleWildBattle(species,level,encounter2[0],encounter2[1],nil,true,false,gender,form,shinysprite,nil,nil,nil)
else
pbWildBattle(species,level,nil,true,false,gender,form,shinysprite)
end
$PokemonTemp.encounterType = nil
$PokemonTemp.encounterTriggered = true
$PokemonTemp.forceSingleBattle = false
EncounterModifier.triggerEncounterEnd
return true
end
#===============================================================================
# overriding Method pbWildBattle in Script PField_Battles
# to include alternate forms of the wild pokemon
#===============================================================================
#-----------------------------------------------------------------------------
#added by derFischae to set the gender, form and shinyflag
#genwildpoke.gender = gender if gender!=nil and gender>=0 and gender<3
#genwildpoke.form = form if form!=nil and form>0
#genwildpoke.shiny = shinysprite if shinysprite!=nil
# well actually it is not okay to test if form>0, we should also test if form
# is smaller than the maximal form, but for now I keep it that way.
#-----------------------------------------------------------------------------
#===============================================================================
# Standard methods that start a wild battle of various sizes
#===============================================================================
# Used when walking in tall grass, hence the additional code.
def pbWildBattle(species, level, outcomeVar=1, canRun=true, canLose=false,gender = nil,form = nil,shinysprite = nil)
species = GameData::Species.get(species).id
# Potentially call a different pbWildBattle-type method instead (for roaming
# Pokémon, Safari battles, Bug Contest battles)
handled = [nil]
Events.onWildBattleOverride.trigger(nil,species,level,handled)
return handled[0] if handled[0]!=nil
# Set some battle rules
setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
setBattleRule("cannotRun") if !canRun
setBattleRule("canLose") if canLose
# Prepare pokemon
pkmn = pbGenerateWildPokemon(species,level)
pkmn.gender = gender if gender!=nil and gender>=0 and gender<3
pkmn.form = form if form!=nil and form>=0
pkmn.reset_moves
pkmn.shiny = shinysprite if shinysprite != nil
# Perform the battle
decision = pbWildBattleCore(pkmn)
# Used by the Poké Radar to update/break the chain
Events.onWildBattleEnd.trigger(nil,species,level,decision)
# Return false if the player lost or drew the battle, and true if any other result
return (decision!=2 && decision!=5)
end
#===============================================================================
# overriding Method pbDoubleWildBattle in Script PField_Battles
# to include alternate forms of the wild pokemon in double battles
#===============================================================================
#-----------------------------------------------------------------------------
#added by derFischae to set the gender, form and shinyflag
# well actually it is not okay to test if form>0, we should also test if form
# is smaller than the maximal form, but for now I keep it that way.
#genwildpoke.setGender(gender1) if USEFEMALESPRITES==true and gender1!=nil and gender1>=0 and gender1<3
#if USEALTFORMS==true and form1!=nil and form1>0
# genwildpoke.form = form1
# genwildpoke.shinyflag = shinysprite1 if shinysprite1!=nil
# genwildpoke.resetMoves
#end
#genwildpoke2.setGender(gender) if USEFEMALESPRITES==true and gender2!=nil and gender2>=0 and gender2<3
#if USEALTFORMS==true and form2!=nil and form2>0
# genwildpoke2.form = form2 if USEALTFORMS==true and form2!=nil and form2>0
# genwildpoke2.shinyflag = shinysprite2 if shinysprite2!=nil
# genwildpoke2.resetMoves
#end
#-----------------------------------------------------------------------------
def pbDoubleWildBattle(species1, level1, species2, level2,
outcomeVar=1, canRun=true, canLose=false,
gender1 = nil,form1 = nil,shinysprite1 = nil,gender2 = nil,form2 = nil,shinysprite2 = nil)
# Set some battle rules
setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
setBattleRule("cannotRun") if !canRun
setBattleRule("canLose") if canLose
setBattleRule("double")
# Prepare pokemon 1
pkmn1 = pbGenerateWildPokemon(species1,level1)
pkmn1.gender = gender1 if gender1!=nil and gender1>=0 and gender1<3
pkmn1.form = form1 if form1!=nil and form1>=0
pkmn1.reset_moves
pkmn1.shiny = shinysprite1 if shinysprite1 != nil
# Prepare pokemon 2
pkmn2 = pbGenerateWildPokemon(species2,level2)
pkmn2.gender = gender2 if gender2!=nil and gender2>=0 and gender2<3
pkmn2.form = form2 if form2!=nil and form2>=0
pkmn2.reset_moves
pkmn2.shiny = shinysprite2 if shinysprite2 != nil
# Perform the battle
decision = pbWildBattleCore(pkmn1, pkmn2)
# Return false if the player lost or drew the battle, and true if any other result
return (decision!=2 && decision!=5)
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,form=0,volume=30,pitch=100) # default volume=90
return if !pokemon || pitch <= 0
form = 0 if form==nil
if pokemon.is_a?(Pokemon)
if !pokemon.egg?
GameData::Species.play_cry_from_pokemon(pokemon,volume,pitch)
end
else
GameData::Species.play_cry_from_species(pokemon,form,volume,pitch)
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
#########################################################
# #
# 2. PART: VANISHING OF OVERWORLD ENCOUNTER #
# #
#########################################################
#===============================================================================
# adding a new variable stepCount and replacing the method increase_steps
# in class Game_Event in script Game_PokeEvent to count the steps of
# overworld encounter and to make them disappear after taking exactly
# STEPS_BEFORE_VANISH steps
# and for shiny if exactly STEPS_BEFORE_VANISH_SHINY steps
#------
# also replacing method update
# - SHINY_NOSOUND_ANIMATION_ID is the id of the existing animation in database
# that will play constantly over a shiny pokemon when it is in the screen
# - if REMOVE_DISTANCED is activated calculates the screen distance from the
# PokeEvent to the Player and make them disappear after separeting exactly
# DISTANCE_VANISH tiles, and for shiny if exactly DISTANCE_VANISH_SHINY tiles
# - if REMOVE_PROLONGED is activated checks by frames how long has the
# PokeEvent being active, and make them disappear after waiting
# SECONDS_BEFORE_VANISH seconds, and for shiny SECONDS_BEFORE_VANISH_SHINY seconfs
#===============================================================================
class Game_PokeEvent < Game_Event
#attr_accessor :event
attr_accessor :stepCount #counts the steps of an overworld encounter
attr_accessor :frameCount #counts the existence frames of an overworld encounter
def initialize(map_id, event, map=nil)
super(map_id, event, map)
end
alias original_increase_steps increase_steps
def increase_steps
if self.name=="vanishingEncounter" && @stepCount && @stepCount>=VisibleEncounterSettings::STEPS_BEFORE_VANISH
removeThisEventfromMap
elsif self.name=="vanishingEncounter_Shiny" && @stepCount && @stepCount>=VisibleEncounterSettings::STEPS_BEFORE_VANISH_SHINY
removeThisEventfromMap
else
@stepCount=0 if (!@stepCount || @stepCount<0)
@stepCount+=1
original_increase_steps
end
end
def removeThisEventfromMap
if $game_map.events.has_key?(@id) and $game_map.events[@id]==self
if defined?($scene.spritesets)
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
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
if defined?($scene.spritesets) && $scene.spritesets[self.map_id] && $scene.spritesets[self.map_id].character_sprites
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
end
map.events.delete(@id)
break
end
end
else
pbMessage("Actually, this should not be possible")
end
end
end
alias original_update update
def update
original_update
return if $game_temp.in_menu
#SHINY SPARKLE FOR SHINY
if self.name=="vanishingEncounter_Shiny"
shiny_anim_id = VisibleEncounterSettings::SHINY_NOSOUND_ANIMATION_ID if defined?(VisibleEncounterSettings::SHINY_NOSOUND_ANIMATION_ID)
#check if animation exist
if shiny_anim_id && $data_animations[shiny_anim_id]
#spam every (animationframes + 4) frames
if Graphics.frame_count % ($data_animations[shiny_anim_id].frames.length + 4) == 0
#check if event on screen
if (self.screen_x >= 0 && self.screen_x <= Graphics.width) || (self.screen_y-16 >= 0 && self.screen_y-16 <= Graphics.height)
#Show shiny animation
#check if event on same map as player
if @map_id!= $game_map.map_id #diferent map
sx = self.screen_x - $game_player.screen_x
sy = self.screen_y - $game_player.screen_y
newx = $game_player.x + (sx/32)
newy = $game_player.y + (sy/32)
$scene.spriteset.addUserAnimation(shiny_anim_id,newx,newy,true,1)
else #same map
$scene.spriteset.addUserAnimation(shiny_anim_id,x,y,true,1)
end
end
end
end
end
#REMOVE DISTANCED
if VisibleEncounterSettings::REMOVE_DISTANCED && (self.name.include? "vanishingEncounter")
sx = (self.screen_x - $game_player.screen_x).abs
sy = (self.screen_y - $game_player.screen_y).abs
distance = [sx,sy].max
if self.name=="vanishingEncounter" && VisibleEncounterSettings::DISTANCE_VANISH>0 && distance>=VisibleEncounterSettings::DISTANCE_VANISH*32
removeThisEventfromMap
elsif self.name=="vanishingEncounter_Shiny" && VisibleEncounterSettings::DISTANCE_VANISH_SHINY>0 && distance>=VisibleEncounterSettings::DISTANCE_VANISH_SHINY*32
removeThisEventfromMap
end
end
#REMOVE PROLONGED
@frameCount=0 if !@frameCount
if VisibleEncounterSettings::REMOVE_PROLONGED && (self.name.include? "vanishingEncounter")
varTime = VisibleEncounterSettings::SECONDS_VARIATION
extraTime = rand(varTime*2)+1 - varTime
if self.name=="vanishingEncounter"
time = VisibleEncounterSettings::SECONDS_BEFORE_VANISH
if time>0
removeThisEventfromMap if @frameCount > ((time + extraTime) * Graphics.frame_rate)
end
elsif self.name=="vanishingEncounter_Shiny"
time = VisibleEncounterSettings::SECONDS_BEFORE_VANISH_SHINY
if time>0
removeThisEventfromMap if @frameCount > ((time + extraTime) * Graphics.frame_rate)
end
end
end
@frameCount+=1
end
end
#-------------
class Game_Map
def removeThisEventfromMap(id)
if @events.has_key?(id)
if defined?($scene.spritesets)
for sprite in $scene.spritesets[@map_id].character_sprites
if sprite.character == @events[id]
$scene.spritesets[@map_id].character_sprites.delete(sprite)
sprite.dispose
break
end
end
end
@events.delete(id)
end
end
end
#===============================================================================
# new methods to remove pkmn spawned
#===============================================================================
#Remove all spawned events
def pbRemovePokeEvents
if $MapFactory
for map in $MapFactory.maps
for event in map.events.values
if event.name.include? "vanishingEncounter"
event.removeThisEventfromMap
end
end
end
end
end
#Remove spawned events in current map
def pbRemovePokeEventsInMap
$game_map.events.values.each { |event|
if event.name.include? "vanishingEncounter"
event.removeThisEventfromMap
end
}
end
#--------------------------------------
#########################################################
# #
# 3. PART: ADDITIONAL FEATURES #
# #
#########################################################
#===============================================================================
# Adding Event OnWildPokemonCreateForSpawning to Module Events in Script PField_Field.
# This Event is triggered when a new pokemon spawns. Use this Event instead of OnWildPokemonCreate
# if you want to add a new procedure that modifies a pokemon on spawning
# but not on creation while going into battle with an already spawned pokemon.
#Note that OnPokemonCreate is also triggered when a pokemon is created for spawning,
#But OnPokemonCreateForSpawning is not triggered when a pokemon is created in other situations than for spawning
#===============================================================================
module Events
@@OnWildPokemonCreateForSpawning = Event.new
# Triggers whenever a wild Pokémon is created for spawning
# Parameters:
# e[0] - Pokémon being created for spawning
def self.onWildPokemonCreateForSpawning; @@OnWildPokemonCreateForSpawning; end
def self.onWildPokemonCreateForSpawning=(v); @@OnWildPokemonCreateForSpawning = v; end
end
#===============================================================================
# adds new parameter battlingSpawnedPokemon to the class PokemonGlobalMetadata.
# Also overrides initialize include that parameter there.
#===============================================================================
class PokemonGlobalMetadata
attr_accessor :creatingSpawningPokemon
attr_accessor :battlingSpawnedPokemon
alias original_initialize initialize
def initialize
creatingSpawningPokemon = false
battlingSpawnedPokemon = false
original_initialize
end
end
#===============================================================================
# ADD-ONS: =====================================================================
#===============================================================================
#===============================================================================
# Allways Shiny (when switch activated)
#===============================================================================
Events.onWildPokemonCreateForSpawning += proc { |_sender,_e|
pokemon = _e[0]
if $game_switches[Settings::SHINY_WILD_POKEMON_SWITCH]
pokemon.shiny = true
end
}
#===============================================================================
# (Bug Fix for Events.onChangeDirection)
# - ChangeDirection won't update visible pokemon
# - ChangeDirection will trigger instant battle only if
# OVERWORLD_ENCOUNTER_VARIABLE > 0
#===============================================================================
Events.onChangeDirection.clear
# Notice that this will clear everything related to onChangeDirection
# (on PEv19.1 there is only one proc, so this entire script must be above
# any other script by the community that uses it)
Events.onChangeDirection += proc {
repel_active = ($PokemonGlobal.repel > 0)
setInstantChance if getInstantChance == 0
if (getInstantChance >= 100 || rand(100) < getInstantChance)
pbBattleOnStepTaken(repel_active) if !$game_temp.in_menu
end
}
# Start wild encounters while turning on the spot
Events.onChangeDirection += proc {
repel = ($PokemonGlobal.repel>0)
pbBattleOnStepTaken(repel) if !$game_temp.in_menu
}
Events.onChangeDirection += proc {
repel_active = ($PokemonGlobal.repel > 0)
setInstantChance if getInstantChance == 0
if (getInstantChance >= 100 || rand(100) < getInstantChance)
pbBattleOnStepTaken(repel_active) if !$game_temp.in_menu
end
}
# Start wild overworld/mixed encounters while turning on the spot
Events.onChangeDirection += proc {
repel = ($PokemonGlobal.repel>0)
if !$game_temp.in_menu
if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE] == 0
if INSTANT_WILD_BATTLE_PROPABILITY > 0 && INSTANT_WILD_BATTLE_PROPABILITY < 100
$game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = INSTANT_WILD_BATTLE_PROPABILITY
elsif INSTANT_WILD_BATTLE_PROPABILITY >= 100
$game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = 100
else
$game_variables[OVERWORLD_ENCOUNTER_VARIABLE] = -1
end
end
if $game_variables[OVERWORLD_ENCOUNTER_VARIABLE]>0 && ($game_variables[OVERWORLD_ENCOUNTER_VARIABLE]>=100 || rand(100) < $game_variables[OVERWORLD_ENCOUNTER_VARIABLE])
#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,isShiny = pbChooseEncounter(pos[0],pos[1],repel)
return if !encounter
#we generate an random encounter overworld event
pbPlaceEncounter(pos[0],pos[1],encounter,gender,form,isShiny)
end
end
}
Hi everyone.
During the implementations of new features I've been wondering about how to handle PokeEvents as temporals, so pokemon are not there after saving and loading up your game.
Since it is a hard task I came up with an Add-On that does something similar but in a forced manner:
This Add-On is a simple idea that removes all PokeEvents when loading a save and when transferring.Spoiler:Code:#=============================================================================== # Add-On: Remove all PokeEvent on load_save/transfer by TrankerGolD # (only for v19.1) #=============================================================================== #Method for removing all spawned events def pbRemovePokeEvents if $MapFactory for map in $MapFactory.maps for event in map.events.values if event.name.include? "vanishingEncounter" event.removeThisEventfromMap end end end end end #Overide load_map module Game class << self alias original_load_map load_map end def self.load_map original_load_map pbRemovePokeEvents end end #Overide transfer_player (optional) class Scene_Map alias original_transfer_player transfer_player def transfer_player(cancelVehicles=true) pbRemovePokeEvents original_transfer_player(cancelVehicles) end end
Concerning player transferring:
- Sometimes a transfer to the same map can happen, which won't clear and update the map
- If you want to use it on specific transfers you will have to delete the last part ("#Overide transfer_player"...) and call "pbRemovePokeEvents" right before transferring to another location of the same map.
Also, with this Add-On you can call the script "pbRemovePokeEvents" inside any event whenever needed.
In this post I bring not Add-On, but an animation resource.
So, for everyone who haven't noticed yet the new script for PEv19.1 has parameters to store the id of specific animations.
Currently, since the only thing provided is code there was no need for this kind of thing.
But for anyone that is interested in this, here are some examples on what you can do with them:
Spoiler:
(When shiny or agressive the animations have a specific sound effect so you can notice without looking)
You can find these new animations I created in this download.
(WARNING! This resource overrides your current animations.rxdata which contains all animations from the database, DON'T use this resource if you already edited yours.)
If you already have your own animations and still want to try these ones here is a little tip:
You can totally make your own animations instead, and remember this is for the script that works with PEv19.1 version.Spoiler:Code:- First, copy your project folder (or download PEv19.1) - Second, paste there (in the copy) the animations.rxdata in Data folder - Third, open both your project and the copied project with the animations - Fourth, in the copied project open database, go to Animations, click "008: Shiny", and do Ctrl+C - Fifth, in your own proyect do the same but click a blank space with no animations and do Ctrl+V - Sixth, do the 4th and 5th step with: - "009: Shiny no sound" - "010: Water splash" - "011: Agressive" - Seventh, make sure your project has the audio and graphic - Eighth, change in VisibleEncounterSettings the id for the animations
Here is the instruction to different encounters for over-world spawning and original encountering on the same map in V19.1:
Insert a new line in scripts under "Overworld_VisibleEncounter" and call it "Overworld_EncounterType", and paste this code inside:
And done, the solution is much simpler in PEv19.1 (no need to modify scripts)Spoiler:Code:#=============================================================================== # * Different EncounterType # * for over-world spawning and original encountering on the same map # * by TrankerGolD # * made for Visible Overworld Wild Encounters for PEv19.1 - by derFischae and TrankerGolD (Credits if used please) * #=============================================================================== GameData::EncounterType.register({ :id => :OverworldLand, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldLandDay, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldLandNight, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldLandMorning, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldLandAfternoon, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldLandEvening, :type => :overworld_land, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCave, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCaveDay, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCaveNight, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCaveMorning, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCaveAfternoon, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldCaveEvening, :type => :overworld_cave, :trigger_chance => 5, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) GameData::EncounterType.register({ :id => :OverworldWater, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldWaterDay, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldWaterNight, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldWaterMorning, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldWaterAfternoon, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldWaterEvening, :type => :overworld_water, :trigger_chance => 2, :old_slots => [60, 30, 5, 4, 1] }) GameData::EncounterType.register({ :id => :OverworldBugContest, :type => :overworld_contest, :trigger_chance => 21, :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] }) #=============================================================================== # adding new Methods encounter_type_on_tile and encounter_possible_here_on_tile? # in Class PokemonEncounters #=============================================================================== class PokemonEncounters #============================================================================= # Returns whether land-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around. def has_overworld_land_encounters? GameData::EncounterType.each do |enc_type| next if ![:overworld_land, :overworld_contest].include?(enc_type.type) return true if has_encounter_type?(enc_type.id) end return false end # Returns whether land-like encounters have been defined for the current map # (ignoring the Bug Catching Contest one). # Applies only to encounters triggered by moving around. def has_normal_overworld_land_encounters? GameData::EncounterType.each do |enc_type| return true if enc_type.type == :overworld_land && has_encounter_type?(enc_type.id) end return false end # Returns whether cave-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around. def has_overworld_cave_encounters? GameData::EncounterType.each do |enc_type| return true if enc_type.type == :overworld_cave && has_encounter_type?(enc_type.id) end return false end # Returns whether water-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around (i.e. not fishing). def has_overworld_water_encounters? GameData::EncounterType.each do |enc_type| return true if enc_type.type == :overworld_water && has_encounter_type?(enc_type.id) end return false end #============================================================================= def encounter_type_on_tile(x,y) time = pbGetTimeNow ret = nil if has_overworld_water_encounters? && $game_map.terrain_tag(x,y).can_surf_freely ret = find_valid_encounter_type_for_time(:OverworldWater, time) else # OverworldLand/OverworldCave (can have both in the same map) if has_overworld_land_encounters? && $game_map.terrain_tag(x, y).land_wild_encounters ret = :OverworldBugContest if pbInBugContest? && has_encounter_type?(:OverworldBugContest) ret = find_valid_encounter_type_for_time(:OverworldLand, time) if !ret end if !ret && has_overworld_cave_encounters? ret = find_valid_encounter_type_for_time(:OverworldCave, time) end end return ret end end
How to use:
I think this should work properly as intended.Spoiler:Code:- Go to encounters.txt in the PBS folder. - Use for example OverworldLand instead of Land for visible encounters spawning. - All new EncounterType are: OverworldLand OverworldLandDay OverworldLandNight OverworldLandMorning OverworldLandAfternoon OverworldLandEvening OverworldCave OverworldCaveDay OverworldCaveNight OverworldCaveMorning OverworldCaveAfternoon OverworldCaveEvening OverworldWater OverworldWaterDay OverworldWaterNight OverworldWaterMorning OverworldWaterAfternoon OverworldWaterEvening OverworldBugContest - (NOTE: using this script will restrict visible encounters spawn to the new EncounterTypes)
Big Thanks to derFischae for v19.1 support!
There seems to be an issue with the v19.1 version. There are an awful lot of Pokémon spawning at a very high rate, no matter how high or low the step value is. I didn't have that issue in the v18 version.
return if !$PokemonEncounters.encounter_triggered?(encounterType, repel)
return if !$PokemonEncounters.encounter_possible_here_on_tile?(x,y)
My bad, this line of code sould be used in v19.1:
Code:return if !$PokemonEncounters.encounter_triggered?(encounterType, repel)
Inside pbChooseEncounter, under this line:
Code:return if !$PokemonEncounters.encounter_possible_here_on_tile?(x,y)
This will use the encounters chance saved in encounters.txt and will check if the first pokemon has a certain Item or Ability,
also holding Control in Debug mode will prevent from spawning pokemon
I've been working on an update that will have more parameter/features, and some problems including that one will be already fixed.
My bad, this line of code sould be used in v19.1:
Code:return if !$PokemonEncounters.encounter_triggered?(encounterType, repel)
Inside pbChooseEncounter, under this line:
Code:return if !$PokemonEncounters.encounter_possible_here_on_tile?(x,y)
This will use the encounters chance saved in encounters.txt and will check if the first pokemon has a certain Item or Ability,
also holding Control in Debug mode will prevent from spawning pokemon
I've been working on an update that will have more parameter/features, and some problems including that one will be already fixed.
Thanks! It works perfectly now. And thank you for the update to v19.1.
Now I have another problem. Once in a while there is a problem with trainer battles. If I start one then this massage is appearing:
Spoiler:[2021-08-16 09:22:40 +0200]
[Pokémon Essentials version 19.1]
[Generation 8 Project v1.0.3]
Exception: RuntimeError
Message: Script error in event 4 (coords 4,8), map 10 (Cedolan Gym):
Exception: SystemStackError
Message: stack level too deep
***Full script:
pbTrainerIntro(:CAMPER)
pbNoticePlayer(get_character(0))
Backtrace:
373:Overworld_VisibleEncounters:831:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
373:Overworld_VisibleEncounters:838:in `increase_steps'
Backtrace:
033:Interpreter:189:in `rescue in execute_script'
033:Interpreter:135:in `execute_script'
034:Interpreter_Commands:1024:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032: Scene_Map:157:in `block in update'
032: Scene_Map:155:in `loop'
032: Scene_Map:155:in `update'
When I'm deleting the script, all trainer battles working as intented.
I hope you can help.
The method "original_increase_steps" links to the already defined method "increase_steps". This method is not defined in the visible overworld wild encounter script. It is defined in Pokemon Essentials or could be overwritten by any other script you installed. If you use f12 without closing the test window, then the game memory will not be cleared. This leads to the problem that the method "original_increase_steps" does not link to the original method "increase_steps" anymore, but to the later defined method "increase_steps" in the visible overworld wild encounter script. This behaviour leads to the stack overflow after using f12 without closing the window and, by the way, can occure in any arbitrary script which uses the "alias" command. That's why I do not recommand to use f12 without closing the window.
However, if you want to continue with your workflow and use f12, then you can do so by modifying the code in the following way:
Go find the following code in the visible overworld wild encounter script (it is the snippet where your errors occure)
and replace it byCode:alias original_increase_steps increase_steps def increase_steps if self.name=="vanishingEncounter" && @stepCount && @stepCount>=STEPSBEFOREVANISHING removeThisEventfromMap else @stepCount=0 if (!@stepCount || @stepCount<0) @stepCount+=1 original_increase_steps end end
It will work, I tested it. However, if you use any other script that overwrites the Method "increase_steps" of Class "Game_Character" in Script section "Game_Character", then this new code above will neglect that changes of that other script and could lead to compatibly problems. The original code above will not due to the alias command.Code:def increase_steps if self.name=="vanishingEncounter" && @stepCount && @stepCount>=STEPSBEFOREVANISHING removeThisEventfromMap else @stepCount=0 if (!@stepCount || @stepCount<0) @stepCount+=1 @stop_count = 0 triggerLeaveTile() end end
You're welcome.
$PokemonTemp.encounterType = -1
$PokemonTemp.encounterType = nil