• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Script: Pokemon Outbreaks

1,669
Posts
8
Years
  • Age 23
  • Seen today
Sometimes swarms of Pokemon appear on routes they normally don't. This script just replicates the Gen 4 mechanics, for the most part. As long as the switch to activate is on, it will generate a predefined outbreak of Pokemon on one route for the time period you have set up. The script defaults to 24 hours and will persist through a save and quit.

It's a plug and play script, defaulting to being enabled with switch 100, and it has a 40% chance of replacing the normal encounter on a map.

Included are two utility methods, pbGenerateOutbreak and pbOutbreakInformation. pbGenerateOutbreak, just creates a new outbreak and resets the time period, while pbOutbreakInformation takes two arguments, the variable number to save the species and the variable number to save the map name, and it also returns an array containing the map id and species index. pbOutbreakInformation will set the variables to -1 if there is no outbreak and returns [-1,-1].

To create a new possible outbreak, you just need to add another array to OUTBREAKSPECIES. The script comes predefined with two encounters, Doduo on map id 5 that only spawn at level 2 and Voltorb on map id 5 that spawn at level 28-29.

Now you can set encounters to work with only a certain Encounter type, so you don't get Zigzagoons while you surf!

v17/v18 Pastebin: https://pastebin.com/REm39gHv
v19 Pastebin: https://pastebin.com/c5LU0ThP
v20 Pastebin https://pastebin.com/UQpWgsTq
 
Last edited:
16
Posts
11
Years
  • Seen Apr 25, 2020
could you help me understand how to use the pbOutbreakInformation method? when i create an event using essentials 17.2 with this in a script it returns an error "exception:argument error, wrong number of arguments (0 of 2)" other then that everything works great!
 
277
Posts
15
Years
You have to pass 2 arguments through pbOutbreakInformation, the first being the Pokemon you want to spawn and the second being the map you want them to spawn on. I don't have this script installed but my best guess would be to do something like this.

pbOutbreakInformation(DITTO,42)
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
could you help me understand how to use the pbOutbreakInformation method? when i create an event using essentials 17.2 with this in a script it returns an error "exception:argument error, wrong number of arguments (0 of 2)" other then that everything works great!

pbOutbreakInformation takes two arguments, the index of the game variable used to save the species, and the index used to save the map name. You can set them to zero or under if you don't want to set the value to any game variable.
 
16
Posts
11
Years
  • Seen Apr 25, 2020
i figured out the outbreak info, thanks! but it appears its not automatically generating a new outbreak. I changed the outbreak time to 4 hours but its been the same outbreak for days. any suggestions?
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
Couple of things I want to check. Do you have more than one outbreak defined, and what value did you set OUTBREAKTIME to?
 
16
Posts
11
Years
  • Seen Apr 25, 2020
heres what i have set up :
OUTBREAKTIME = 4
OUTBREAKCHANCE = 40
OUTBREAKSWITCH = 129
OUTBREAKSPECIES = [
[20,:BULBASAUR,2,5,[EncounterTypes::Land]],
[21,:CHARMANDER,3,8,[EncounterTypes::Land]],
[22,:CHARMANDER,7,12,[EncounterTypes::Land]],
[25,:PORYGON,18,21,[EncounterTypes::Land]],
[28,:DRATINI,18,23,[EncounterTypes::Water]],
[32,:CHANSEY,23,23,[EncounterTypes::Land]],
[34,:TAUROS,27,33,[EncounterTypes::Land]],
[34,:SCYTHER,25,31,[EncounterTypes::Land]],
[34,:PINSIR,25,31,[EncounterTypes::Land]],
[36,:EEVEE,22,26,[EncounterTypes::Land]],
[38,:LAPRAS,25,35,[EncounterTypes::Water]],
[39,:LAPRAS,25,35,[EncounterTypes::Water]],
[42,:EXEGGCUTE,32,34,[EncounterTypes::Land]],
[43,:SQUIRTLE,7,12,[EncounterTypes::Land]],
[44,:SQUIRTLE,9,14,[EncounterTypes::Land]],
[209,:BULBASAUR,3,6,[EncounterTypes::Land]],
[220,:KANGASKHAN,14,18,[EncounterTypes::Cave]],
]
class PokemonGlobalMetadata
attr_accessor :currentOutbreak
end

