• 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?".
  • 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.

Random Egg Generator

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
Code:
#===============================================================================
# * Random Egg Generator - by FL (Credits will be apreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It random generates an egg with all
# possible pokémon that can hatch from an eggs (excluding some species like
# Ditto, Mewtwo and Unown) with same probability.
#
#===============================================================================
#
# To this scripts works, put it above main and use in script command 
# 'randomEggGenerator'. This only gives to player an egg if the player has
# a empty party slot. You can also calls the method with an array with the
# exceptions that cannot be random generated. Example:
# randomEggGenerator(PBSpecies::DRATINI,PBSpecies::LARVITAR) won't generates
# Dratini or Larvitar.
# 
# This script also doesn't generate eggs for pokémon than can incense breed
# like Marill, but generate for pokémon than are incense babies like Azurill. 
# If you wish to enable the both cases in eggs, both counting as different
# pokémon call the script using 'randomEggGenerator([],true)'.
# 
#===============================================================================

def randomEggGenerator(exceptions=[],enableIncenseEvos=false)
  # Phione and Manaphy are always exceptions 
  exceptions+=[PBSpecies::PHIONE,PBSpecies::MANAPHY] 
  if $Trainer.party.length>=6
    Kernel.pbMessage(_INTL(
        "I'm sorry, but it would seem that you can't carry any more Pokemon."))
  else
    species=0
    while(species==0)
      species=rand(PBSpecies.maxValue)+1
      # Redo the loop if the species can't be in an egg, is an exceptions or
      # is an evolution (only if enableIncenseEvos=false)
      species=0 if (!pbHasEgg?(species) || exceptions.include?(species) || 
          (!enableIncenseEvos && pbGetPreviousForm(species)!=species))
    end
    pbGenerateEgg(species)
    Kernel.pbMessage(
        _INTL("{1} received the Egg!\\se[itemlevel]\1",$Trainer.name))
  end
end
 

Nickalooose

--------------------
1,309
Posts
16
Years
  • Seen Dec 28, 2023
Just to say, good script, nice and simple, but for example:

If I were to just want a choice from fire types, would I have to specify all Pokémon except fire types to the exceptions=[] variable?

Or does this script literally choose any of the million Pokémon created except the 2, you say not to?
 

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
You need to specify all Pokémon except fire types to the exceptions=[] variable. You only need to put the first forms, this script always ignores the evolved species

The exceptions=[] variable only removes pokémon possibilities, if them can't be in an egg (like the Mewtwo and the evo Salamance), then them are ignored.

I didn't understand you second question.

If you wish to made a choice between pokémon types, you need some customizations, tell me than I can do for you, is easy for me.
 

Nickalooose

--------------------
1,309
Posts
16
Years
  • Seen Dec 28, 2023
No you did just answer my question, I don't know if you wanted to add a section where you can keep desired types etc. It would be a good idea, like for example you pick up an egg in a volcano, it would be unlikely a Caterpie should hatch, but adding all Pokémon that aren't fire types would take a while and maybe cause 1 or 2 to be missed and randomly hatch a Pokémon you never meant to.
 

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
No you did just answer my question, I don't know if you wanted to add a section where you can keep desired types etc. It would be a good idea, like for example you pick up an egg in a volcano, it would be unlikely a Caterpie should hatch, but adding all Pokémon that aren't fire types would take a while and maybe cause 1 or 2 to be missed and randomly hatch a Pokémon you never meant to.
Use:
Code:
def randomEggGenerator(exceptions=[],enableIncenseEvos=false,type=-1)
  # Phione and Manaphy are always exceptions 
  exceptions+=[PBSpecies::PHIONE,PBSpecies::MANAPHY] 
  if $Trainer.party.length>=6
    Kernel.pbMessage(_INTL(
        "I'm sorry, but it would seem that you can't carry any more Pokemon."))
  else   
    species=0
    dexdata=pbOpenDexData
    while(species==0)
      species=rand(PBSpecies.maxValue)+1
      pbDexDataOffset(dexdata,species,8)
      type1=dexdata.fgetb
      type2=dexdata.fgetb
      # Redo the loop if the species can't be in an egg, is an exceptions or
      # is an evolution (only if enableIncenseEvos=false)
      species=0 if (!pbHasEgg?(species) || exceptions.include?(species) || 
          (!enableIncenseEvos && pbGetPreviousForm(species)!=species) ||
          (type!=-1 && type!=type1 && type!=type2))
    end
    dexdata.close    
    pbGenerateEgg(species)
    Kernel.pbMessage(
        _INTL("{1} received the Egg!\\se[itemlevel]\1",$Trainer.name))
  end
end
Use the command 'randomEggGenerator([],false,PBTypes::FIRE)'

