• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • It's time to vote for your favorite Pokémon Battle Revolution protagonist in our new weekly protagonist poll! Click here to cast your vote and let us know which PBR protagonist you like most.
  • 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] A few issues with the Hidden Ability Capsule item.

  • 90
    Posts
    7
    Years
    • Seen Nov 24, 2023
    I've tried using this code that I found on this site for an item that gives Pokemon a hidden ability in my game:
    Code:
    ItemHandlers::UseOnPokemon.add(:DREAMCAPSULE,proc{|item,pokemon,scene|
      abil=pokemon.getAbilityList
      dream_abil=[]
      for i in 0...abil[0].length
        dream_abil.push(abil[0][i]) if abil[1][i]>1
      end
      if dream_abil.length >0
        if Kernel.pbConfirmMessage(_INTL("Do you want to change {1}'s ability to {2}?",
          pokemon.name,PBAbilities.getName(dream_abil[0])))
          pokemon.setAbility(2)
          scene.pbDisplay(_INTL("{1}'s ability was changed to {2}!",pokemon.name,PBAbilities.getName(pokemon.ability)))
          pokemon.calcStats
          next true
        else
          next false
        end
      else
        scene.pbDisplay(_INTL("It won't have any effect."))
        next false
      end
    })
    The are 2 problems that I've found with it, though:
    1.There's no way to get the second hidden ability of a Pokemon with this code.
    2.If you try to use this item to revert a Pokemon's ability back to its normal one, the first text will instead display the name of the hidden ability.
    Can anyone try to fix this? For example, have the Dream Capsule change a Pokemon's ability to its hidden one, then use a normal Ability Capsule to change it to its second Hidden Ability. I'm not very good at coding, so I was thinking someone from here might be able to do it.
     
    The first thing is to define how you want this item to work, in my case when you use the item you get the hidden ability but if it already has it, the item has no effect. Then if the pokemon has more than one hidden ability it changes to the next one. To do so, you have to define the item like this:

    Code:
    ItemHandlers::UseOnPokemon.add(:DREAMITEM,proc{|item,pokemon,scene|
      hiddabil=0
      abil=pokemon.getAbilityList
      curabil=pokemon.ability
      curabilind=pokemon.abilityIndex
      for i in 2..5
        hiddabil+=1 if abil[i][0] != 0
      end
      if hiddabil != 0
        if hiddabil == 1 && curabilind != 2
          if Kernel.pbConfirmMessage(_INTL("Do you want to change {1}'s ability from {2} to {3}?",
            pokemon.name,PBAbilities.getName(curabil),PBAbilities.getName(abil[2][0])))
            pokemon.setAbility(2)
            scene.pbDisplay(_INTL("{1}'s ability was changed to {2}!",pokemon.name,PBAbilities.getName(pokemon.ability)))
            pokemon.calcStats
            next true
          else
            next false
          end
        elsif hiddabil > 1
          newabil = curabilind + 1
          newabil = 2 if abil[newabil][0] == 0
            if Kernel.pbConfirmMessage(_INTL("Do you want to change {1}'s ability from {2} to {3}?",
              pokemon.name,PBAbilities.getName(curabil),PBAbilities.getName(abil[newabil][0])))
              pokemon.setAbility(newabil)
              scene.pbDisplay(_INTL("{1}'s ability was changed to {2}!",pokemon.name,PBAbilities.getName(pokemon.ability)))
              pokemon.calcStats
              next true
            else
              next false
            end
        else
          scene.pbDisplay(_INTL("It won't have any effect."))
          next false
        end
      else
        scene.pbDisplay(_INTL("It won't have any effect."))
        next false
      end
    })

    Then, the problem is that getAbilityList doesn't get the hidden abilities from index 2 if in the PBS the pokemon has only one ability, to change this you should go to Pokebattle_Pokemon and change the definition to:

    Code:
      def getAbilityList
        abils=[]; ret=[]
        dexdata=pbOpenDexData
        pbDexDataOffset(dexdata,self.fSpecies,2)
        abils.push(dexdata.fgetw)
        abils.push(dexdata.fgetw)
        pbDexDataOffset(dexdata,self.fSpecies,40)
        abils.push(dexdata.fgetw)
        abils.push(dexdata.fgetw)
        abils.push(dexdata.fgetw)
        abils.push(dexdata.fgetw)
        dexdata.close
        for i in 0...abils.length
          #next if !abils[i] || abils[i]<=0  ##bagtu
          ret.push([abils[i],i])
        end
        return ret
      end

    This will allow you to get 0 in index=1 in case the pokemon has only one ability. The only side effect is that the debug menu will not show the correct abilities, to correct this go to Debug_Pokemon and find this block and change it to:

    Code:
    when "setability"
          cmd = 0
          loop do
            abils = pkmn.getAbilityList
            oldabil = PBAbilities.getName(pkmn.ability)
            commands = []
            for i in abils
              next if i[0]==0  ##bagtu
              commands.push(((i[1]<2) ? "" : "(H) ")+PBAbilities.getName(i[0]))
            end
            commands.push(_INTL("Remove override"))
            msg = [_INTL("Ability {1} is natural.",oldabil),
                   _INTL("Ability {1} is being forced.",oldabil)][pkmn.abilityflag!=nil ? 1 : 0]
            cmd = @scene.pbShowCommands(msg,commands,cmd)
            break if cmd<0
            if cmd>=0 && cmd<abils.length   # Set ability override
              pkmn.setAbility(abils[cmd][1])
            elsif cmd==abils.length   # Remove override
              pkmn.abilityflag = nil
            end
            pbRefreshSingle(pkmnid)
          end

    I hope this works for you. This change also includes in the message the current ability you want to change.
     
    Zerokid made this script sometime back which you can adapt to your game and use it as the Dream Capsule. It gives the player to option to chose the ability you want. Please give him credit if you use this.

    https://www.pokecommunity.com/threads/428241
     
    I hope this works for you. This change also includes in the message the current ability you want to change.

    It works perfectly. Thanks a lot for the help!

    Zerokid made this script sometime back which you can adapt to your game and use it as the Dream Capsule. It gives the player to option to chose the ability you want. Please give him credit if you use this.

    https://www.pokecommunity.com/threads/428241

    Thanks for the suggestion!
     
    Back
    Top