thanks so much for the responses!
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
Okay, so here's the rub, I can't reproduce the issue. I did stick in FL's unreal time, since I wasn't in the mood to set this up for an overnight test, but that has no impact on the running of the script itself.

Here's my debug code to see if the generation code even activates. Do recall that this is RNG in the end, and it's possible to get the same pokemon multiple times in a row technically. I did get two different encounters, and EEVEE and a LAPRAS, generated
Code:
def pbGenerateOutbreak
  index=rand(OUTBREAKSPECIES.length)
  $PokemonGlobal.currentOutbreak=[index,pbGetTimeNow]
  newenc=OUTBREAKSPECIES[$PokemonGlobal.currentOutbreak[0]]
  species=getID(PBSpecies,newenc[1])
  p _INTL("ENCOUNTER INDEX: {1} ({2} on {3})",index,PBSpecies.getName(species), newenc[0])
end
Also, in your code, you have an extra comma at the end of [220,:KANGASKHAN,14,18,[EncounterTypes::Cave]],. I realized I removed it on my end, so that may or may not have an impact. (It probably would just mess with the encounter modifier and the outbreak info code though, since the script wasn't made to expect a nil, the generation would just pull a regular index, it doesn't care about that.)
 
16
Posts
11
Years
  • Seen Apr 25, 2020
ok, so i just want to make sure im doing this right, do i need to use the pbGenerateOutbreak command in an event somewhere to generate a new outbreak? or is this script supposed to just automatically generate a new outbreak every so many hours? because if i use the pbGenerateOutbreak command it works, but lets say i set the outbreak time to 1 hour, the outbreak remains the same past 1 hour.

also, in an unrelated issue i have solved, i was getting an error for a water outbreak on a map with both land and water encounters. it appears you have a small typo on line 49 of your script "return encouter if !newenc[4].include?($PokemonEncounters.pbEncounterType)" it appears you missed an "n" in return encounter at the beginning. i changed this and it fixed my error.
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
oh goodness, it's misspelled!
I'll need to fix this tomorrow!
and the script should automatically generate the encounters, provided the activating switch, 129 in your case, is on.
 
16
Posts
11
Years
  • Seen Apr 25, 2020
after testing out your script in a clean version of essentials, it worked just fine, so i went back and finally figured it out. turns out if you change what switch activates the outbreaks, you also need to change the (100) in line "if rand(100)<OUTBREAKCHANCE" to whatever switch you set, i did this and it works just fine now
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
after testing out your script in a clean version of essentials, it worked just fine, so i went back and finally figured it out. turns out if you change what switch activates the outbreaks, you also need to change the (100) in line "if rand(100)<OUTBREAKCHANCE" to whatever switch you set, i did this and it works just fine now

That's not how that works. rand(100) is literally, get a random number from 0 to 99. so by default it's a 40% chance. what you did was change it to rand(129), so a 40/129 chance of the encounter getting replaced.

Call it bad luck.

Anyway, I fixed the misspelled encounter error, sorry about that one.
 
226
Posts
8
Years
  • Age 32
  • Seen Jul 19, 2023
Hello! This is working great! Unless I am mistaken, you can only have one active outbreak at a given moment of time. How could you possibly have two or three outbreaks occurring simultaneously?
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
Hello! This is working great! Unless I am mistaken, you can only have one active outbreak at a given moment of time. How could you possibly have two or three outbreaks occurring simultaneously?

You are not mistaken, the script as is only supports 1 outbreak at a time. It saves the index and start time of the outbreak in $PokemonGlobal.currentOutbreak, so you would probably have to start there to add multiple outbreaks (save multiple indexes?).
 
226
Posts
8
Years
  • Age 32
  • Seen Jul 19, 2023
Thanks! In case anyone is interested, I found a simple, although not very elegant nor flexible way of having three simultaneous outbreaks.