EDIT: Take note that pokémon like Azurill counts as normal type.
 
Last edited:

Nickalooose

--------------------
1,309
Posts
16
Years
  • Seen Dec 28, 2023
Perfect, just trying to make this script have more options and give variety, nice work
 

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
If you use the code in the last post, you can add this at someplace:

Code:
def randomEggBasedOnTypeEntered(helptext)
  typeName = pbEnterText(helptext,0,8)
  typeValidNumber = nil 
  typeAvailable = [:NORMAL,:FIGHTING,:FLYING,:POISON,:GROUND,
      :ROCK,:BUG,:GHOST,:STEEL,:FIRE,:WATER,:GRASS,:ELECTRIC,:PSYCHIC,
      :ICE,:DRAGON,:DARK]
  for typeSymbol in typeAvailable
    type = getID(PBTypes,typeSymbol)
    if PBTypes.getName(type).downcase == typeName.strip.downcase
      typeValidNumber = type 
      break
    end
  end
  if typeValidNumber
    randomEggGenerator([],false,typeValidNumber)
    return true
  end
  return false
end

This code allows the player to type a type. If a valid type is typed, give the player a random egg of that type and return true. Otherside returns false. Call as 'randomEggBasedOnTypeEntered("Type name?")' on a conditional branch.
 
Last edited:

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
FL, as one more of your perfect scripts! Thank you so much for sharing.
Even though I know I can ask too much, I'll risk it, even because the "no" I already have.
I have sprite to all the eggs of pokemon and I would like to leave the sprite first as a generic egg (from their egg scripts by type) and after X,like,1k steps the egg takes the format of the pokemon that will collide. Is possible?
To prevent the player from getting 'soft reset' until he finds what he wants (although it's too annoying to do this, it's crazy that he does, and one of them is me).

Thank you very much for your attention!

EDIT: AND WOOOW! I hachted a Talonflame usin your egg generator by type lol how can config to remove all evolutions form?
 
Last edited:

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
FL, as one more of your perfect scripts! Thank you so much for sharing.
Even though I know I can ask too much, I'll risk it, even because the "no" I already have.
I have sprite to all the eggs of pokemon and I would like to leave the sprite first as a generic egg (from their egg scripts by type) and after X,like,1k steps the egg takes the format of the pokemon that will collide. Is possible?
To prevent the player from getting 'soft reset' until he finds what he wants (although it's too annoying to do this, it's crazy that he does, and one of them is me).
On PSystem_FileUtilities, before the first line 'bitmapFileName = pbResolveBitmap(bitmapFileName)' add 'bitmapFileName = sprintf("Graphics/Battlers/egg") if pokemon.forceDefaultEggSprite?'. On PokeBattle_Pokemon, after line 'alias isEgg? egg?' add:

Code:
  attr_accessor(:eggStepsToShowSprite) 
  def forceDefaultEggSprite?
    return @eggStepsToShowSprite && @eggStepsToShowSprite<@eggsteps
  end

And, in my script, change

Code:
    dexdata.close
    pbGenerateEgg(species)

into

Code:
    pbDexDataOffset(dexdata,species,21)
    eggsteps = dexdata.fgetw
    dexdata.close
    pbGenerateEgg(species)
    egg = $Trainer.party[$Trainer.party.length-1]
    egg.eggStepsToShowSprite = eggsteps-1000
    p egg.eggStepsToShowSprite

AND WOOOW! I hachted a Talonflame usin your egg generator by type lol how can config to remove all evolutions form?
I tested right now correcting a single detail (pbHasEggEx? into pbHasEgg?) and it was blocking evolutions from being generated from this script.
 

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
On PSystem_FileUtilities, before the first line 'bitmapFileName = pbResolveBitmap(bitmapFileName)' add 'bitmapFileName = sprintf("Graphics/Battlers/egg") if pokemon.forceDefaultEggSprite?'. On PokeBattle_Pokemon, after line 'alias isEgg? egg?' add:

Code:
  attr_accessor(:eggStepsToShowSprite) 
  def forceDefaultEggSprite?
    return @eggStepsToShowSprite && @eggStepsToShowSprite<@eggsteps
  end

And, in my script, change

Code:
    dexdata.close
    pbGenerateEgg(species)

into

Code:
    pbDexDataOffset(dexdata,species,21)
    eggsteps = dexdata.fgetw
    dexdata.close
    pbGenerateEgg(species)
    egg = $Trainer.party[$Trainer.party.length-1]
    egg.eggStepsToShowSprite = eggsteps-1000
    p egg.eggStepsToShowSprite

I tested right now correcting a single detail (pbHasEggEx? into pbHasEgg?) and it was blocking evolutions from being generated from this script.

