The PokéCommunity Forums Fan Games Game Development Scripts, Tutorials & Tools
Essentials Script Random Egg Generator

Scripts, Tutorials & Tools This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old August 25th, 2012 (12:01 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
     
    Join Date: Sep 2010
    Gender: Male
    Posts: 1,769
    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
    __________________
    Reply With Quote
      #2    
    Old August 25th, 2012 (12:50 PM).
    Nickalooose Nickalooose is offline
    --------------------
       
      Join Date: Mar 2008
      Gender: Female
      Posts: 1,309
      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?
      Reply With Quote
        #3    
      Old August 26th, 2012 (4:40 AM).
      FL's Avatar
      FL FL is offline
      Pokémon Island Creator
         
        Join Date: Sep 2010
        Gender: Male
        Posts: 1,769
        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.
        __________________
        Reply With Quote
          #4    
        Old August 26th, 2012 (4:57 AM).
        Nickalooose Nickalooose is offline
        --------------------
           
          Join Date: Mar 2008
          Gender: Female
          Posts: 1,309
          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.
          Reply With Quote
            #5    
          Old August 26th, 2012 (6:40 AM). Edited 4 Weeks Ago by FL.
          FL's Avatar
          FL FL is offline
          Pokémon Island Creator
             
            Join Date: Sep 2010
            Gender: Male
            Posts: 1,769
            Quote:
            Originally Posted by Nickalooose View Post
            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.
            __________________
            Reply With Quote
              #6    
            Old August 27th, 2012 (4:15 AM).
            Nickalooose Nickalooose is offline
            --------------------
               
              Join Date: Mar 2008
              Gender: Female
              Posts: 1,309
              Perfect, just trying to make this script have more options and give variety, nice work
              Reply With Quote
                #7    
              Old May 9th, 2015 (10:57 AM). Edited May 9th, 2015 by FL.
              FL's Avatar
              FL FL is offline
              Pokémon Island Creator
                 
                Join Date: Sep 2010
                Gender: Male
                Posts: 1,769
                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.
                __________________
                Reply With Quote
                  #8    
                Old September 26th, 2018 (2:11 PM). Edited September 26th, 2018 by WolfPP.
                WolfPP's Avatar
                WolfPP WolfPP is online now
                   
                  Join Date: Aug 2018
                  Location: Brazil
                  Gender: Male
                  Nature: Jolly
                  Posts: 150
                  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?
                  Reply With Quote
                    #9    
                  Old 4 Weeks Ago (5:30 AM).
                  FL's Avatar
                  FL FL is offline
                  Pokémon Island Creator
                     
                    Join Date: Sep 2010
                    Gender: Male
                    Posts: 1,769
                    Quote:
                    Originally Posted by WolfPP View Post
                    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
                    Quote:
                    Originally Posted by WolfPP View Post
                    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.
                    __________________
                    Reply With Quote
                      #10    
                    Old 4 Weeks Ago (6:41 AM).
                    WolfPP's Avatar
                    WolfPP WolfPP is online now
                       
                      Join Date: Aug 2018
                      Location: Brazil
                      Gender: Male
                      Nature: Jolly
                      Posts: 150
                      Quote:
                      Originally Posted by FL View Post
                      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?' :/
                      Reply With Quote
                        #11    
                      Old 4 Weeks Ago (7:03 AM).
                      FL's Avatar
                      FL FL is offline
                      Pokémon Island Creator
                         
                        Join Date: Sep 2010
                        Gender: Male
                        Posts: 1,769
                        Quote:
                        Originally Posted by WolfPP View Post
                        i change to 'pbHasEggEx' and give me a error cuz i dont have that 'pbHasEggEx?' :/
                        It's the exact opposite.
                        __________________
                        Reply With Quote
                          #12    
                        Old 4 Weeks Ago (7:43 AM). Edited 4 Weeks Ago by WolfPP.
                        WolfPP's Avatar
                        WolfPP WolfPP is online now
                           
                          Join Date: Aug 2018
                          Location: Brazil
                          Gender: Male
                          Nature: Jolly
                          Posts: 150
                          Quote:
                          Originally Posted by FL View Post
                          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 -.-
                          Attached Images
                          File Type: png a.png‎ (19.9 KB, 4 views) (Save to Dropbox)
                          Reply With Quote
                            #13    
                          Old 4 Weeks Ago (8:29 AM).
                          FL's Avatar
                          FL FL is offline
                          Pokémon Island Creator
                             
                            Join Date: Sep 2010
                            Gender: Male
                            Posts: 1,769
                            Quote:
                            Originally Posted by WolfPP View Post
                            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.
                            __________________
                            Reply With Quote
                              #14    
                            Old 4 Weeks Ago (12:16 PM). Edited 4 Weeks Ago by WolfPP.
                            WolfPP's Avatar
                            WolfPP WolfPP is online now
                               
                              Join Date: Aug 2018
                              Location: Brazil
                              Gender: Male
                              Nature: Jolly
                              Posts: 150
                              Quote:
                              Originally Posted by FL View Post
                              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
                              Attached Images
                              File Type: png a.png‎ (26.1 KB, 3 views) (Save to Dropbox)
                              Reply With Quote
                                #15    
                              Old 3 Weeks Ago (9:38 AM). Edited 3 Weeks Ago by FL.
                              FL's Avatar
                              FL FL is offline
                              Pokémon Island Creator
                                 
                                Join Date: Sep 2010
                                Gender: Male
                                Posts: 1,769
                                Quote:
                                Originally Posted by WolfPP View Post
                                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.

                                Quote:
                                Originally Posted by WolfPP View Post
                                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.
                                __________________
                                Reply With Quote
                                Reply

                                Quick Reply

                                Join the conversation!

                                Create an account to post a reply in this thread, participate in other discussions, and more!

                                Create a PokéCommunity Account
                                Thread Tools

                                Posting Rules
                                You may not post new threads
                                You may not post replies
                                You may not post attachments
                                You may not edit your posts

                                BB code is On
                                Smilies are On
                                [IMG] code is On
                                HTML code is Off

                                Forum Jump


                                All times are GMT -8. The time now is 10:21 PM.