Code:
EncounterModifier.register(proc {|encounter|
   return encounter if !encounter
   return encounter if !$game_switches[OUTBREAKSWITCH]
   if !$PokemonGlobal.currentOutbreak ||
     $PokemonGlobal.currentOutbreak[0]<=-1 ||
     ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAKTIME*60*60)
     $PokemonGlobal.currentOutbreak=[COLOR="RoyalBlue"][-1,nil,-1,-1][/COLOR]
   end
   if $PokemonGlobal.currentOutbreak[0]>-1
     newenc=OUTBREAKSPECIES[$PokemonGlobal.currentOutbreak[0]]
     return encounter if $game_map && $game_map.map_id!=newenc[0]
     return encounter if !newenc[4].include?($PokemonEncounters.pbEncounterType)
     if rand(100)<OUTBREAKCHANCE
       level=rand(newenc[3]-newenc[2])+newenc[2]
       return [getID(PBSpecies,newenc[1]),level]
     end
   end
[COLOR="RoyalBlue"]   if $PokemonGlobal.currentOutbreak[2]>-1
     newenc=OUTBREAKSPECIES[$PokemonGlobal.currentOutbreak[2]]
     return encounter if $game_map && $game_map.map_id!=newenc[0]
     return encounter if !newenc[4].include?($PokemonEncounters.pbEncounterType)
     if rand(100)<OUTBREAKCHANCE
       level=rand(newenc[3]-newenc[2])+newenc[2]
       return [getID(PBSpecies,newenc[1]),level]
     end
   end
   if $PokemonGlobal.currentOutbreak[3]>-1
     newenc=OUTBREAKSPECIES[$PokemonGlobal.currentOutbreak[3]]
     return encounter if $game_map && $game_map.map_id!=newenc[0]
     return encounter if !newenc[4].include?($PokemonEncounters.pbEncounterType)
     if rand(100)<OUTBREAKCHANCE
       level=rand(newenc[3]-newenc[2])+newenc[2]
       return [getID(PBSpecies,newenc[1]),level]
     end[/COLOR]
   end
   return encounter
})

Code:
def pbGenerateOutbreak
 index=rand(OUTBREAKSPECIES.length)
  [COLOR="RoyalBlue"] loop do
    index2=rand(OUTBREAKSPECIES.length)
    index3=rand(OUTBREAKSPECIES.length)
    if index != index2 && index != index3 && index2 != index3
      break
    end
  end
  $PokemonGlobal.currentOutbreak=[index,pbGetTimeNow,index2,index3][/COLOR]
end
 
Last edited:
68
Posts
4
Years
  • Age 20
  • Seen Nov 9, 2023
Does anyone know how to add a way to find out what Pokemon is swarming in what location via a TV broadcast/NPC?
 
1,669
Posts
8
Years
  • Age 23
  • Seen today
Does anyone know how to add a way to find out what Pokemon is swarming in what location via a TV broadcast/NPC?

That would be pbOutbreakInformation(speciesvar,mapvar). You give it two game variable indices, say, 1 and 2, and then you can do \v[1] for the species name and \v[2] for the map name.
 
68
Posts
4
Years
  • Age 20
  • Seen Nov 9, 2023

I tried it and I got this error:

---------------------------
Pokemon Essentials
---------------------------
[Pokémon Essentials version 17.2]

Exception: RuntimeError

Message: Script error within event 4 (coords 12,13), map 155 (ROUTE 1):

Exception: SyntaxError

Message: (eval):1:in `pbExecuteScript'compile error
(eval):1: syntax error
@pbOutbreakInformation(0,1)
^

***Full script:

@pbOutbreakInformation(0,1)




Interpreter:276:in `pbExecuteScript'

Interpreter:1606:in `command_355'

Interpreter:494:in `execute_command'

Interpreter:193:in `update'

Interpreter:106:in `loop'

Interpreter:198:in `update'

Scene_Map:163:in `follow_update'

Scene_Map:161:in `loop'

Scene_Map:170:in `follow_update'

Following_Pokemon:1935:in `update'



This exception was logged in

C:\Users\Kids\Saved Games\Pokemon Essentials\errorlog.txt.

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK
---------------------------
 
Back
Top