v18 Level Limit (EXP Cap)

This thread pertains to v18 of Pokémon Essentials.

ValiantSoul

Novice
Member
Joined
Sep 12, 2020
Posts
12
Age
26
Hey all,

I was playing Insurgence recently and really liked the Level Cap between Gyms (i.e without a badge, once a Pokemon gets to Lv20 they get 1 exp per encounter; after one badge you can go up to Lv25 etc etc ) and I was wondering how I would go about implementing that in my game? I tried asking around a while ago, but got not concrete responses.

Anyone who can help, I thank you greatly:)
 

Golisopod User

Elite Trainer
Member
Joined
May 11, 2020
Posts
181
Just make the change in the script pbGainExp to not give exp if your Pokemon's level is above the level cap. You can use switches or Variables to increase or decrease the level cap throughout the game.
 

TechSkylander1518

Wiki Dweeb
Member
Joined
Mar 24, 2017
Posts
364
Okay so fair warning my computer's busted so I can't look through scripts or playtest, but one thing that I imagine would work would be to go into the Settings script, and creating a condition that changes the max level for each badge.
Ruby:
if $game_variables[x]==1
       MAXLEVEL=20
    elsif $game_variables[x]==2
       MAXLEVEL=25
and so on, with X being whatever variable you use to determine this.

This would probably also impact the max level for enemy Pokemon, though, and I don't know if that's something you'd want.
 

ValiantSoul

Novice
Member
Joined
Sep 12, 2020
Posts
12
Age
26
Just make the change in the script pbGainExp to not give exp if your Pokemon's level is above the level cap. You can use switches or Variables to increase or decrease the level cap throughout the game.

See, I would, but I'm a hopeless scripter so I'm leaning on the generosity of others in this scenario; genuine thanks for the heads up where to look though.

Okay so fair warning my computer's busted so I can't look through scripts or playtest, but one thing that I imagine would work would be to go into the Settings script, and creating a condition that changes the max level for each badge.
Ruby:
if $game_variables[x]==1
       MAXLEVEL=20
    elsif $game_variables[x]==2
       MAXLEVEL=25
and so on, with X being whatever variable you use to determine this.

This would probably also impact the max level for enemy Pokemon, though, and I don't know if that's something you'd want.

Ah, is there any way to do it without affecting wild Pokemon and/or trainer battles?
 

Scyl

Ironically Unironic Edgelord Extraordinaire
Member
Joined
Apr 4, 2018
Posts
41
If you're going to be checking the same variable to see if it's a specific integer, then I'd recommend that you use a case instead of elsifs for clarity and readability.
 

ValiantSoul

Novice
Member
Joined
Sep 12, 2020
Posts
12
Age
26
Code:
  # Returns the maximum level a Pokémon can attain. If you want to make it vary,
  # here's where you put your formulae. Note that this is also called by the
  # Compiler, which happens before anything (e.g. Game Switches/Variables, the
  # player's data) is loaded, so make sure they exist before using them, and
  # make this method return the most maximum ever level if they don't.
  def self.maxLevel
    return maxLevel=125
    if $game_variables[27]==0
       maxLevel=15
    elsif $game_variables[27]==1
       maxLevel=25
    elsif $game_variables[27]==3
       maxLevel=35
    elsif $game_variables[27]==5
       maxLevel=50
    elsif $game_variables[27]==7
       maxLevel=50
    elsif $game_variables[27]==8
       maxLevel=75
    elsif $game_variables[27]==9
       maxLevel=100
    elsif $game_variables[27]==10
       maxLevel=125
    return MAXIMUM_LEVEL
  end

So I inserted this into PBExperience, and the game booted, but I ran into this error:

Code:
---------------------------
Pokemon Essentials
---------------------------
[Pokémon Essentials version 18]

Exception: NoMethodError

Message: undefined method `pbGetStartExperience' for PBExperience:Module



Backtrace:

PokeBattle_Pokemon:122:in `level='

PokeBattle_Pokemon:916:in `__mf_initialize'

Pokemon_Forms:52:in `initialize'

PokeBattle_Pokemon:934:in `new'

PokeBattle_Pokemon:934:in `pbNewPkmn'

PField_Encounters:407:in `pbGenerateWildPokemon'

PField_Battles:242:in `pbWildBattleCore'

PField_Battles:233:in `each'

PField_Battles:233:in `pbWildBattleCore'

