Advertisement
Vendily

Pokemon Outbreaks v20

Jul 28th, 2023
2,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.49 KB | None | 0 0
  1. #===============================================================================
  2. # Pokémon Outbreaks - By Vendily [v20] - v4
  3. #===============================================================================
  4. # This script adds in the Mass Outbreak of Pokémon 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 Pokémon will spawn in place of
  19. #    a regular one. (Default 40)
  20. # * The switch used to enable outbreaks, -1 to not use a switch. (Default 100)
  21. # * A set of arrays each containing details of a wild encounter that can only
  22. #      occur via Pokémon 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 (GameData::EncounterType#type).
  28. #===============================================================================
  29. PluginManager.register({
  30.   :name    => "Pokémon Outbreaks",
  31.   :version => "4.0",
  32.   :link    => "https://reliccastle.com/resources/266/",
  33.   :credits => "Vendily"
  34. })
  35. module Settings
  36.   OUTBREAK_TIME    = 24
  37.   OUTBREAK_CHANCE  = 40
  38.   OUTBREAK_SWITCH  = 100
  39.   OUTBREAK_SPECIES = [
  40.       [5,:DODUO,2,2,[:land]],
  41.       [5,:VOLTORB,28,29,[:land]],
  42.       [2,:MILOTIC,12,16,[:water,:fishing]]
  43.     ]
  44. end
  45. class PokemonGlobalMetadata
  46.   attr_accessor :currentOutbreak
  47. end
  48.  
  49. EventHandlers.add(:on_wild_species_chosen,:outbreak_change_mon,
  50.   proc {|encounter|
  51.     next if !encounter
  52.     next if Settings::OUTBREAK_SWITCH>0 && !$game_switches[Settings::OUTBREAK_SWITCH]
  53.     next if $game_temp.poke_radar_data &&
  54.              encounter[0] == $game_temp.poke_radar_data[0] &&
  55.              encounter[1] == $game_temp.poke_radar_data[1]
  56.     if !$PokemonGlobal.currentOutbreak ||
  57.         $PokemonGlobal.currentOutbreak[0]<=-1 ||
  58.         ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>Settings::OUTBREAK_TIME*60*60)
  59.       $PokemonGlobal.currentOutbreak=[-1,nil]
  60.     end
  61.     if $PokemonGlobal.currentOutbreak[0]>-1
  62.       newenc=Settings::OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  63.       next if $game_map&.map_id != newenc[0]
  64.       next if !newenc[4].include?(GameData::EncounterType.get($game_temp.encounter_type).type)
  65.       if rand(100)<Settings::OUTBREAK_CHANCE
  66.         level=rand(newenc[3]-newenc[2])+newenc[2]
  67.         encounter[0] = newenc[1]
  68.         encounter[1] = level
  69.       end
  70.     end
  71.   }
  72. )
  73.  
  74. EventHandlers.add(:on_frame_update,:outbreak_update,
  75.   proc {
  76.     next if Settings::OUTBREAK_SWITCH>0 && !$game_switches[Settings::OUTBREAK_SWITCH]
  77.     if !$PokemonGlobal.currentOutbreak ||
  78.        $PokemonGlobal.currentOutbreak[0]<=-1 ||
  79.        ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>Settings::OUTBREAK_TIME*60*60)
  80.        pbGenerateOutbreak
  81.     end
  82.   }
  83. )
  84.  
  85. def pbGenerateOutbreak
  86.   index=rand(Settings::OUTBREAK_SPECIES.length)
  87.   $PokemonGlobal.currentOutbreak=[index,pbGetTimeNow]
  88. end
  89.  
  90. def pbOutbreakInformation(speciesvar=-1,mapvar=-1)
  91.   if !$PokemonGlobal.currentOutbreak ||
  92.     $PokemonGlobal.currentOutbreak[0]<=-1 ||
  93.     ((pbGetTimeNow-$PokemonGlobal.currentOutbreak[1])>Settings::OUTBREAK_TIME*60*60)
  94.       $PokemonGlobal.currentOutbreak=[-1,nil]
  95.       $game_variables[speciesvar]=-1 if speciesvar>0
  96.       $game_variables[mapvar]=-1 if mapvar>0
  97.       return [-1,-1]
  98.   end
  99.   newenc=Settings::OUTBREAK_SPECIES[$PokemonGlobal.currentOutbreak[0]]
  100.   species=newenc[1]
  101.   $game_variables[speciesvar]=GameData::Species.get(species).name if speciesvar>0
  102.   $game_variables[mapvar]=pbGetMessage(MessageTypes::MapNames,newenc[0]) if mapvar>0
  103.   return [newenc[0],species]
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement