Random Egg Generator

Status
Not open for further replies.

KitsuneKouta

狐 康太
  • 442
    Posts
    15
    Years
    • Seen Nov 20, 2017
    This is a script that allows you to get a randomly generated egg, excluding evolved forms and legendaries.

    First, alter pbGenerateEgg to look like this:
    Code:
    def pbGenerateEgg(species,level)
     if $Trainer.party.length>=6
      raise _INTL("I'm sorry, but it would seem that you can't carry any more Pokemon.")
     end
     # Get egg steps
     dexdata=pbOpenDexData
     pbDexDataOffset(dexdata,species,21)
     eggsteps=dexdata.fgetw
     dexdata.close
     # Generate egg
     egg=PokeBattle_Pokemon.new(species,level,$Trainer)
     egg.calcStats
     egg.name=_INTL("EGG")
     egg.eggsteps=eggsteps
     # Checks the egg to prevent incorrect pokemon from being generated
     if pbHasEgg?(species) == true && species > 0
       # Add egg to party
       $Trainer.party[$Trainer.party.length]=egg
       Audio.se_play("Audio/SE/itemlevel.wav")
       text=_INTL("{1} recieved an egg!",$Trainer.name)
       Kernel.pbMessage(text)
     else
       # Runs the generator again until the above conditions are met
       pbRandomEgg
     end
    end
    Then, right below it add this:

    Code:
    def pbRandom(x)
     return rand(x)
    end
    
    def pbRandomEgg
      if $Trainer.party.length>=6
        text=_INTL("You don't have room for the egg.")
        Kernel.pbMessage(text)
      else
        pbGenerateEgg(rand(493),5)
      end
    end
    
    def pbHasEgg?(species)
      whitelist=[
        :BULBASAUR,:CHARMANDER,:SQUIRTLE,:CATERPIE,:WEEDLE,:PIDGEY,:RATTATA,:SPEAROW,
        :EKANS,:SANDSHREW,:NIDORANfE,:NIDORANmA,:VULPIX,:ZUBAT,:ODDISH,:PARAS,:VENONAT,
        :DIGLETT,:MEOWTH,:PSYDUCK,:MANKEY,:GROWLITHE,:POLIWAG,:ABRA,:MACHOP,:BELLSPROUT,
        :TENTACOOL,:GEODUDE,:PONYTA,:SLOWPOKE,:MAGNEMITE,:FARFETCHD,:DODUO,:SEEL,:GRIMER,
        :SHELLDER,:GASTLY,:ONIX,:DROWZEE,:KRABBY,:VOLTORB,:EXEGGCUTE,:CUBONE,:LICKITUNG,
        :KOFFING,:RHYHORN,:TANGELA,:KANGASKHAN,:HORSEA,:GOLDEEN,:STARYU,:SCYTHER,:PINSIR,
        :TAUROS,:MAGIKARP,:LAPRAS,:DITTO,:EEVEE,:PORYGON,:OMANYTE,:KABUTO,:AERODACTYL,
        :DRATINI,:CHIKORITA,:CYNDAQUIL,:TOTODILE,:SENTRET,:HOOTHOOT,:LEDYBA,:SPINARAK,
        :CHINCHOU,:PICHU,:CLEFFA,:IGGLYBUFF,:TOGEPI,:NATU,:MAREEP,:HOPPIP,:AIPOM,:YANMA,
        :SUNKERN,:WOOPER,:MURKROW,:MISDREAVUS,:UNOWN,:GIRAFARIG,:PINECO,:DUNSPARCE,:GLIGAR,
        :SNUBULL,:QWILFISH,:SHUCKLE,:HERACROSS,:SNEASEL,:TEDDIURSA,:SWINUB,:SLUGMA,:CORSOLA,
        :REMORAID,:DELIBIRD,:SKARMORY,:HOUNDOUR,:PHANPY,:STANTLER,:SMEARGLE,:TYROGUE,:SMOOCHUM,
        :ELEKID,:MAGBY,:MILTANK,:LARVITAR,:TREECKO,:TORCHIC,:MUDKIP,:POOCHYENA,:ZIGZAGOON,
        :WURMPLE,:LOTAD,:SEEDOT,:TAILLOW,:WINGULL,:RALTS,:SURSKIT,:SHROOMISH,:SLAKOTH,:NINCADA,
        :WHISMUR,:MAKUHITA,:AZURILL,:NOSEPASS,:SKITTY,:SABLEYE,:MAWILE,:ARON,:MEDITITE,
        :ELECTRIKE,:PLUSLE,:MINUN,:VOLBEAT,:ILLUMISE,:GULPIN,:CARVANHA,:WAILMER,:NUMEL,:TORKOAL,
        :SPOINK,:SPINDA,:TRAPINCH,:CACNEA,:SWABLU,:ZANGOOSE,:SEVIPER,:LUNATONE,:SOLROCK,:BARBOACH,
        :CORPHISH,:BALTOY,:LILEEP,:ANORITH,:FEEBAS,:CASTFORM,:KECLEON,:SHUPPET,:DUSKULL,:TROPIUS,
      :ABSOL,:WYNAUT,:SNORUNT,:SPHEAL,:CLAMPERL,:RELICANTH,:LUVDISC,:BAGON,:BELDUM,:TURTWIG,:CHIMCHAR,
        :PIPLUP,:STARLY,:BIDOOF,:KRICKETOT,:SHINX,:BUDEW,:CRANIDOS,:SHIELDON,:BURMY,:COMBEE,
        :PACHIRISU,:BUIZEL,:CHERUBI,:SHELLOS,:GASTRODON,:DRIFLOON,:BUNEARY,:GLAMEOW,:CHINGLING,
        :STUNKY,:BRONZOR,:BONSLY,:MIMEJR,:HAPPINY,:CHATOT,:SPIRITOMB,:GIBLE,:MUNCHLAX,:RIOLU,
        :HIPPOPOTAS,:SKORUPI,:CROAGUNK,:CARNIVINE,:LUMINEON,:MANTYKE,:SNOVER
      ]
      for i in whitelist
       return true if isConst?(species,PBSpecies,i)
      end
      return false
    end
    To use this script, simply add a script command in an event like this: Kernel.pbRandomEgg

    Don't forget to credit if used.

    Thanks to Cilerba for the request which gave me the idea, and KingCharizard for some help on the logic.
     
    Last edited:
    May I suggest a better version of "pbHasEgg" method. This will work even for custom Pokemon species. However,
    it uses the script section PokemonEvolutionHelper, which is included only in newer releases. Also, the function
    was not tested yet.
    Code:
    def pbHasEgg?(species)
     dexdata=pbOpenDexData()
     pbDexDataOffset(dexdata,species,18)
     genderbyte=dexdata.fgetb # Get gender rate of this species
     dexdata.close()
     baby=pbGetBabySpecies(species) # Get baby species
     # Has egg if this is a baby species and isn't genderless
     return (baby==species && genderbyte!=255)
    end
     
    May I suggest a better version of "pbHasEgg" method. This will work even for custom Pokemon species. However,
    it uses the script section PokemonEvolutionHelper, which is included only in newer releases. Also, the function
    was not tested yet.
    Code:
    def pbHasEgg?(species)
     dexdata=pbOpenDexData()
     pbDexDataOffset(dexdata,species,18)
     genderbyte=dexdata.fgetb # Get gender rate of this species
     dexdata.close()
     baby=pbGetBabySpecies(species) # Get baby species
     # Has egg if this is a baby species and isn't genderless
     return (baby==species && genderbyte!=255)
    end

    Thanks a bunch. I knew it was possible, and Maruno told me about the babyspecies thing, but I couldn't quite piece it together. It works perfectly, and is much shorter now.
     
    I'd like to point out that, as it currently stands, you're three times more likely to get a Bulbasaur or Pidgey egg as you are a Farfetch'd or Mawile egg (and 8 times as likely to get an Eevee). It's all due to how many evolutions that family has.
     
    I'd like to point out that, as it currently stands, you're three times more likely to get a Bulbasaur or Pidgey egg as you are a Farfetch'd or Mawile egg (and 8 times as likely to get an Eevee). It's all due to how many evolutions that family has.

    I agree, I think your previous code was better there was nothing long with the length. Remember writing code is about performance, not length... of course shorter is good but if it doesn't perform the way you want its pointless...
     
    I agree, I think your previous code was better there was nothing long with the length. Remember writing code is about performance, not length... of course shorter is good but if it doesn't perform the way you want its pointless...
    I see, thanks for pointing it out guys, I'll revert it now.
     
    if in the whitelist section of the first post could you remove all except certain Pokemon (like the starters or psychic) would the Pokemon that are left be the only ones that it could pick from and would it mess anything else up?
     
    It seems you've been here long enough to know not to revive a thread this old.

    -locked-
     
    Status
    Not open for further replies.
    Back
    Top