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

[Other Question] Hidden Power type formula

ISNorden

Teddiursa
154
Posts
11
Years
  • I know that Essentials (like the commercial Pokémon games) uses creature IVs to determine the damage type and amount for Hidden Power. I also know that Essentials games (unlike the commercial ones) allow Hidden Power to use any new type included on the list. (If a fan-game allows 20 damage types instead of 18, Hidden Power will also select from 20 types.) What I still can't figure out, though, is how a particular combination of IVs corresponds to a type: six perfect IV scores always equals 70 points of Fairy-type damage (or Dark before Gen 6).

    Is there a formula for determining the maximum IV combination linked to a particular Hidden Power? Let's assume I've added Light and Sound to the list of elemental types in my game, and want to give players a near-perfect Noibat as a Mystery Gift. That Noibat is going to know Hidden Power as a "special-event move", I've decided to guarantee that the Noibat always causes Sound-type damage (at least 60 hp) with Hidden Power, What is the highest set of IVs this Noibat can have without changing its power, and how does the game engine calculate that?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I know that Essentials (like the commercial Pokémon games) uses creature IVs to determine the damage type and amount for Hidden Power. I also know that Essentials games (unlike the commercial ones) allow Hidden Power to use any new type included on the list. (If a fan-game allows 20 damage types instead of 18, Hidden Power will also select from 20 types.) What I still can't figure out, though, is how a particular combination of IVs corresponds to a type: six perfect IV scores always equals 70 points of Fairy-type damage (or Dark before Gen 6).

    Is there a formula for determining the maximum IV combination linked to a particular Hidden Power? Let's assume I've added Light and Sound to the list of elemental types in my game, and want to give players a near-perfect Noibat as a Mystery Gift. That Noibat is going to know Hidden Power as a "special-event move", I've decided to guarantee that the Noibat always causes Sound-type damage (at least 60 hp) with Hidden Power, What is the highest set of IVs this Noibat can have without changing its power, and how does the game engine calculate that?

    Sooooooo.
    This question really is about solving a system of two equations with six unknowns. The way it's encoded make it actually easy, yet a bit tricky.

    • If you want maximal base damage, then the IV should be either 30 or 31. Any other values will give you lower than 70 base power. Not too many details here, I think this result is known.

    • The type is determined by another integer.
      List the stats of the Pokémon in a reverse order: SpDef, SpAtk, Speed, Def, Atk, HP.
      Then, depending on the parity of the IVs, write 0 or 1.
      For example: 31, 30, 30, 31, 31, 30 becomes 1, 0, 0, 1, 1, 0. (Well it just looks like I'm substracting 30, but I'm actually looking at the parity).
      When you take this sequence of 0s and 1s, it represents a 6-bit integer written in binary: 100110, which is 38.
      Then multiply it by the number of types that Hidden Power can take (15 in the base game, 16 in Essentials as it considers the Fairy-type, and 18 for you as you have Fairy + Sound + Light), divide by 64 and round down. This will give you the type.

    • Now, what you want, is the converse. You have a type, and you want the IV combinations that lead to that type. But I said before that the type depends on the new integer defined by the parities of the IVs. Let's call this value A. It's easy to figure out that, if your IVs are 30 or 31, whenever you have A, you can get the IV combination ; conversely, whenever your have the IV combination, you can always deduce A. So actually, you just want to solve the equation in A: floor( A * T / 63) = type, where T is the number of types that Hidden Power can take. The floor function has the property that floor( A * T / 63) = type iff type <= A * T / 63 < type + 1, from which we derive: 63 * type / T <= A < 63 * (type+1) / T.

      So whenever you want a given type, just find the integers A that are between 63 * type / T (included) and 63 * (type+1) / T (not included). Then, write A in binary (it should be a 6-bit integer), and this integer encodes the parities of the IVs of the Pokémon.

      The only exception is with the last type, which can only be obtained with a full odd IV combination: [31, 31, 31, 31, 31, 31]. If you have T types, the T-th type will always have this combination.


    Example. Let's say you have T = 18 types (normal types + Fairy + Sound + Light), and you want type Sound. Sound should be type number 17 in this list. We compute: 63 * Sound / T = 63 * 17 / 18 = 59.5 and 63 * (Sound +1)/ T = 63. So the possible A's should be integers greater or equal to 59.5, and stricly lower than 63. There are only three integers between these two values: the only possible A's are: 60, 61 and 62. These three numbers write in binary: 60 = [111100], 61 = [111101] and 62 = [111110], which give the parities for the IVs, in the order listed above: SpDef, SpAtk, Speed, Def, Atk, HP.
    In conclusion, Sound-type Hidden Power, in a game this 18 types, can be obtained with the following IV combinations: [30, 30, 31, 31, 31, 31], [31, 30, 31, 31, 31, 31] and [30, 31, 31, 31, 31, 31] in the usual Essentials order.
     
    Last edited:

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Thank you, that explains the system pretty well...now I just need to find a base-conversion utility online. :pink_smile:

    Run this code:

    Code:
    def pbGenerateHiddenPowerConversion
      # Generates a table that associates types with IV combination.
      types = []
      for i in 0..PBTypes.maxValue
        next if PBTypes.isPseudoType?(i)
        next if isConst?(i,PBTypes,:NORMAL) || isConst?(i,PBTypes,:SHADOW)
        types.push(i)
      end
      
      File.open("hidden_power.txt", "w") { |f|
        # Header
        f.write("Type".ljust(10))
        f.write("HP".ljust(4))
        f.write("Atk".ljust(4))
        f.write("Def".ljust(4))
        f.write("Spd".ljust(4))
        f.write("SpA".ljust(4))
        f.write("SpD".ljust(4))
        f.write("\n")
        
        for num in 0..63
          iv = Array.new(6,30)
          
          for j in 0..5
            iv[j] += (num >> j) &1 # Note: inverted order:
          end 
          
          type = pbHiddenPower2(iv, types)
          
          f.write(PBTypes.getName(type).ljust(10))
          
          for j in 0..5
            f.write(iv[j].to_s.ljust(4))
          end 
          f.write("\n")
        end
      }
      pbMessage("Written Hidden Power conversion table.")
    end 
    
    
    def pbHiddenPower2(iv, types)
      # NOTE: This allows Hidden Power to be Fairy-type (if you have that type in
      #       your game). I don't care that the official games don't work like that.
      idxType = 0
      idxType |= (iv[PBStats::HP]&1)
      idxType |= (iv[PBStats::ATTACK]&1)<<1
      idxType |= (iv[PBStats::DEFENSE]&1)<<2
      idxType |= (iv[PBStats::SPEED]&1)<<3
      idxType |= (iv[PBStats::SPATK]&1)<<4
      idxType |= (iv[PBStats::SPDEF]&1)<<5
      idxType = (types.length-1)*idxType/63
      return types[idxType]
    end

    PS: Lol about the 26 notifications!
     

    ISNorden

    Teddiursa
    154
    Posts
    11
    Years
  • Oops, must have happened after I dropped my keyboard and kept holding a key when I grabbed the thing, :pink_blush:

    Anyway, thank you for the combo-finder script; where would it go? Is it supposed to run from the Debug menu? (It's been 2-3 years since I tried editing Essentials docs from scratch.)
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Anyway, thank you for the combo-finder script; where would it go? Is it supposed to run from the Debug menu? (It's been 2-3 years since I tried editing Essentials docs from scratch.)

    It would go anywhere you want, but just to be safe, make a new script.
    Also, call the function pbGenerateHiddenPowerConversion from an Event.
     
    Back
    Top