• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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.

[Scripting Question] Wild pokemon have a chance to have egg moves

  • 465
    Posts
    8
    Years
    • Seen Jun 17, 2024
    i felt wild pokemon would/should have a chance to have egg moves as wild pokemon WOULD breed occasionally.

    not sure how to go about this; maybe the chance is calculated somewhat like shiny chance (just a much higher chance like 25-33%)
     
    So, you'll probably want to make a Events.onWildPokemonCreate for this, there's a couple of examples of them in PField_EncounterModifiers.

    and this is how the daycare pulls the eggmoves
    Code:
      if movefather.isMale?
        pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
           f.pos=(egg.fSpecies-1)*8
           offset=f.fgetdw
           length=f.fgetdw
           if length>0
             f.pos=offset
             i=0; loop do break unless i<length
               atk=f.fgetw
               moves.push(atk) if movefather.hasMove?(atk)
               i+=1
             end
           end
        }
      end
      if USENEWBATTLEMECHANICS
        pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
           f.pos=(egg.fSpecies-1)*8
           offset=f.fgetdw
           length=f.fgetdw
           if length>0
             f.pos=offset
             i=0; loop do break unless i<length
               atk=f.fgetw
               moves.push(atk) if movemother.hasMove?(atk)
               i+=1
             end
           end
        }
      end
    you can probably pare it down to just push all the moves and pick a few at random.
    Code:
        moves=[]
        pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
           f.pos=(pokemon.fSpecies-1)*8
           offset=f.fgetdw
           length=f.fgetdw
           if length>0
             f.pos=offset
             i=0; loop do break unless i<length
               atk=f.fgetw
               moves.push(atk)
               i+=1
             end
           end
        }
      nummoveslearned=rand(4)
      for i in 0...nummoveslearned
        pokemon.pbLearnMove(moves[rand(moves.length)])
      end

    But like, I didn't test any of this. So take my code with a grain of salt, i guess.
     
    used your code changing fspecies for babyspecies due to specifications between v16 and v17 and that was issues even when definining it; and changing it to pokemon just causes a crash and has issues with "pbrgssOpen"

    Code:
    Events.onWildPokemonCreate+=proc {|sender,e|
       pokemon=e[0]
       moves=[]
        pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
           f.pos=(pokemon-1)*8
           offset=f.fgetdw
           length=f.fgetdw
           if length>0
             f.pos=offset
             i=0; loop do break unless i<length
               atk=f.fgetw
               moves.push(atk) 
               i+=1
             end
           end
        }
      if $PokemonTemp.pokeradar
        nummoveslearned=rand(1)
        for i in 0...nummoveslearned
          pokemon.pbLearnMove(moves[rand(moves.length)])
        end
      else
        nummoveslearned=rand(4)
        for i in 0...nummoveslearned
          pokemon.pbLearnMove(moves[rand(moves.length)])
        end
      end
     
    The reason it crashes is because babyspecies is not a method on the Pokemon object, and now you try to subtract 1 from the pokemon object, which is undefined behaviour.
    try using babyspecies=pbGetBabySpecies(pokemon.species) and replacing (pokemon-1) with (babyspecies-1)

    I assume this will work, but I don't actually have a copy of v16 to check. So this is the most I can do at the moment.
     
    that seems to work i think it was this or another code working earlier; but either way doing that babyspecies definition seems to fix it. however it seems to be able to generate more than one egg move (i cant recrete it but first testing with a venepede it had pursuit,toxic spikes, spikes and takedown, the last 3 being only egg moves at that level)

    any way to limit it or? may just be super rare to do tho. (then again multiple egg moves is possible via chain breeding but still)
     
    The reason it's got a bunch of egg moves is because of this bit here.
    Code:
      if $PokemonTemp.pokeradar
        nummoveslearned=rand(1)
        for i in 0...nummoveslearned
          pokemon.pbLearnMove(moves[rand(moves.length)])
        end
      else
        nummoveslearned=rand(4)
        for i in 0...nummoveslearned
          pokemon.pbLearnMove(moves[rand(moves.length)])
        end
      end
    Your code basically says, if we are using the pokerader, give no egg moves. Else, give 0 to 3 egg moves.
    Change the numbers on the rand to make it fewer, and maybe even consider surrounding that block with another if like if rand(100)<25 to only have a 25% chance of giving egg moves at all. Or perhaps doing pokemon.pbLearnMove(moves[rand(moves.length)]) if rand(100)<25 to have a 25% chance of giving a specific egg move if it was actually gonna try to give it in the first place.
    This is all trial and error honestly. Play with your usage of random numbers to get the amount you want.
     
    thought the random thing was the move count just had it setup wrong ^^; heres what i have after adding that set to one move only ^^

    Code:
    if $DEBUG
        nummoveslearned=2
        for i in 0...nummoveslearned
          pokemon.pbLearnMove(moves[rand(moves.length)])
        end
      elsif $PokemonTemp.pokeradar
        v=[(655/65536)-($PokemonTemp.pokeradar[2]+1)*200,200].max
        v=0xFFFF / v
        v=rand(65536) / v
        if v==0
          nummoveslearned=2
          for i in 0...nummoveslearned
            pokemon.pbLearnMove(moves[rand(moves.length)])
          end
        end
      else
        if rand(400)==1
          nummoveslearned=2
          for i in 0...nummoveslearned
            pokemon.pbLearnMove(moves[rand(moves.length)])
          end
        end
      end
    added the debug one for testing ^^
     
    When I encounter a Pokemon that has reached at least the 2nd development this error occurs

    This error occurs because Pokemon like Venusaur have no egg moves in normal PBS, I have to add egg moves for all Pokemon from Gen 1 to Gen 8 in PBS?

    Code:
    [Pokémon Essentials version 17.2]
    Exception: NoMethodError
    Message: undefined method `<=' for nil:NilClass
    PokeBattle_Pokemon:496:in `pbLearnMove'
    PField_EncounterModifiers:60
    PField_EncounterModifiers:59:in `each'
    PField_EncounterModifiers:59
    PField_EncounterModifiers:42:in `call'
    EventHandlers:54:in `trigger'
    EventHandlers:49:in `each'
    EventHandlers:49:in `trigger'
    PField_Encounters:377:in `pbGenerateWildPokemon'
    PField_Battles:88:in `pbWildBattle_ebs'
     
    When I encounter a Pokemon that has reached at least the 2nd development this error occurs

    This error occurs because Pokemon like Venusaur have no egg moves in normal PBS, I have to add egg moves for all Pokemon from Gen 1 to Gen 8 in PBS?

    Code:
    [Pokémon Essentials version 17.2]
    Exception: NoMethodError
    Message: undefined method `<=' for nil:NilClass
    PokeBattle_Pokemon:496:in `pbLearnMove'
    PField_EncounterModifiers:60
    PField_EncounterModifiers:59:in `each'
    PField_EncounterModifiers:59
    PField_EncounterModifiers:42:in `call'
    EventHandlers:54:in `trigger'
    EventHandlers:49:in `each'
    EventHandlers:49:in `trigger'
    PField_Encounters:377:in `pbGenerateWildPokemon'
    PField_Battles:88:in `pbWildBattle_ebs'

    weird might be issues between versions (not sure but was made for 16.2) but for mine they use their base form eggmoves or just dont use them. ill take a look thought how far it is different from the code i posted here to my current one.

    edit: i believe i know the issue. i dont think its connected to evolutions but moreso that the base form has no egg moves. i honestly am not sure though, i've not got issues with evolved forms and egg moves myself and only got it with species without any egg moves in the entire line. (essentials seems to know what species comes out of breeding/what is the earliest stage, thus can get egg moves for later versions)
     
    Last edited:
    When I encounter a Pokemon that has reached at least the 2nd development this error occurs

    This error occurs because Pokemon like Venusaur have no egg moves in normal PBS, I have to add egg moves for all Pokemon from Gen 1 to Gen 8 in PBS?

    Code:
    [Pokémon Essentials version 17.2]
    Exception: NoMethodError
    Message: undefined method `<=' for nil:NilClass
    PokeBattle_Pokemon:496:in `pbLearnMove'
    PField_EncounterModifiers:60
    PField_EncounterModifiers:59:in `each'
    PField_EncounterModifiers:59
    PField_EncounterModifiers:42:in `call'
    EventHandlers:54:in `trigger'
    EventHandlers:49:in `each'
    EventHandlers:49:in `trigger'
    PField_Encounters:377:in `pbGenerateWildPokemon'
    PField_Battles:88:in `pbWildBattle_ebs'

    Given the error, pbLearnMove was given nil, clearly. You can either:
    a) gate the pbLearnMove, so that it has to pass the condition moves.length>0
    b) use the baby species of the pokemon species, which in hindsight is what I should have done. But that's 20/20, am i right. replace the calls to pokemon.fSpecies with pbGetBabySpecies(pokemon.species). that should do the trick. sorry :P

    Why, you could probably do both for double the protection.
    this is why you test stuff!
     
    Last edited:
    Given the error, pbLearnMove was given nil, clearly. You can either:
    a) gate the pbLearnMove, so that it has to pass the condition moves.length>0
    b) use the baby species of the pokemon species, which in hindsight is what I should have done. But that's 20/20, am i right. replace the calls to pokemon.fSpecies with pbGetBabySpecies(pokemon.species). that should do the trick. sorry :P

    Why, you could probably do both for double the protection.
    this is why you test stuff!

    Nice fixed thanks (i'm feeling stupid now OO)
     
    Back
    Top