i change to 'pbHasEggEx' and give me a error cuz i dont have that 'pbHasEggEx?' :/
 

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
It's the exact opposite.

Really sorry but i dont get it xD how can i create that 'def'?

i try to create, changin all 'true' to 'false' and not success...
Code:
#===============================================================================
# Returns true if the given species can be legitimately obtained as an egg
#===============================================================================
def pbHasEggEx?(species)
  if species.is_a?(String) || species.is_a?(Symbol)
    species = getID(PBSpecies,species)
  end
  # species may be unbreedable, so check its evolution's compatibilities
  evospecies = pbGetEvolvedFormData(species)
  compatspecies = (evospecies && evospecies[0]) ? evospecies[0][2] : species
  dexdata = pbOpenDexData
  pbDexDataOffset(dexdata,compatspecies,31)
  compat1 = dexdata.fgetb   # Get egg group 1 of this species
  compat2 = dexdata.fgetb   # Get egg group 2 of this species
  dexdata.close
  return false if isConst?(compat1,PBEggGroups,:Ditto) ||
                  isConst?(compat1,PBEggGroups,:Undiscovered) ||
                  isConst?(compat2,PBEggGroups,:Ditto) ||
                  isConst?(compat2,PBEggGroups,:Undiscovered)
  baby = pbGetBabySpecies(species)
  return false if species==baby   # Is a basic species
  baby = pbGetBabySpecies(species,0,0)
  return false if species==baby   # Is an egg species without incense
  return true
end

And unfortanely, when a get that egg always appears this:

What is this?

Sorry for to many question -.-
 

Attachments

  • a.png
    a.png
    19.9 KB · Views: 11
Last edited:

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
Really sorry but i dont get it xD how can i create that 'def'?

i try to create, changin all 'true' to 'false' and not success...
Code:
#===============================================================================
# Returns true if the given species can be legitimately obtained as an egg
#===============================================================================
def pbHasEggEx?(species)
  if species.is_a?(String) || species.is_a?(Symbol)
    species = getID(PBSpecies,species)
  end
  # species may be unbreedable, so check its evolution's compatibilities
  evospecies = pbGetEvolvedFormData(species)
  compatspecies = (evospecies && evospecies[0]) ? evospecies[0][2] : species
  dexdata = pbOpenDexData
  pbDexDataOffset(dexdata,compatspecies,31)
  compat1 = dexdata.fgetb   # Get egg group 1 of this species
  compat2 = dexdata.fgetb   # Get egg group 2 of this species
  dexdata.close
  return false if isConst?(compat1,PBEggGroups,:Ditto) ||
                  isConst?(compat1,PBEggGroups,:Undiscovered) ||
                  isConst?(compat2,PBEggGroups,:Ditto) ||
                  isConst?(compat2,PBEggGroups,:Undiscovered)
  baby = pbGetBabySpecies(species)
  return false if species==baby   # Is a basic species
  baby = pbGetBabySpecies(species,0,0)
  return false if species==baby   # Is an egg species without incense
  return true
end

And unfortanely, when a get that egg always appears this:

What is this?

Sorry for to many question -.-
I changed the ''pbHasEggEx?" into "pbHasEgg?", not the opposite. Try to copy and paste the randomEgg generator code with type parameter from my old post.
 

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
I changed the ''pbHasEggEx?" into "pbHasEgg?", not the opposite. Try to copy and paste the randomEgg generator code with type parameter from my old post.

oh sorry, i undestood.

So, im still get that error number lol

How can i fix it?

Im usin v17.2 and EBS (and installed in a clean essentials version)

EDIT:

Hey FL, i got it! I just ignore 'p egg.eggStepsToShowSprite'. I put '#' and didnt give me that error.

Ty ty for everything! :D

EDIT 2:

And FL, excuse me but how can i merge with your Egg Picture Group?

https://www.pokecommunity.com/showthread.php?t=238503
 

Attachments

  • a.png
    a.png
    26.1 KB · Views: 8
Last edited:

FL

Pokémon Island Creator
2,443
Posts
13
Years
  • Seen Apr 16, 2024
Hey FL, i got it! I just ignore 'p egg.eggStepsToShowSprite'. I put '#' and didnt give me that error.

Ty ty for everything! :D
Oh, I forgot a print in the code.

And FL, excuse me but how can i merge with your Egg Picture Group?

https://www.pokecommunity.com/showthread.php?t=238503
This is a very old script for a very old Essentials Version (2010 =0) and I'm unsure about how you adapted it. Changing "Graphics/Battlers/egg" into EggType.EggPicture(pokemon.species,false) in the code may make Different Egg Types Script work with this "hide egg until 1000 steps" change.
 
Last edited:
Back
Top