PField_Battles:308:in `pbWildBattle'



This exception was logged in

C:\Users\MSI\Saved Games\Pokemon Essentials\errorlog.txt.

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------

And I'm not sure where to go from here. Can anyone tell me what has gone wrong? Thanks in advance!
 

ValiantSoul

Novice
Member
Joined
Sep 12, 2020
Posts
12
Age
26
I tackled the bug myself a second after posting, figuring I'd added the end in the wrong place, but putting it just after the script I'd added essentially meant it just didn't restrict max level.
 

LightningKillua15

Rookie
Member
Joined
Sep 21, 2020
Posts
8
Hey, so what you can do is use a case statement like Skyl suggested. Instead of altering MAXLEVEL, you can alter maxexp instead based on

maxexp = pbGetExpInternal(MAXLEVEL,growth)

In PBExperience, use CTRL+F to find def PBExperience.pbAddExperience(currexp,expgain,growth)

Replace it with the code below, while altering the parameters as you see fit.

Experience based on badges:
def PBExperience.pbAddExperience(currexp,expgain,growth)
    if growth>=6 || growth<0
      return ArgumentError.new("The growth rate is invalid.")
    end
    exp = currexp+expgain
    case $trainer.numbadges
        when 0
        maxexp = pbGetExpInternal(20,growth)
        when 1
        maxexp = pbGetExpInternal(30,growth)
        when 2
        maxexp = pbGetExpInternal(40,growth)
        when 3
        maxexp = pbGetExpInternal(50,growth)
        when 4
        maxexp = pbGetExpInternal(60,growth)
        when 5
        maxexp = pbGetExpInternal(70,growth)
        when 6
        maxexp = pbGetExpInternal(80,growth)
        when 7
        maxexp = pbGetExpInternal(90,growth)
        when 8
        maxexp = pbGetExpInternal(MAXLEVEL,growth)
    end
    exp = maxexp if exp>maxexp
    return exp
  end
 

LightningKillua15

Rookie
Member
Joined
Sep 21, 2020
Posts
8
Hey bud, I appreciate HUGELY you offering to help; I was banging my head against the wall tryna figure out how to do this haha; I'll wait on your V18 update :)
Happy to help :) I got the badge-based level cap working successfully in v18.

1) Open your scripts, and go to PBExperience

2) Within PBExperience, find line 169. It should say:
Line 169:
def self.pbAddExperience(currexp,expgain,growth)

If not, use CTRL + F to find it within PBExperience

3) Replace the following line:
Original maxexp line:
maxexp = pbGetExpInternal(maxLevel,growth)

with:
New maxexp case:
case $Trainer.numbadges
    when 0
      maxexp = pbGetExpInternal(20,growth)
    when 1
      maxexp = pbGetExpInternal(25,growth)
    when 2
      maxexp = pbGetExpInternal(30,growth)
    else
      maxexp = pbGetExpInternal(maxLevel,growth)
    end
Customize the case statement as you wish :) Note that rare candies still elevate your level past the cap, & this gives 0 exp instead of 1 at the level cap.

Hope this helps
 

DarrylhoBD

Rookie
Member
Joined
Sep 7, 2020
Posts
6
Age
15
Happy to help :) I got the badge-based level cap working successfully in v18.

1) Open your scripts, and go to PBExperience

2) Within PBExperience, find line 169. It should say:
Line 169:
def self.pbAddExperience(currexp,expgain,growth)

If not, use CTRL + F to find it within PBExperience

3) Replace the following line:
Original maxexp line:
maxexp = pbGetExpInternal(maxLevel,growth)

with:
New maxexp case:
case $Trainer.numbadges
    when 0
      maxexp = pbGetExpInternal(20,growth)
    when 1
      maxexp = pbGetExpInternal(25,growth)
    when 2
      maxexp = pbGetExpInternal(30,growth)
    else
      maxexp = pbGetExpInternal(maxLevel,growth)
    end
Customize the case statement as you wish :) Note that rare candies still elevate your level past the cap, & this gives 0 exp instead of 1 at the level cap.

Hope this helps
So just double-checking, "when 0" means if the player has no badges, not if the player have 1 badge right?
 

DarrylhoBD

Rookie
Member
Joined
Sep 7, 2020
Posts
6
Age
15
It actually works really well, however it only works properly with natural means. For Rare Candy, the item can still be used. But for the Exp Candy, it uses the item but doesn't level the pokemon up (therefore pretty much broken).
 

ValiantSoul

Novice
Member
Joined
Sep 12, 2020
Posts
12
Age
26
It actually works really well, however it only works properly with natural means. For Rare Candy, the item can still be used. But for the Exp Candy, it uses the item but doesn't level the pokemon up (therefore pretty much broken).
I figure the simple fix there, is just don't input a Rare Candy into the game in the standard way; I'm planning on changing it's function entirely :)
 
Top