Advertisement
Vendily

Pokemon Outbreaks

Dec 30th, 2018 (edited)
3,690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.28 KB | None | 0 0
  1. #===============================================================================
  2. # Pokémon Outbreaks - By Vendily [v17/v18] - v2.2
  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.2",
  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 $PokemonTemp.pokeradar &&
  56.       encounter[0] == $PokemonTemp.pokeradar[0] &&
  57.       encounter[1] == $PokemonTemp.pokeradar[1]
  58.      return encounter
  59.    end
  60.    if !$PokemonGlobal.currentOutbreak ||
  61.      $PokemonGlobal.currentOutbreak[0]<=-1 ||
  62.      ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  63.      $PokemonGlobal.currentOutbreak=[-1,nil]
  64.    end
  65.    if $PokemonGlobal.currentOutbreak[0]>-1
  66.      newenc=OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  67.      return encounter if $game_map && $game_map.map_id!=newenc[0]
  68.      return encouter if !newenc[4].include?($PokemonEncounters.pbEncounterType)
  69.      if rand(100)<OUTBREAK_CHANCE
  70.        level=rand(newenc[3]-newenc[2])+newenc[2]
  71.        return [getID(PBSpecies,newenc[1]),level]
  72.      end
  73.    end
  74.    return encounter
  75. })
  76.  
  77. Events.onMapUpdate+=proc {|sender,e|
  78.   next if !$game_switches[OUTBREAK_SWITCH]
  79.   if !$PokemonGlobal.currentOutbreak ||
  80.      $PokemonGlobal.currentOutbreak[0]<=-1 ||
  81.      ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  82.      pbGenerateOutbreak
  83.   end
  84. }
  85.  
  86. def pbGenerateOutbreak
  87.   index=rand(OUTBREAK_SPECIES.length)
  88.   $PokemonGlobal.currentOutbreak=[index,pbGetTimeNow]
  89. end
  90.  
  91. def pbOutbreakInformation(speciesvar,mapvar)
  92.   if !$PokemonGlobal.currentOutbreak ||
  93.     $PokemonGlobal.currentOutbreak[0]<=-1 ||
  94.     ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>OUTBREAK_TIME*60*60)
  95.       $PokemonGlobal.currentOutbreak=[-1,nil]
  96.       $game_variables[speciesvar]=-1 if speciesvar>0
  97.       $game_variables[mapvar]=-1 if mapvar>0
  98.       return [-1,-1]
  99.   end
  100.   newenc=OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  101.   species=getID(PBSpecies,newenc[1])
  102.   $game_variables[speciesvar]=PBSpecies.getName(species) if speciesvar>0
  103.   $game_variables[mapvar]=pbGetMessage(MessageTypes::MapNames,newenc[0]) if mapvar>0
  104.   return [newenc[0],species]
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement