Vendily

Pokemon Outbreaks

Dec 30th, 2018 (edited)
514
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # Pokémon Outbreaks - By Vendily [v17/v18] - v2.1
  3. #===============================================================================
  4. # This script adds in the Mass outbreak of pokemon that appear on a random map.
  5. # It uses the Gen 4 version of the mechanics, so when the save is loaded, if
  6. #  there is no active outbreak and the switch is active, will pick one outbreak
  7. #  at random and spawn them at a 40% encounter rate. Feel free to change that of
  8. #  course.
  9. #===============================================================================
  10. # This script includes some utility functions, such as the ability to
  11. #  randomly set a new outbreak at will with pbGenerateOutbreak, and get the
  12. #  location and species of an outbreak, pbOutbreakInformation (which can save in
  13. #  two variables,  for species and map in that order). The variables contain
  14. #  strings for names, or -1 if there is no outbreak. It will also return the map
  15. #  id and species index for your scripting uses.
  16. #===============================================================================
  17. # * The length of time that an encounter will last in hours. (Default 24)
  18. # * The percent chance an outbroken pokemon will spawn in place of
  19. #    a regular one. (Default 40)
  20. # * The switch used to enable outbreaks. (Default 100)
  21. # * A set of arrays each containing details of a wild encounter that can only
  22. #      occur via Pokemon Outbreaks. The information within is as follows:
  23. #      - Map ID on which this encounter can occur.
  24. #      - Species.
  25. #      - Minimum possible level.
  26. #      - Maximum possible level.
  27. #      - Allowed encounter types.
  28. #===============================================================================
  29. begin
  30. PluginManager.register({
  31.   :name    => "Pokémon Outbreaks",
  32.   :version => "2.1",
  33.   :link    => "https://reliccastle.com/resources/266/",
  34.   :credits => "Vendily"
  35. })
  36. rescue
  37.   # not v18
  38. end
  39.  
  40. OUTBREAK_TIME    = 24
  41. OUTBREAK_CHANCE  = 40
  42. OUTBREAK_SWITCH  = 100
  43. OUTBREAK_SPECIES = [
  44.     [5,:DODUO,2,2,[EncounterTypes::Land]],
  45.     [5,:VOLTORB,28,29,[EncounterTypes::Land,EncounterTypes::LandNight]],
  46.     [2,:MILOTIC,12,16,[EncounterTypes::Water]]
  47.     ]
  48. class PokemonGlobalMetadata
  49.   attr_accessor :currentOutbreak
  50. end
  51.  
  52. EncounterModifier.register(proc {|encounter|
  53.    return encounter if !encounter
  54.    return encounter if !$game_switches[OUTBREAK_SWITCH]
  55.    if !$PokemonGlobal.currentOutbreak ||
  56.      $PokemonGlobal.currentOutbreak[0]<=-1 ||
  57.      ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  58.      $PokemonGlobal.currentOutbreak=[-1,nil]
  59.    end
  60.    if $PokemonGlobal.currentOutbreak[0]>-1
  61.      newenc=OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  62.      return encounter if $game_map && $game_map.map_id!=newenc[0]
  63.      return encouter if !newenc[4].include?($PokemonEncounters.pbEncounterType)
  64.      if rand(100)<OUTBREAK_CHANCE
  65.        level=rand(newenc[3]-newenc[2])+newenc[2]
  66.        return [getID(PBSpecies,newenc[1]),level]
  67.      end
  68.    end
  69.    return encounter
  70. })
  71.  
  72. Events.onMapUpdate+=proc {|sender,e|
  73.   next if !$game_switches[OUTBREAK_SWITCH]
  74.   if !$PokemonGlobal.currentOutbreak ||
  75.      $PokemonGlobal.currentOutbreak[0]<=-1 ||
  76.      ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  77.      pbGenerateOutbreak
  78.   end
  79. }
  80.  
  81. def pbGenerateOutbreak
  82.   index=rand(OUTBREAK_SPECIES.length)
  83.   $PokemonGlobal.currentOutbreak=[index,pbGetTimeNow]
  84. end
  85.  
  86. def pbOutbreakInformation(speciesvar,mapvar)
  87.   if !$PokemonGlobal.currentOutbreak ||
  88.     $PokemonGlobal.currentOutbreak[0]<=-1 ||
  89.     ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  90.       $PokemonGlobal.currentOutbreak=[-1,nil]
  91.       $game_variables[speciesvar]=-1 if speciesvar>0
  92.       $game_variables[mapvar]=-1 if mapvar>0
  93.       return [-1,-1]
  94.   end
  95.   newenc=OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  96.   species=getID(PBSpecies,newenc[1])
  97.   $game_variables[speciesvar]=PBSpecies.getName(species) if speciesvar>0
  98.   $game_variables[mapvar]=pbGetMessage(MessageTypes::MapNames,newenc[0]) if mapvar>0
  99.   return [newenc[0],species]
  100. end
RAW Paste Data