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

Stop gaining exp after reaching a badge-dependent lvl cap

277
Posts
8
Years
    • Seen Aug 29, 2022
    Hi. I want to make that the pokemon remain at lvl 20 until you get the first badge , not gaining exp , I tried my own script but it was a disaster and i couldn't find anything for that.

    Could anybody help me?

    Thanx!!
     
    277
    Posts
    8
    Years
    • Seen Aug 29, 2022
    I got a syntax error but i think i'll leave it like it is, i made inversal rarecandies so it's not bad at all. Thank you for answer!!
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    I'm not so sure why you'd want to make it ">19", just add more conditions or something:
    Code:
    exp=0 if (thispoke.level==20 && $Trainer.badges[0]==false) || (thispoke.level==30 && $Trainer.badges[1]==false) || (thispoke.level==40 && $Trainer.badges[2]==false)
    And so on... But your game, work it how you want.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    If you happened to be level 19 and gained enough Exp to advance multiple levels, you'd gain all of that Exp and become that greater-than-20 level even though the badges say you couldn't. Then thispoke.level==20 would be false, and the Pokemon could continue gaining Exp despite it supposedly not being allowed. It's a very unlikely scenario, but it's still a valid reason to use >19 rather than ==20 (I'd tend to use >=20, actually, because that number is the level cap and thus easier to figure out at a glance).

    Even if you don't jump multiple levels, upon hitting level 20, you'd almost certainly have more than the minimum amount of Exp you need to reach level 20. This would manifest itself as a part-filled Exp bar in the Pokémon's summary screen, which is not desirable. It also means that, once you're allowed to go beyond level 20, you'd already have a head-start, which is also not desirable.

    The better solution here would be to modify def PBExperience.pbAddExperience, as that adjusts how much Exp you gain so that you can't exceed the maximum. Change the value of maxexp in there to whatever it'll be at level 20 for the given growth rate, if you don't have the first badge.

    Rare Candy works differently, and would need to be modified separately. Edit the UseOnPokemon ItemHandler for the Rare Candy item so that it says "It won't have any effect." if the Pokémon is at level 20 and you don't have the first badge (in addition to the other scenarios already there in which it'd say that).
     
    429
    Posts
    4
    Years
  • I know how you feel. I wish this program used a language I partially understood, like GML.

    Anyway has anyone figured out how to make this work yet?
     
    285
    Posts
    5
    Years
    • Seen Oct 1, 2023
    I know how you feel. I wish this program used a language I partially understood, like GML.

    Anyway has anyone figured out how to make this work yet?

    Yes, I've gotten it to work using the code from Pokemon Rejuvenation, which has already implemented this. This is also better than most other implementations of level caps, as it doesn't actually limit the maximum level, so you could still have Pokemon in the game above this cap (like on trainers). All you have to do is add this code directly under "growthrate=thispoke.growthrate" in Pokebattle_Battle:
    Code:
        levelLimits = [20] # Gym Badges Hard Level Cap
        leadersDefeated = pbPlayer.numbadges
        if thispoke.level>=levelLimits[leadersDefeated]
          exp = 0
        elsif thispoke.level<levelLimits[leadersDefeated]
          totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated], growthrate)
          currExpNeeded = totalExpNeeded - thispoke.exp
          if exp > currExpNeeded
            exp = currExpNeeded
          end
        end
    You'll need to change "levelLimits = [20]" to include the level cap for each gym badge (like [20,30,40]) for the first 3. I believe you need to have values for every gym badge in the game, including ones where the cap doesn't increase.

    This won't prevent leveling up through Rare Candy, and if you want to do this, you'd have to go to PItem_ItemEffects, search for "RARECANDY", and replace the code with this:
    Code:
    ItemHandlers::UseOnPokemon.add(:RARECANDY,proc{|item,pokemon,scene|
       levelLimits = [20] # Gym Badges Hard Level Cap
       if pokemon.level>=levelLimits[$Trainer.numbadges] || (pokemon.isShadow? rescue false)
         scene.pbDisplay(_INTL("It won't have any effect."))
         next false
       else
         pbChangeLevel(pokemon,pokemon.level+1,scene)
         scene.pbHardRefresh
         next true
       end
    })
    Once, again remember to change "[20]" so it's the same as with the first part.

    Same thing with EXP Candies, if you have those:
    Code:
    ItemHandlers::UseOnPokemon.add(:EXPCANDYXS,proc{|item,pokemon,scene|
       levelLimits = [20] # Gym Badges Hard Level Cap
       leadersDefeated = $Trainer.numbadges
       if pokemon.level>=levelLimits[leadersDefeated] || (pokemon.isShadow? rescue false)
         scene.pbDisplay(_INTL("It won't have any effect."))
         next false
       else
         experience=100   if isConst?(item,PBItems,:EXPCANDYXS)
         experience=800   if isConst?(item,PBItems,:EXPCANDYS)
         experience=3000  if isConst?(item,PBItems,:EXPCANDYM)
         experience=10000 if isConst?(item,PBItems,:EXPCANDYL)
         experience=30000 if isConst?(item,PBItems,:EXPCANDYXL)
         if pokemon.level<levelLimits[leadersDefeated]
           totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated],pokemon.growthrate)
           currExpNeeded = totalExpNeeded - pokemon.exp
           if experience > currExpNeeded
             experience = currExpNeeded
           end
         end
         newexp=PBExperience.pbAddExperience(pokemon.exp,experience,pokemon.growthrate)
         newlevel=PBExperience.pbGetLevelFromExperience(newexp,pokemon.growthrate)
         curlevel=pokemon.level
         scene.pbDisplay(_INTL("Your Pokémon gained {1} Exp. Points!",experience))
         if newlevel==curlevel
           pokemon.exp=newexp
           pokemon.calcStats
           scene.pbRefresh
         else
           attackdiff=pokemon.attack
           defensediff=pokemon.defense
           speeddiff=pokemon.speed
           spatkdiff=pokemon.spatk
           spdefdiff=pokemon.spdef
           totalhpdiff=pokemon.totalhp
           oldlevel=pokemon.level
           pokemon.level=newlevel
           pokemon.changeHappiness("levelup")
           pokemon.calcStats
           scene.pbRefresh
           Kernel.pbMessage(_INTL("\\se[Pkmn level up]{1} was elevated to Level {2}!",pokemon.name,pokemon.level))
           attackdiff=pokemon.attack-attackdiff
           defensediff=pokemon.defense-defensediff
           speeddiff=pokemon.speed-speeddiff
           spatkdiff=pokemon.spatk-spatkdiff
           spdefdiff=pokemon.spdef-spdefdiff
           totalhpdiff=pokemon.totalhp-totalhpdiff
           pbTopRightWindow(_INTL("Max. HP<r>+{1}\r\nAttack<r>+{2}\r\nDefense<r>+{3}\r\nSp. Atk<r>+{4}\r\nSp. Def<r>+{5}\r\nSpeed<r>+{6}",
              totalhpdiff,attackdiff,defensediff,spatkdiff,spdefdiff,speeddiff))
           pbTopRightWindow(_INTL("Max. HP<r>{1}\r\nAttack<r>{2}\r\nDefense<r>{3}\r\nSp. Atk<r>{4}\r\nSp. Def<r>{5}\r\nSpeed<r>{6}",
              pokemon.totalhp,pokemon.attack,pokemon.defense,pokemon.spatk,pokemon.spdef,pokemon.speed))
           movelist=pokemon.getMoveList
           for i in movelist
             if i[0]>oldlevel && i[0]<=pokemon.level
               pbLearnMove(pokemon,i[1],true)
             end
           end
           newspecies=pbCheckEvolution(pokemon)
           if newspecies>0
             pbFadeOutInWithMusic(99999){
                evo=PokemonEvolutionScene.new
                evo.pbStartScreen(pokemon,newspecies)
                evo.pbEvolution
                evo.pbEndScreen
             }
           end
           pokemon.exp=newexp
           scene.pbRefresh
         end
         next true
       end
    })
     
    136
    Posts
    3
    Years
    • Seen yesterday
    Yes, I've gotten it to work using the code from Pokemon Rejuvenation, which has already implemented this. This is also better than most other implementations of level caps, as it doesn't actually limit the maximum level, so you could still have Pokemon in the game above this cap (like on trainers). All you have to do is add this code directly under "growthrate=thispoke.growthrate" in Pokebattle_Battle:
    Code:
        levelLimits = [20] # Gym Badges Hard Level Cap
        leadersDefeated = pbPlayer.numbadges
        if thispoke.level>=levelLimits[leadersDefeated]
          exp = 0
        elsif thispoke.level<levelLimits[leadersDefeated]
          totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated], growthrate)
          currExpNeeded = totalExpNeeded - thispoke.exp
          if exp > currExpNeeded
            exp = currExpNeeded
          end
        end
    You'll need to change "levelLimits = [20]" to include the level cap for each gym badge (like [20,30,40]) for the first 3. I believe you need to have values for every gym badge in the game, including ones where the cap doesn't increase.

    This won't prevent leveling up through Rare Candy, and if you want to do this, you'd have to go to PItem_ItemEffects, search for "RARECANDY", and replace the code with this:
    Code:
    ItemHandlers::UseOnPokemon.add(:RARECANDY,proc{|item,pokemon,scene|
       levelLimits = [20] # Gym Badges Hard Level Cap
       if pokemon.level>=levelLimits[$Trainer.numbadges] || (pokemon.isShadow? rescue false)
         scene.pbDisplay(_INTL("It won't have any effect."))
         next false
       else
         pbChangeLevel(pokemon,pokemon.level+1,scene)
         scene.pbHardRefresh
         next true
       end
    })
    Once, again remember to change "[20]" so it's the same as with the first part.

    Same thing with EXP Candies, if you have those:
    Code:
    ItemHandlers::UseOnPokemon.add(:EXPCANDYXS,proc{|item,pokemon,scene|
       levelLimits = [20] # Gym Badges Hard Level Cap
       leadersDefeated = $Trainer.numbadges
       if pokemon.level>=levelLimits[leadersDefeated] || (pokemon.isShadow? rescue false)
         scene.pbDisplay(_INTL("It won't have any effect."))
         next false
       else
         experience=100   if isConst?(item,PBItems,:EXPCANDYXS)
         experience=800   if isConst?(item,PBItems,:EXPCANDYS)
         experience=3000  if isConst?(item,PBItems,:EXPCANDYM)
         experience=10000 if isConst?(item,PBItems,:EXPCANDYL)
         experience=30000 if isConst?(item,PBItems,:EXPCANDYXL)
         if pokemon.level<levelLimits[leadersDefeated]
           totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated],pokemon.growthrate)
           currExpNeeded = totalExpNeeded - pokemon.exp
           if experience > currExpNeeded
             experience = currExpNeeded
           end
         end
         newexp=PBExperience.pbAddExperience(pokemon.exp,experience,pokemon.growthrate)
         newlevel=PBExperience.pbGetLevelFromExperience(newexp,pokemon.growthrate)
         curlevel=pokemon.level
         scene.pbDisplay(_INTL("Your Pokémon gained {1} Exp. Points!",experience))
         if newlevel==curlevel
           pokemon.exp=newexp
           pokemon.calcStats
           scene.pbRefresh
         else
           attackdiff=pokemon.attack
           defensediff=pokemon.defense
           speeddiff=pokemon.speed
           spatkdiff=pokemon.spatk
           spdefdiff=pokemon.spdef
           totalhpdiff=pokemon.totalhp
           oldlevel=pokemon.level
           pokemon.level=newlevel
           pokemon.changeHappiness("levelup")
           pokemon.calcStats
           scene.pbRefresh
           Kernel.pbMessage(_INTL("\\se[Pkmn level up]{1} was elevated to Level {2}!",pokemon.name,pokemon.level))
           attackdiff=pokemon.attack-attackdiff
           defensediff=pokemon.defense-defensediff
           speeddiff=pokemon.speed-speeddiff
           spatkdiff=pokemon.spatk-spatkdiff
           spdefdiff=pokemon.spdef-spdefdiff
           totalhpdiff=pokemon.totalhp-totalhpdiff
           pbTopRightWindow(_INTL("Max. HP<r>+{1}\r\nAttack<r>+{2}\r\nDefense<r>+{3}\r\nSp. Atk<r>+{4}\r\nSp. Def<r>+{5}\r\nSpeed<r>+{6}",
              totalhpdiff,attackdiff,defensediff,spatkdiff,spdefdiff,speeddiff))
           pbTopRightWindow(_INTL("Max. HP<r>{1}\r\nAttack<r>{2}\r\nDefense<r>{3}\r\nSp. Atk<r>{4}\r\nSp. Def<r>{5}\r\nSpeed<r>{6}",
              pokemon.totalhp,pokemon.attack,pokemon.defense,pokemon.spatk,pokemon.spdef,pokemon.speed))
           movelist=pokemon.getMoveList
           for i in movelist
             if i[0]>oldlevel && i[0]<=pokemon.level
               pbLearnMove(pokemon,i[1],true)
             end
           end
           newspecies=pbCheckEvolution(pokemon)
           if newspecies>0
             pbFadeOutInWithMusic(99999){
                evo=PokemonEvolutionScene.new
                evo.pbStartScreen(pokemon,newspecies)
                evo.pbEvolution
                evo.pbEndScreen
             }
           end
           pokemon.exp=newexp
           scene.pbRefresh
         end
         next true
       end
    })

    this worked very well thank you!
     
    6
    Posts
    3
    Years
    • Seen Feb 17, 2021
    Yes, I've gotten it to work using the code from Pokemon Rejuvenation, which has already implemented this. This is also better than most other implementations of level caps, as it doesn't actually limit the maximum level, so you could still have Pokemon in the game above this cap (like on trainers). All you have to do is add this code directly under "growthrate=thispoke.growthrate" in Pokebattle_Battle:
    Code:
        levelLimits = [20] # Gym Badges Hard Level Cap
        leadersDefeated = pbPlayer.numbadges
        if thispoke.level>=levelLimits[leadersDefeated]
          exp = 0
        elsif thispoke.level<levelLimits[leadersDefeated]
          totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated], growthrate)
          currExpNeeded = totalExpNeeded - thispoke.exp
          if exp > currExpNeeded
            exp = currExpNeeded
          end
        end
    You'll need to change "levelLimits = [20]" to include the level cap for each gym badge (like [20,30,40]) for the first 3. I believe you need to have values for every gym badge in the game, including ones where the cap doesn't increase.
    [/code]

    I have been trying to get this working in Essentials v18.1. I have been struggling along with trying to get it to work and I'm so close but I have absolutely no idea how to fix this current problem.

    Code:
     pkmn = pbParty(0)[idxParty]   # The Pokémon gaining EVs from defeatedBattler
        growthRate = pkmn.growthrate
        
        levelLimits = [20,30,40,50,60,70,80,90] # Gym Badges Hard Level Cap
        leadersDefeated = pbPlayer.numbadges
        if pkmn.level>=levelLimits[leadersDefeated]
          exp = 0
        elsif pkmn.level<levelLimits[leadersDefeated]
          totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated], growthRate)
          currExpNeeded = totalExpNeeded - pkmn.exp
          if exp > currExpNeeded
            exp = currExpNeeded
          end
        end

    This is the current code in the script, and this is the error I get:

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 18.1]

    Exception: NoMethodError

    Message: undefined method `>' for nil:NilClass



    Backtrace:

    Battle_ExpAndMoveLearning:102:in `pbGainExpOne'

    Battle_ExpAndMoveLearning:40:in `pbGainExp'

    Battle_ExpAndMoveLearning:36:in `eachInTeam'

    PokeBattle_Battle:388:in `each_with_index'

    PokeBattle_Battle:388:in `each'

    PokeBattle_Battle:388:in `each_with_index'

    PokeBattle_Battle:388:in `eachInTeam'

    Battle_ExpAndMoveLearning:36:in `pbGainExp'

    Battle_ExpAndMoveLearning:13:in `each'

    Battle_ExpAndMoveLearning:13:in `pbGainExp'

    If anyone could help out at all, please let me know what I can do to fix this.
     
    143
    Posts
    4
    Years
    • Seen Mar 26, 2024
    If your line number 102 looks like this:
    Code:
    exp > currExpNeeded
    then you placed the code at the wrong location. But that isn't a problem, just cut it out and paste it at the following place. :)
    Code:
    # Modify Exp gain based on pkmn's held item
        i = BattleHandlers.triggerExpGainModifierItem(pkmn.item,pkmn,exp)
        if i<0
          i = BattleHandlers.triggerExpGainModifierItem(@initialItems[0][idxParty],pkmn,exp)
        end
        exp = i if i>=0
    [COLOR="Red"]# Paste it here[/COLOR]
    # Make sure Exp doesn't exceed the maximum
        expFinal = PBExperience.pbAddExperience(pkmn.exp,exp,growthRate)
        expGained = expFinal-pkmn.exp
        return if expGained<=0
     
    6
    Posts
    3
    Years
    • Seen Feb 17, 2021
    If your line number 102 looks like this:
    Code:
    exp > currExpNeeded
    then you placed the code at the wrong location. But that isn't a problem, just cut it out and paste it at the following place. :)
    Code:
    # Modify Exp gain based on pkmn's held item
        i = BattleHandlers.triggerExpGainModifierItem(pkmn.item,pkmn,exp)
        if i<0
          i = BattleHandlers.triggerExpGainModifierItem(@initialItems[0][idxParty],pkmn,exp)
        end
        exp = i if i>=0
    [COLOR="Red"]# Paste it here[/COLOR]
    # Make sure Exp doesn't exceed the maximum
        expFinal = PBExperience.pbAddExperience(pkmn.exp,exp,growthRate)
        expGained = expFinal-pkmn.exp
        return if expGained<=0

    That worked! Thank you~
     
    47
    Posts
    4
    Years
    • Seen Nov 22, 2023
    Not seeing PokeBattle_battle in V18. Where would I put it instead? (also used control+alt+f and couldn't find the desired content)
     
    Back
    Top