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

[Scripting Question] Aura Crystal Item

HeroesFightingFear

"The Champion of Alon"
99
Posts
4
Years
  • I want to make an item called the Aura Crystal that checks if a Pokemon can evolve, and whether it evolves once or not, fetches the stats and learnset from the final evolution of that Pokemon and assigns them to the Pokemon holding the item.
    I have no clue how to go about this, but here is the item description.
    A crystal radiating a powerful aura. Unevolved Pokemon can supposedly tap into it.
     
    143
    Posts
    4
    Years
    • Seen Mar 26, 2024
    Hey there,
    this should kinda work as you wished. I excluded the Hp stat because I think it would enable weird shenanigans.
    In "def pbInitPokemon(pkmn,idxParty)" add this part right below "@speed = pkmn.speed":
    Code:
    if hasActiveItem?(:YOURITEM)
          stats = pkmn.calcEvolvedFormStats
          @attack = stats[PBStats::ATTACK]
          @defense = stats[PBStats::DEFENSE]
          @spatk = stats[PBStats::SPATK]
          @spdef = stats[PBStats::SPDEF]
          @speed = stats[PBStats::SPEED]
        end
    Do the same in "def pbUpdate(fullChange=false)" with this code:
    Code:
    if hasActiveItem?(:YOURITEM)
            stats = @pokemon.calcEvolvedFormStats
            @attack = stats[PBStats::ATTACK]
            @defense = stats[PBStats::DEFENSE]
            @spatk = stats[PBStats::SPATK]
            @spdef = stats[PBStats::SPDEF]
            @speed = stats[PBStats::SPEED]
          end
    Finally paste this method into the PokeBattle_Pokemon class, preferably above "def clone":
    Code:
    # Recalculates this Pokémon's evolved form's stats.
      def calcEvolvedFormStats
        pkmn = self.species
        evolution = pbGetEvolvedFormData(pkmn)
        loop do break if !evolution[0].is_a?(Array)
          pkmn = evolution[1]
        end
        pkmn = PokeBattle_Pokemon.new(pkmn,1,$Trainer,false)
        bs        = pkmn.baseStats
        usedLevel = self.level
        usedIV    = self.calcIV
        pValues   = PBNatures.getStatChanges(self.calcNature)
        stats = [0]
        PBStats.eachStat do |s|
          next if s==PBStats::HP
          stats[s] = calcStat(bs[s],usedLevel,usedIV[s],@ev[s],pValues[s])
        end
        return stats
      end
    I haven't tested it myself, so be sure to come back on me if you encounter any problems. :)
     
    143
    Posts
    4
    Years
    • Seen Mar 26, 2024
    It did work, sure, but it made any battle I tried lag out.
    Oops, I think the loop carries on forever.THis should fix it
    Code:
    # Recalculates this Pokémon's evolved form's stats.
      def calcEvolvedFormStats
        pkmn = self.species
        [B]loop do break if !pbGetEvolvedFormData(pkmn)[0].is_a?(Array)
          pkmn = pbGetEvolvedFormData(pkmn)[1][/B]
        end
        pkmn = PokeBattle_Pokemon.new(pkmn,1,$Trainer,false)
        bs        = pkmn.baseStats
        usedLevel = self.level
        usedIV    = self.calcIV
        pValues   = PBNatures.getStatChanges(self.calcNature)
        stats = [0]
        PBStats.eachStat do |s|
          next if s==PBStats::HP
          stats[s] = calcStat(bs[s],usedLevel,usedIV[s],@ev[s],pValues[s])
        end
        return stats
      end
     

    HeroesFightingFear

    "The Champion of Alon"
    99
    Posts
    4
    Years
  • This time it straight up throws an error when trying to initiate a battle. The error seems to be related with how the method is structured, as it is causing interference with the evolution scripts.
     
    143
    Posts
    4
    Years
    • Seen Mar 26, 2024
    This time it straight up throws an error when trying to initiate a battle. The error seems to be related with how the method is structured, as it is causing interference with the evolution scripts.
    Could you add the error message? It would help me a lot, fixing this problem. :)
     

    HeroesFightingFear

    "The Champion of Alon"
    99
    Posts
    4
    Years
  • Aura Crystal Item
     
    143
    Posts
    4
    Years
    • Seen Mar 26, 2024
    Figured it out and tested it, should function without errors now. Sorry for the hassle. :)
    Code:
    loop do break if !pbGetEvolvedFormData(pkmn)[0].is_a?(Array)
          pkmn = pbGetEvolvedFormData(pkmn)[0][2]
        end
     
    Back
    Top