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

[Essentials v17] Advanced Level Balacing + Evolution

This script doesn't seem to be working for v.18.1 anymore. I've been using it in another project of mine that were using v.17. Are there any plans on updating this script to work for v18.1?
Code:
newlevel=PBExperience::MAXLEVEL if newlevel>PBExperience::MAXLEVEL
This part in particular seem to crash with the new version of essentials. MAXIMUMLEVEL can be changed to MAXIMUM_LEVEL, but can't get it to work with that line.
 
This script doesn't seem to be working for v.18.1 anymore. I've been using it in another project of mine that were using v.17. Are there any plans on updating this script to work for v18.1?
Code:
newlevel=PBExperience::MAXLEVEL if newlevel>PBExperience::MAXLEVEL
This part in particular seem to crash with the new version of essentials. MAXIMUMLEVEL can be changed to MAXIMUM_LEVEL, but can't get it to work with that line.

Try changing the two PBExperience::MAXLEVEL to PBExperience.MAXLEVEL if you are in v18.x
 
Thanks now I got it to work for v18! :D And for everyone else that just want to copy+paste. I take no credit as I just changed a few wordings here and there. It's essential the same script but works for Essentials v18.

Spoiler:
Haven't tested the trainer battle portion though, as I just wanted it for scaling wild pokémon(that also evolves if it hits the required level threshold).
 
I know this is necro-ing, but what do I need to change to make this work with v19.1?

For Pokemon Essentials v19.1, Joltiks' Advanced Pokemon Level Balancing might be changed to:
Code:
################################################################################
# Advanced Pokemon Level Balancing
# By Joltik
#Inspired by Umbreon's code
################################################################################
################################################################################


module LevelBalance
  
  Light = 10                 #from 1 to 10
  Easy = 20                  #from 11 to 20
  Medium = 30                #from 21 to 30
  Hard = 40                  #from 31 to 40
  Insane = 55                #from 41 to 55
  Extreme = Settings::MAXIMUM_LEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100               #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that controls trainer battle's difficulty
  
  # Calculates the difficulty based on your party pokemon's level and badges
  def self.calcDifficulty
    lv=[Light,Easy,Medium,Hard,Insane,Extreme]
    badges = $Trainer.numbadges
    balance = pbBalancedLevel($Trainer.party)
    mlv=0
    for poke in $Trainer.pokemonParty
      mlv=poke.level if poke.level>mlv
    end
    average = (badges*30+3*balance+4*mlv)/10
      for i in 0...lv.length
        if average <= lv[i]
          break
        end
      end
    return i
  end
end

Events.onWildPokemonCreate+=proc {|sender,e|
  pokemon=e[0]
  difficulty= LevelBalance::calcDifficulty
  badges = $Trainer.numbadges
  balance = pbBalancedLevel($Trainer.party)
  mlv=0
  for poke in $Trainer.pokemonParty
    mlv=poke.level if poke.level>mlv
  end
  case difficulty
    when 0 #Light
      l = balance/3 - 2 + rand(5)
    when 1 #Easy
      l = 2*balance/3  - 4 + rand(8)
    when 2 #Medium
      l = 3*(balance + 4*mlv)/20 - 4 + rand(8)
    when 3 #Hard
      l = 4*(balance + 4*mlv)/25 - 2 + rand(8)
    when 4 #Insane
      l = (balance + 4*mlv)/6 - 4 + rand(4+balance/10)
    else #Extreme
      l = 9*(balance + 4*mlv)/50 - 4 + rand(4+balance/10)
  end
  newlevel=l
  newlevel=1 if newlevel<1
  newlevel=GameData::GrowthRate.max_level if newlevel>GameData::GrowthRate.max_level
  pokemon.level=newlevel
  #now we evolve the pokémon, if applicable
  species = pokemon.species
  newspecies = pbGetBabySpecies(species) # revert to the first evolution
  evoflag=0 #used to track multiple evos not done by lvl
  endevo=false
  loop do #beginning of loop to evolve species
    nl = newlevel + 5
    nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
    pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
    cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
    evo = pbGetEvolvedFormData(newspecies)
    if evo
      evo = evo[rand(evo.length - 1)]
      # here we evolve things that don't evolve through level
      # that's what we check with evo[0]!=4
      #notice that such species have cevo==-1 and wouldn't pass the last check
      #to avoid it we set evoflag to 1 (with some randomness) so that
      #pokemon may have its second evolution (Raichu, for example)
      if evo && !cevo && rand(50) <= newlevel # if evo && cevo < 1 && rand(50) <= newlevel
        if evo[0] != 4 && rand(50) <= newlevel
          newspecies = evo[2] 
          if evoflag == 0 && rand(50) <= newlevel 
            evoflag=1
          else
            evoflag=0
          end
        end
      else
        endevo=true   
      end
    end
    if evoflag==0 || endevo
      if  !cevo || rand(50) > newlevel # if  cevo  == -1 || rand(50) > newlevel
        # Breaks if there no more evolutions or randomnly
        # Randomness applies only if the level is under 50 
        break
      else
        newspecies = evo[2]
      end
    end
  end
  #fixing some things such as Bellossom would turn into Vileplume
  #check if original species could evolve (Bellosom couldn't)
  couldevo=pbGetEvolvedFormData(species)
  #check if current species can evolve
  evo = pbGetEvolvedFormData(newspecies)
  if evo.length<1 && couldevo.length<1
  else
    species=newspecies
  end
  pokemon.name=GameData::Species.get(species).species.name # pokemon.name=PBSpecies.getName(species)
  pokemon.species=species
  pokemon.calcStats
  pokemon.resetMoves
}
     
Events.onTrainerPartyLoad+=proc {|sender,e|
  if e # if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0] # trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=trainer.items # items=trainer.items   # An array of the trainer's items they can use
    party=trainer.party # party=e[0].party # An array of the trainer's Pokémon

    if $game_switches && $game_switches[LevelBalance::Switch] && $Trainer && $Trainer.party.length > 0
      badges = $Trainer.numbadges
      balance = pbBalancedLevel($Trainer.party)
      mlv=0
      for poke in $Trainer.pokemonParty
        mlv=poke.level if poke.level>mlv
      end
      for i in 0...party.length
        #sets difficulty based on variable
        case $game_variables[LevelBalance::Trainer_dif]
          when 0 #Light
            l = balance/2 - 2 + rand(5)
          when 1 #Easy
            l = 3*balance/4  - 4 + rand(8)
          when 2 #Medium
            l = 9*(balance + 4*mlv)/50 - 4 + rand(4 + balance/10)
          when 3 #Hard
            l = 11*(balance + 4*mlv)/50  - 4 + rand(4 + balance/10)
          when 4 #Insane
            l = 5*(balance + 4*mlv)/20 - 4 + rand(4+balance/10)
          else #Extreme
            l = 7*(balance + 4*mlv)/25 - 4+ rand(4+balance/10)
        end
        level = l  
        level=1 if level<1
        level=GameData::GrowthRate.max_level if level>GameData::GrowthRate.max_level
        party[i].level = level
        #now we evolve the pokémon, if applicable
        species = party[i].species
        newspecies = pbGetBabySpecies(species) # revert to the first evolution
        evoflag=0 #used to track multiple evos not done by lvl
        endevo=false      
        loop do #beginning of loop to evolve species
          nl = level + 5
          nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
          pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
          cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
          evo = pbGetEvolvedFormData(newspecies)
          if evo
            evo = evo[rand(evo.length - 1)]
            # here we evolve things that don't evolve through level
            # that's what we check with evo[0]!=4
            #notice that such species have cevo==-1 and wouldn't pass the last check
            #to avoid it we set evoflag to 1 (with some randomness) so that
            #pokemon may have its second evolution (Raichu, for example)
            if evo && !cevo && rand(50) <= level # if evo && cevo < 1 && rand(50) <= level
              if evo[0] != 4 && rand(50) <= level
                newspecies = evo[2] 
                if evoflag == 0 && rand(50) <= level 
                  evoflag=1
                else
                  evoflag=0
                end
              end
            else
              endevo=true   
            end
          end
          if evoflag==0 || endevo
            if  !cevo || rand(50) > level # if  cevo  == -1 || rand(50) > level
              # Breaks if there no more evolutions or randomnly
              # Randomness applies only if the level is under 50 
              break
            else
              newspecies = evo[2]
            end
          end
        end #end of loop do
        #fixing some things such as Bellossom would turn into Vileplume
        #check if original species could evolve (Bellosom couldn't)
        couldevo=pbGetEvolvedFormData(species)
        #check if current species can evolve
        evo = pbGetEvolvedFormData(newspecies)
        if evo.length<1 && couldevo.length<1
        else
          species=newspecies
        end #end of evolving script
        party[i].name=GameData::Species.get(species).species.name # party[i].name=PBSpecies.getName(species)
        party[i].species=species
        party[i].calcStats
        party[i].resetMoves
      end #end of for
    end
  end
}
 
Last edited:
For Pokemon Essentials v19.1, Joltiks' Advanced Pokemon Level Balancing might be changed to:
Code:
################################################################################
# Advanced Pokemon Level Balancing
# By Joltik
#Inspired by Umbreon's code
################################################################################
################################################################################


module LevelBalance
  
  Light = 10                 #from 1 to 10
  Easy = 20                  #from 11 to 20
  Medium = 30                #from 21 to 30
  Hard = 40                  #from 31 to 40
  Insane = 55                #from 41 to 55
  Extreme = Settings::MAXIMUM_LEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100               #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that controls trainer battle's difficulty
  
  # Calculates the difficulty based on your party pokemon's level and badges
  def self.calcDifficulty
    lv=[Light,Easy,Medium,Hard,Insane,Extreme]
    badges = $Trainer.numbadges
    balance = pbBalancedLevel($Trainer.party)
    mlv=0
    for poke in $Trainer.pokemonParty
      mlv=poke.level if poke.level>mlv
    end
    average = (badges*30+3*balance+4*mlv)/10
      for i in 0...lv.length
        if average <= lv[i]
          break
        end
      end
    return i
  end
end

Events.onWildPokemonCreate+=proc {|sender,e|
  pokemon=e[0]
  difficulty= LevelBalance::calcDifficulty
  badges = $Trainer.numbadges
  balance = pbBalancedLevel($Trainer.party)
  mlv=0
  for poke in $Trainer.pokemonParty
    mlv=poke.level if poke.level>mlv
  end
  case difficulty
    when 0 #Light
      l = balance/3 - 2 + rand(5)
    when 1 #Easy
      l = 2*balance/3  - 4 + rand(8)
    when 2 #Medium
      l = 3*(balance + 4*mlv)/20 - 4 + rand(8)
    when 3 #Hard
      l = 4*(balance + 4*mlv)/25 - 2 + rand(8)
    when 4 #Insane
      l = (balance + 4*mlv)/6 - 4 + rand(4+balance/10)
    else #Extreme
      l = 9*(balance + 4*mlv)/50 - 4 + rand(4+balance/10)
  end
  newlevel=l
  newlevel=1 if newlevel<1
  newlevel=GameData::GrowthRate.max_level if newlevel>GameData::GrowthRate.max_level
  pokemon.level=newlevel
  #now we evolve the pokémon, if applicable
  species = pokemon.species
  newspecies = pbGetBabySpecies(species) # revert to the first evolution
  evoflag=0 #used to track multiple evos not done by lvl
  endevo=false
  loop do #beginning of loop to evolve species
    nl = newlevel + 5
    nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
    pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
    cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
    evo = pbGetEvolvedFormData(newspecies)
    if evo
      evo = evo[rand(evo.length - 1)]
      # here we evolve things that don't evolve through level
      # that's what we check with evo[0]!=4
      #notice that such species have cevo==-1 and wouldn't pass the last check
      #to avoid it we set evoflag to 1 (with some randomness) so that
      #pokemon may have its second evolution (Raichu, for example)
      if evo && !cevo && rand(50) <= newlevel # if evo && cevo < 1 && rand(50) <= newlevel
        if evo[0] != 4 && rand(50) <= newlevel
          newspecies = evo[2] 
          if evoflag == 0 && rand(50) <= newlevel 
            evoflag=1
          else
            evoflag=0
          end
        end
      else
        endevo=true   
      end
    end
    if evoflag==0 || endevo
      if  !cevo || rand(50) > newlevel # if  cevo  == -1 || rand(50) > newlevel
        # Breaks if there no more evolutions or randomnly
        # Randomness applies only if the level is under 50 
        break
      else
        newspecies = evo[2]
      end
    end
  end
  #fixing some things such as Bellossom would turn into Vileplume
  #check if original species could evolve (Bellosom couldn't)
  couldevo=pbGetEvolvedFormData(species)
  #check if current species can evolve
  evo = pbGetEvolvedFormData(newspecies)
  if evo.length<1 && couldevo.length<1
  else
    species=newspecies
  end
  pokemon.name=GameData::Species.get(species).species.name # pokemon.name=PBSpecies.getName(species)
  pokemon.species=species
  pokemon.calcStats
  pokemon.resetMoves
}
     
Events.onTrainerPartyLoad+=proc {|sender,e|
  if e # if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0] # trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=e[1] # items=e[0][1]   # An array of the trainer's items they can use
    party=e[2] # party=e[0][2] # An array of the trainer's Pokémon

    if $game_switches && $game_switches[LevelBalance::Switch] && $Trainer && $Trainer.party.length > 0
      badges = $Trainer.numbadges
      balance = pbBalancedLevel($Trainer.party)
      mlv=0
      for poke in $Trainer.pokemonParty
        mlv=poke.level if poke.level>mlv
      end
      for i in 0...party.length
        #sets difficulty based on variable
        case $game_variables[LevelBalance::Trainer_dif]
          when 0 #Light
            l = balance/2 - 2 + rand(5)
          when 1 #Easy
            l = 3*balance/4  - 4 + rand(8)
          when 2 #Medium
            l = 9*(balance + 4*mlv)/50 - 4 + rand(4 + balance/10)
          when 3 #Hard
            l = 11*(balance + 4*mlv)/50  - 4 + rand(4 + balance/10)
          when 4 #Insane
            l = 5*(balance + 4*mlv)/20 - 4 + rand(4+balance/10)
          else #Extreme
            l = 7*(balance + 4*mlv)/25 - 4+ rand(4+balance/10)
        end
        level = l  
        level=1 if level<1
        level=GameData::GrowthRate.max_level if level>GameData::GrowthRate.max_level
        party[i].level = level
        #now we evolve the pokémon, if applicable
        species = party[i].species
        newspecies = pbGetBabySpecies(species) # revert to the first evolution
        evoflag=0 #used to track multiple evos not done by lvl
        endevo=false      
        loop do #beginning of loop to evolve species
          nl = level + 5
          nl = MAXIMUM_LEVEL if nl > MAXIMUM_LEVEL
          pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
          cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
          evo = pbGetEvolvedFormData(newspecies)
          if evo
            evo = evo[rand(evo.length - 1)]
            # here we evolve things that don't evolve through level
            # that's what we check with evo[0]!=4
            #notice that such species have cevo==-1 and wouldn't pass the last check
            #to avoid it we set evoflag to 1 (with some randomness) so that
            #pokemon may have its second evolution (Raichu, for example)
            if evo && !cevo && rand(50) <= level # if evo && cevo < 1 && rand(50) <= level
              if evo[0] != 4 && rand(50) <= level
                newspecies = evo[2] 
                if evoflag == 0 && rand(50) <= level 
                  evoflag=1
                else
                  evoflag=0
                end
              end
            else
              endevo=true   
            end
          end
          if evoflag==0 || endevo
            if  !cevo || rand(50) > level # if  cevo  == -1 || rand(50) > level
              # Breaks if there no more evolutions or randomnly
              # Randomness applies only if the level is under 50 
              break
            else
              newspecies = evo[2]
            end
          end
        end #end of loop do
        #fixing some things such as Bellossom would turn into Vileplume
        #check if original species could evolve (Bellosom couldn't)
        couldevo=pbGetEvolvedFormData(species)
        #check if current species can evolve
        evo = pbGetEvolvedFormData(newspecies)
        if evo.length<1 && couldevo.length<1
        else
          species=newspecies
        end #end of evolving script
        party[i].name=GameData::Species.get(species).species.name # party[i].name=PBSpecies.getName(species)
        party[i].species=species
        party[i].calcStats
        party[i].resetMoves
      end #end of for
    end
  end
}

Excellent! Now the only question I have is how do I change the pokemon that appear? The only pokemon that appears at level 100 is Pidgeot
 
I know how to do that, as I've already set some encounters. The Pidgeot that appears at level 100 isn't a pokemon that I put in. So far I have Pidgey, Taillow and Lillipup on Route 1

And now I get this error when trying to heal my Pokemon

[Pokémon Essentials version 19.1]

Exception: RuntimeError
Message: Script error in event 1 (coords 7,2), map 82 (Pokémon Center):
Exception: NoMethodError
Message: undefined method `pokemon_count' for nil:NilClass

***Full script:
count = $player.pokemon_count
for i in 1..count
pbSet(6, i)
pbSEPlay("Battle ball shake")
pbWait(16)
end


Backtrace:
(eval):1:in `execute_script'
033:Interpreter:137:in `eval'
033:Interpreter:137:in `execute_script'
034:Interpreter_Commands:1024:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'


Backtrace:
033:Interpreter:189:in `rescue in execute_script'
033:Interpreter:135:in `execute_script'
034:Interpreter_Commands:1024:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'
032:Scene_Map:155:in `update'
 
And now I get this error when trying to heal my Pokemon

[Pokémon Essentials version 19.1]

Exception: RuntimeError
Message: Script error in event 1 (coords 7,2), map 82 (Pokémon Center):
Exception: NoMethodError
Message: undefined method `pokemon_count' for nil:NilClass

***Full script:
count = $player.pokemon_count
for i in 1..count
pbSet(6, i)
pbSEPlay("Battle ball shake")
pbWait(16)
end


Backtrace:
(eval):1:in `execute_script'
033:Interpreter:137:in `eval'
033:Interpreter:137:in `execute_script'
034:Interpreter_Commands:1024:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'


Backtrace:
033:Interpreter:189:in `rescue in execute_script'
033:Interpreter:135:in `execute_script'
034:Interpreter_Commands:1024:in `command_355'
034:Interpreter_Commands:116:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'
032:Scene_Map:155:in `update'

Your code in your nurse healing event seems to be outdated.
The script should be
Code:
count = $Trainer.pokemon_count
for i in 1..count
  pbSet(6, i)
  pbSEPlay("Battle ball shake")
  pbWait(16)
end
but it is
Code:
count = $player.pokemon_count
for i in 1..count
  pbSet(6, i)
  pbSEPlay("Battle ball shake")
  pbWait(16)
end
in your event. Maybe, this is old code from previous Pokemon Essentials versions or from Pokemon Essentials v20, but not from Pokemon Essentials v19.1. Do you really use Pokemon Essentials v19.1? Or what have you done to have such a Pokemon Essentials mix.

By the way, this is not the right thread to ask for help concerning your pokemon healing event. This thread is about the Advanced Pokemon Level Balance + Evolution Script.
 
Last edited:
I know how to do that, as I've already set some encounters. The Pidgeot that appears at level 100 isn't a pokemon that I put in. So far I have Pidgey, Taillow and Lillipup on Route 1

I tested it myself on Route 1 with Pidgey and Rattata, and I get Pidgey, Rattata and its evolved forms, as it should be with this Advanced Level Balancing and Evolution Script.

Since you have placed Pidgey, Taillow and Lillipup on Route 1, you will get all these pokemon plus its evolved forms on Route 1. Maybe some of them have with a lower encountering chance, and you have to test it just a little bit longer to get encounters with a level depending on the level of the player's party pokemon other than Pigeots.

Or you have to be more precise, what your settings are, what you expect to happen and what really happens, so we can understand what your problem is.
 
I get this error when attempting to battle a trainer. What do I need to fix? The script DOES work, but only when battling wild Pokémon. What's happening is that when I turn on the switch to turn on Trainer Difficulty Control, that's when I get the error. If the switch is off however, I can fight the trainer as usual.

[Pokémon Essentials version 19.1]

Exception: RuntimeError
Message: Script error in event 1 (coords 17,32), map 3 (Route 1 - Springwood Way):
Exception: NoMethodError
Message: undefined method `length' for nil:NilClass

***Full script:
pbTrainerBattle(:YOUNGSTER, "Ben")

Backtrace:
371:Advanced Pokemon Level Balancing:135:in `block in <main>'
035:Event_Handlers:53:in `block in trigger'
035:Event_Handlers:48:in `each'
035:Event_Handlers:48:in `trigger'
229:Overworld_BattleStarting:474:in `pbTrainerBattle'
(eval):1:in `execute_script'
033:Interpreter:137:in `eval'
033:Interpreter:137:in `execute_script'
034:Interpreter_Commands:352:in `command_111'
034:Interpreter_Commands:29:in `execute_command'


Backtrace:
033:Interpreter:189:in `rescue in execute_script'
033:Interpreter:135:in `execute_script'
034:Interpreter_Commands:352:in `command_111'
034:Interpreter_Commands:29:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'
032:Scene_Map:155:in `update'
 
Last edited:
I get this error when attempting to battle a trainer. What do I need to fix? The script DOES work, but only when battling wild Pokémon. What's happening is that when I turn on the switch to turn on Trainer Difficulty Control, that's when I get the error. If the switch is off however, I can fight the trainer as usual.

[Pokémon Essentials version 19.1]

Exception: RuntimeError
Message: Script error in event 1 (coords 17,32), map 3 (Route 1 - Springwood Way):
Exception: NoMethodError
Message: undefined method `length' for nil:NilClass

***Full script:
pbTrainerBattle(:YOUNGSTER, "Ben")

Backtrace:
371:Advanced Pokemon Level Balancing:135:in `block in <main>'
035:Event_Handlers:53:in `block in trigger'
035:Event_Handlers:48:in `each'
035:Event_Handlers:48:in `trigger'
229:Overworld_BattleStarting:474:in `pbTrainerBattle'
(eval):1:in `execute_script'
033:Interpreter:137:in `eval'
033:Interpreter:137:in `execute_script'
034:Interpreter_Commands:352:in `command_111'
034:Interpreter_Commands:29:in `execute_command'


Backtrace:
033:Interpreter:189:in `rescue in execute_script'
033:Interpreter:135:in `execute_script'
034:Interpreter_Commands:352:in `command_111'
034:Interpreter_Commands:29:in `execute_command'
033:Interpreter:127:in `block in update'
033:Interpreter:87:in `loop'
033:Interpreter:87:in `update'
032:Scene_Map:157:in `block in update'
032:Scene_Map:155:in `loop'
032:Scene_Map:155:in `update'

Thank you for reporting your error. Please use this code
Code:
################################################################################
# Advanced Pokemon Level Balancing
# By Joltik
#Inspired by Umbreon's code
################################################################################
################################################################################


module LevelBalance
  
  Light = 10                 #from 1 to 10
  Easy = 20                  #from 11 to 20
  Medium = 30                #from 21 to 30
  Hard = 40                  #from 31 to 40
  Insane = 55                #from 41 to 55
  Extreme = Settings::MAXIMUM_LEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100               #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that controls trainer battle's difficulty
  
  # Calculates the difficulty based on your party pokemon's level and badges
  def self.calcDifficulty
    lv=[Light,Easy,Medium,Hard,Insane,Extreme]
    badges = $Trainer.numbadges
    balance = pbBalancedLevel($Trainer.party)
    mlv=0
    for poke in $Trainer.pokemon_party
      mlv=poke.level if poke.level>mlv
    end
    average = (badges*30+3*balance+4*mlv)/10
      for i in 0...lv.length
        if average <= lv[i]
          break
        end
      end
    return i
  end
end

Events.onWildPokemonCreate+=proc {|sender,e|
  pokemon=e[0]
  difficulty= LevelBalance::calcDifficulty
  badges = $Trainer.numbadges
  balance = pbBalancedLevel($Trainer.party)
  mlv=0
  for poke in $Trainer.pokemon_party
    mlv=poke.level if poke.level>mlv
  end
  case difficulty
    when 0 #Light
      l = balance/3 - 2 + rand(5)
    when 1 #Easy
      l = 2*balance/3  - 4 + rand(8)
    when 2 #Medium
      l = 3*(balance + 4*mlv)/20 - 4 + rand(8)
    when 3 #Hard
      l = 4*(balance + 4*mlv)/25 - 2 + rand(8)
    when 4 #Insane
      l = (balance + 4*mlv)/6 - 4 + rand(4+balance/10)
    else #Extreme
      l = 9*(balance + 4*mlv)/50 - 4 + rand(4+balance/10)
  end
  newlevel=l
  newlevel=1 if newlevel<1
  newlevel=GameData::GrowthRate.max_level if newlevel>GameData::GrowthRate.max_level
  pokemon.level=newlevel
  #now we evolve the pokémon, if applicable
  species = pokemon.species
  newspecies = pbGetBabySpecies(species) # revert to the first evolution
  evoflag=0 #used to track multiple evos not done by lvl
  endevo=false
  loop do #beginning of loop to evolve species
    nl = newlevel + 5
    nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
    pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
    cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
    evo = pbGetEvolvedFormData(newspecies)
    if evo
      evo = evo[rand(evo.length - 1)]
      # here we evolve things that don't evolve through level
      # that's what we check with evo[0]!=4
      #notice that such species have cevo==-1 and wouldn't pass the last check
      #to avoid it we set evoflag to 1 (with some randomness) so that
      #pokemon may have its second evolution (Raichu, for example)
      if evo && !cevo && rand(50) <= newlevel # if evo && cevo < 1 && rand(50) <= newlevel
        if evo[0] != 4 && rand(50) <= newlevel
          newspecies = evo[2] 
          if evoflag == 0 && rand(50) <= newlevel 
            evoflag=1
          else
            evoflag=0
          end
        end
      else
        endevo=true   
      end
    end
    if evoflag==0 || endevo
      if  !cevo || rand(50) > newlevel # if  cevo  == -1 || rand(50) > newlevel
        # Breaks if there no more evolutions or randomnly
        # Randomness applies only if the level is under 50 
        break
      else
        newspecies = evo[2]
      end
    end
  end
  #fixing some things such as Bellossom would turn into Vileplume
  #check if original species could evolve (Bellosom couldn't)
  couldevo=pbGetEvolvedFormData(species)
  #check if current species can evolve
  evo = pbGetEvolvedFormData(newspecies)
  if evo.length<1 && couldevo.length<1
  else
    species=newspecies
  end
  pokemon.name=GameData::Species.get(species).species.name # pokemon.name=PBSpecies.getName(species)
  pokemon.species=species
  pokemon.calcStats
  pokemon.resetMoves
}
     
Events.onTrainerPartyLoad+=proc {|sender,e|
  if e # if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0] # trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=trainer.items # items=trainer.items   # An array of the trainer's items they can use
    party=trainer.party # party=e[0].party # An array of the trainer's Pokémon

    if $game_switches && $game_switches[LevelBalance::Switch] && $Trainer && $Trainer.party.length > 0
      badges = $Trainer.numbadges
      balance = pbBalancedLevel($Trainer.party)
      mlv=0
      for poke in $Trainer.pokemon_party
        mlv=poke.level if poke.level>mlv
      end
      for i in 0...party.length
        #sets difficulty based on variable
        case $game_variables[LevelBalance::Trainer_dif]
          when 0 #Light
            l = balance/2 - 2 + rand(5)
          when 1 #Easy
            l = 3*balance/4  - 4 + rand(8)
          when 2 #Medium
            l = 9*(balance + 4*mlv)/50 - 4 + rand(4 + balance/10)
          when 3 #Hard
            l = 11*(balance + 4*mlv)/50  - 4 + rand(4 + balance/10)
          when 4 #Insane
            l = 5*(balance + 4*mlv)/20 - 4 + rand(4+balance/10)
          else #Extreme
            l = 7*(balance + 4*mlv)/25 - 4+ rand(4+balance/10)
        end
        level = l  
        level=1 if level<1
        level=GameData::GrowthRate.max_level if level>GameData::GrowthRate.max_level
        party[i].level = level
        #now we evolve the pokémon, if applicable
        species = party[i].species
        newspecies = pbGetBabySpecies(species) # revert to the first evolution
        evoflag=0 #used to track multiple evos not done by lvl
        endevo=false      
        loop do #beginning of loop to evolve species
          nl = level + 5
          nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
          pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattle_Pokemon.new(newspecies, nl) 
          cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
          evo = pbGetEvolvedFormData(newspecies)
          if evo
            evo = evo[rand(evo.length - 1)]
            # here we evolve things that don't evolve through level
            # that's what we check with evo[0]!=4
            #notice that such species have cevo==-1 and wouldn't pass the last check
            #to avoid it we set evoflag to 1 (with some randomness) so that
            #pokemon may have its second evolution (Raichu, for example)
            if evo && !cevo && rand(50) <= level # if evo && cevo < 1 && rand(50) <= level
              if evo[0] != 4 && rand(50) <= level
                newspecies = evo[2] 
                if evoflag == 0 && rand(50) <= level 
                  evoflag=1
                else
                  evoflag=0
                end
              end
            else
              endevo=true   
            end
          end
          if evoflag==0 || endevo
            if  !cevo || rand(50) > level # if  cevo  == -1 || rand(50) > level
              # Breaks if there no more evolutions or randomnly
              # Randomness applies only if the level is under 50 
              break
            else
              newspecies = evo[2]
            end
          end
        end #end of loop do
        #fixing some things such as Bellossom would turn into Vileplume
        #check if original species could evolve (Bellosom couldn't)
        couldevo=pbGetEvolvedFormData(species)
        #check if current species can evolve
        evo = pbGetEvolvedFormData(newspecies)
        if evo.length<1 && couldevo.length<1
        else
          species=newspecies
        end #end of evolving script
        party[i].name=GameData::Species.get(species).species.name # party[i].name=PBSpecies.getName(species)
        party[i].species=species
        party[i].calcStats
        party[i].resetMoves
      end #end of for
    end
  end
}
 
Last edited:
I have a team of level 100 pokemon, plus all 8 badges, so wild pokemon and trainer pokemon should be very close to my level, right?

Below, you find a new version for Joltik's "Advanced Level Balacing + Evolution" script for Pokemon Essentials version 19 and 19.1. It should work how you want it to work.

But first of all, some explainations how the old version actually works and why you have very low leveled trainer pokemon: The level of wild pokemon is based on the level of your team and your badges. However, the level of trainer pokemon is only based on the difficulty you stored in the $game_variable "trainer_dif". The value of that $game_variable is 0 by default, hence the difficulty is very easy and so trainer pokemon have a significant lower level. To increase the trainer difficulty you have to increase the value in that $game_variable during the story of your game goes on via events. With the new version below, you don't have to do that. Instead, the trainer difficulty is also based on the number of badges and everything works fine and automatically, similarily to wild pokebattles.

The new version for Pokemon Essentials version 19 and 19.1 allows you to set the trainer difficulty independently from the gained badges with that $game_variable mentioned before, but the difficulty will be the same as for wild pokebattles as long as you did not set the value of that $game_variable individually or set it to a number lower or equal to zero.

Now, the new code (simply replace the old code by this one in your project):

Code:
################################################################################
# Advanced Pokemon Level Balancing
# By Joltik
#Inspired by Umbreon's code
################################################################################
################################################################################


module LevelBalance
  
  Light = 10                 #from 1 to 10
  Easy = 20                  #from 11 to 20
  Medium = 30                #from 21 to 30
  Hard = 40                  #from 31 to 40
  Insane = 55                #from 41 to 55
  Extreme = Settings::MAXIMUM_LEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100               #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that controls trainer battle's difficulty
  
  # Calculates the difficulty based on your party pokemon's level and badges
  def self.calcDifficulty
    lv=[Light,Easy,Medium,Hard,Insane,Extreme]
    badges = $Trainer.numbadges
    balance = pbBalancedLevel($Trainer.party)
    mlv=0
    for poke in $Trainer.pokemon_party
      mlv=poke.level if poke.level>mlv
    end
    average = (badges*30+3*balance+4*mlv)/10
      for i in 0...lv.length
        if average <= lv[i]
          break
        end
      end
    return i
  end
end

Events.onWildPokemonCreate+=proc {|sender,e|
  pokemon=e[0]
  difficulty= LevelBalance::calcDifficulty
  badges = $Trainer.numbadges
  balance = pbBalancedLevel($Trainer.party)
  mlv=0
  for poke in $Trainer.pokemon_party
    mlv=poke.level if poke.level>mlv
  end
  case difficulty
    when 0 #Light
      l = balance/3 - 2 + rand(5)
    when 1 #Easy
      l = 2*balance/3  - 4 + rand(8)
    when 2 #Medium
      l = 3*(balance + 4*mlv)/20 - 4 + rand(8)
    when 3 #Hard
      l = 4*(balance + 4*mlv)/25 - 2 + rand(8)
    when 4 #Insane
      l = (balance + 4*mlv)/6 - 4 + rand(4+balance/10)
    else #Extreme
      l = 9*(balance + 4*mlv)/50 - 4 + rand(4+balance/10)
  end
  newlevel=l
  newlevel=1 if newlevel<1
  newlevel=GameData::GrowthRate.max_level if newlevel>GameData::GrowthRate.max_level
  pokemon.level=newlevel
  #now we evolve the pokémon, if applicable
  species = pokemon.species
  newspecies = pbGetBabySpecies(species) # revert to the first evolution
  evoflag=0 #used to track multiple evos not done by lvl
  endevo=false
  loop do #beginning of loop to evolve species
    nl = newlevel + 5
    nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
    pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattlepokemon_partyokemon.new(newspecies, nl) 
    cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
    evo = pbGetEvolvedFormData(newspecies)
    if evo
      evo = evo[rand(evo.length - 1)]
      # here we evolve things that don't evolve through level
      # that's what we check with evo[0]!=4
      #notice that such species have cevo==-1 and wouldn't pass the last check
      #to avoid it we set evoflag to 1 (with some randomness) so that
      #pokemon may have its second evolution (Raichu, for example)
      if evo && !cevo && rand(50) <= newlevel # if evo && cevo < 1 && rand(50) <= newlevel
        if evo[0] != 4 && rand(50) <= newlevel
          newspecies = evo[2] 
          if evoflag == 0 && rand(50) <= newlevel 
            evoflag=1
          else
            evoflag=0
          end
        end
      else
        endevo=true   
      end
    end
    if evoflag==0 || endevo
      if  !cevo || rand(50) > newlevel # if  cevo  == -1 || rand(50) > newlevel
        # Breaks if there no more evolutions or randomnly
        # Randomness applies only if the level is under 50 
        break
      else
        newspecies = evo[2]
      end
    end
  end
  #fixing some things such as Bellossom would turn into Vileplume
  #check if original species could evolve (Bellosom couldn't)
  couldevo=pbGetEvolvedFormData(species)
  #check if current species can evolve
  evo = pbGetEvolvedFormData(newspecies)
  if evo.length<1 && couldevo.length<1
  else
    species=newspecies
  end
  pokemon.name=GameData::Species.get(species).species.name # pokemon.name=PBSpecies.getName(species)
  pokemon.species=species
  pokemon.calcStats
  pokemon.resetMoves
}
     
Events.onTrainerPartyLoad+=proc {|sender,e|
  if e # if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0] # trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=trainer.items # items=trainer.items   # An array of the trainer's items they can use
    party=trainer.party # party=e[0].party # An array of the trainer's Pokémon

    if $game_switches && $game_switches[LevelBalance::Switch] && $Trainer && $Trainer.party.length > 0
      badges = $Trainer.numbadges
      balance = pbBalancedLevel($Trainer.party)
      mlv=0
      for poke in $Trainer.pokemon_party
        mlv=poke.level if poke.level>mlv
      end
      #sets difficulty based on variable
      difficulty = $game_variables[LevelBalance::Trainer_dif]
      difficulty = LevelBalance::calcDifficulty if !difficulty || difficulty <= 0
      for i in 0...party.length
        case difficulty
          when 0 #Light
            l = balance/2 - 2 + rand(5)
          when 1 #Easy
            l = 3*balance/4  - 4 + rand(8)
          when 2 #Medium
            l = 9*(balance + 4*mlv)/50 - 4 + rand(4 + balance/10)
          when 3 #Hard
            l = 11*(balance + 4*mlv)/50  - 4 + rand(4 + balance/10)
          when 4 #Insane
            l = 5*(balance + 4*mlv)/20 - 4 + rand(4+balance/10)
          else #Extreme
            l = 7*(balance + 4*mlv)/25 - 4+ rand(4+balance/10)
        end
        level = l  
        level=1 if level<1
        level=GameData::GrowthRate.max_level if level>GameData::GrowthRate.max_level
        party[i].level = level
        #now we evolve the pokémon, if applicable
        species = party[i].species
        newspecies = pbGetBabySpecies(species) # revert to the first evolution
        evoflag=0 #used to track multiple evos not done by lvl
        endevo=false      
        loop do #beginning of loop to evolve species
          nl = level + 5
          nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
          pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattlepokemon_partyokemon.new(newspecies, nl) 
          cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
          evo = pbGetEvolvedFormData(newspecies)
          if evo
            evo = evo[rand(evo.length - 1)]
            # here we evolve things that don't evolve through level
            # that's what we check with evo[0]!=4
            #notice that such species have cevo==-1 and wouldn't pass the last check
            #to avoid it we set evoflag to 1 (with some randomness) so that
            #pokemon may have its second evolution (Raichu, for example)
            if evo && !cevo && rand(50) <= level # if evo && cevo < 1 && rand(50) <= level
              if evo[0] != 4 && rand(50) <= level
                newspecies = evo[2] 
                if evoflag == 0 && rand(50) <= level 
                  evoflag=1
                else
                  evoflag=0
                end
              end
            else
              endevo=true   
            end
          end
          if evoflag==0 || endevo
            if  !cevo || rand(50) > level # if  cevo  == -1 || rand(50) > level
              # Breaks if there no more evolutions or randomnly
              # Randomness applies only if the level is under 50 
              break
            else
              newspecies = evo[2]
            end
          end
        end #end of loop do
        #fixing some things such as Bellossom would turn into Vileplume
        #check if original species could evolve (Bellosom couldn't)
        couldevo=pbGetEvolvedFormData(species)
        #check if current species can evolve
        evo = pbGetEvolvedFormData(newspecies)
        if evo.length<1 && couldevo.length<1
        else
          species=newspecies
        end #end of evolving script
        party[i].name=GameData::Species.get(species).species.name # party[i].name=PBSpecies.getName(species)
        party[i].species=species
        party[i].calcStats
        party[i].resetMoves
      end #end of for
    end
  end
}
 
Last edited:
looks good hope one day to see it for 20.1 but I understand these things take time
 
Hi! I updated this to be compatible with v21, I've tested it in all scenarios and it works. I also added a switch to enable or disable the script for wild Pokémon (63 by default)
Code:
################################################################################
# Advanced Pokemon Level Balancing
# By Joltik
#Inspired by Umbreon's code
################################################################################
################################################################################


module LevelBalance
  
  Light = 10                 #from 1 to 10
  Easy = 20                  #from 11 to 20
  Medium = 30                #from 21 to 30
  Hard = 40                  #from 31 to 40
  Insane = 55                #from 41 to 55
  Extreme = Settings::MAXIMUM_LEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100                 #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that controls trainer battle's difficulty
  DifficultySwitch = 63  #Switch that turns on Wild Difficulty

  # Calculates the difficulty based on your party pokemon's level and badges
  def self.calcDifficulty
    lv=[Light,Easy,Medium,Hard,Insane,Extreme]
    badges = $player.badge_count
    balance = pbBalancedLevel($player.party)
    mlv=0
    for poke in $player.pokemon_party
      mlv=poke.level if poke.level>mlv
    end
    average = (badges*30+3*balance+4*mlv)/10
      for i in 0...lv.length
        if average <= lv[i]
          break
        end
      end
    return i
  end
end

EventHandlers.add(:on_wild_pokemon_created, :automatic_level,
  proc { |pkmn|
    difficulty= LevelBalance::calcDifficulty
    badges = $player.badge_count
    balance = pbBalancedLevel($player.party)
    mlv=0
    if $game_switches && $game_switches[LevelBalance::DifficultySwitch]
    for poke in $player.pokemon_party
      mlv=poke.level if poke.level>mlv
    end
    case difficulty
      when 0 #Light
        l = balance/3 - 2 + rand(5)
      when 1 #Easy
        l = 2*balance/3  - 4 + rand(8)
      when 2 #Medium
        l = 3*(balance + 4*mlv)/20 - 4 + rand(8)
      when 3 #Hard
        l = 4*(balance + 4*mlv)/25 - 2 + rand(8)
      when 4 #Insane
        l = (balance + 4*mlv)/6 - 4 + rand(4+balance/10)
      else #Extreme
        l = 9*(balance + 4*mlv)/50 - 4 + rand(4+balance/10)
    end
    newlevel=l
    newlevel=1 if newlevel<1
    newlevel=GameData::GrowthRate.max_level if newlevel>GameData::GrowthRate.max_level
    pkmn.level=newlevel
    #now we evolve the pokémon, if applicable
    species = pkmn.species
    baby_species = babySpecies(species)
    newspecies = GameData::Species.get(baby_species)
    evoflag=0 #used to track multiple evos not done by lvl
    endevo=false
    loop do #beginning of loop to evolve species
      nl = newlevel + 5
      nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
      pkmn1 = Pokemon.new(newspecies, nl) # pkmn = PokeBattlepokemon_partyokemon.new(newspecies, nl) 
      cevo = pkmn1.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
      evo = GameData::Species.get(newspecies).get_evolutions
      if evo
        evo = evo[rand(evo.length - 1)]
        # here we evolve things that don't evolve through level
        # that's what we check with evo[0]!=4
        #notice that such species have cevo==-1 and wouldn't pass the last check
        #to avoid it we set evoflag to 1 (with some randomness) so that
        #pokemon may have its second evolution (Raichu, for example)
        if evo && !cevo && rand(50) <= newlevel # if evo && cevo < 1 && rand(50) <= newlevel
          if evo[1] != "Level" && rand(50) <= newlevel
            newspecies = GameData::Species.get(evo[0])
            if evoflag == 0 && rand(50) <= newlevel 
              evoflag=1
            else
              evoflag=0
            end
          end
        else
          endevo=true   
        end
      end
      if evoflag==0 || endevo
        if  !cevo || rand(50) > newlevel # if  cevo  == -1 || rand(50) > newlevel
          # Breaks if there no more evolutions or randomnly
          # Randomness applies only if the level is under 50 
          break
        else
          newspecies = GameData::Species.get(evo[0])
        end
      end
    end
    #fixing some things such as Bellossom would turn into Vileplume
    #check if original species could evolve (Bellosom couldn't)
    couldevo = GameData::Species.get(species).get_evolutions
    #check if current species can evolve
    evo = GameData::Species.get(newspecies).get_evolutions
    if evo.length<1 && couldevo.length<1
    else
      species=newspecies
    end
    pkmn.name=species.name # pokemon.name=PBSpecies.getName(species)
    pkmn.species=species
    pkmn.calc_stats
    pkmn.reset_moves
    end
  }
)
     
EventHandlers.add(:on_trainer_load, :put_a_name_here,
  proc { |trainer|
  if trainer# if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    items=trainer.items # items=trainer.items   # An array of the trainer's items they can use
    party=trainer.party # party=e[0].party # An array of the trainer's Pokémon
    if $game_switches && $game_switches[LevelBalance::Switch] && $player && $player.party.length > 0
      badges = $player.badge_count
      balance = pbBalancedLevel($player.party)
      mlv=0
      for poke in $player.pokemon_party
        mlv=poke.level if poke.level>mlv
      end
      #sets difficulty based on variable
      difficulty = $game_variables[LevelBalance::Trainer_dif]
      difficulty = LevelBalance::calcDifficulty if !difficulty || difficulty <= 0
      for i in 0...party.length
        case difficulty
          when 0 #Light
            l = balance/2 - 2 + rand(5)
          when 1 #Easy
            l = 3*balance/4  - 4 + rand(8)
          when 2 #Medium
            l = 9*(balance + 4*mlv)/50 - 4 + rand(4 + balance/10)
          when 3 #Hard
            l = 11*(balance + 4*mlv)/50  - 4 + rand(4 + balance/10)
          when 4 #Insane
            l = 5*(balance + 4*mlv)/20 - 4 + rand(4+balance/10)
          else #Extreme
            l = 7*(balance + 4*mlv)/25 - 4+ rand(4+balance/10)
        end
        level = l  
        level=1 if level<1
        level=GameData::GrowthRate.max_level if level>GameData::GrowthRate.max_level
        party[i].level = level
        #now we evolve the pokémon, if applicable
        species = party[i].species
        newspecies = babySpecies(species)
        evoflag=0 #used to track multiple evos not done by lvl
        endevo=false      
        loop do #beginning of loop to evolve species
          nl = level + 5
          nl = Settings::MAXIMUM_LEVEL if nl > Settings::MAXIMUM_LEVEL
          pkmn = Pokemon.new(newspecies, nl) # pkmn = PokeBattlepokemon_partyokemon.new(newspecies, nl) 
          cevo = pkmn.check_evolution_on_level_up # cevo = Kernel.pbCheckEvolution(pkmn)
          evo = GameData::Species.get(newspecies).get_evolutions
          if evo
            evo = evo[rand(evo.length - 1)]
            # here we evolve things that don't evolve through level
            # that's what we check with evo[0]!=4
            #notice that such species have cevo==-1 and wouldn't pass the last check
            #to avoid it we set evoflag to 1 (with some randomness) so that
            #pokemon may have its second evolution (Raichu, for example)
            if evo && !cevo && rand(50) <= level # if evo && cevo < 1 && rand(50) <= level
              if evo[1] != "Level" && rand(50) <= level
                newspecies = GameData::Species.get(evo[0])
                if evoflag == 0 && rand(50) <= level 
                  evoflag=1
                else
                  evoflag=0
                end
              end
            else
              endevo=true   
            end
          end
          if evoflag==0 || endevo
            if  !cevo || rand(50) > level # if  cevo  == -1 || rand(50) > level
              # Breaks if there no more evolutions or randomnly
              # Randomness applies only if the level is under 50 
              break
            else
              newspecies = GameData::Species.get(evo[0])
            end
          end
        end #end of loop do
        #fixing some things such as Bellossom would turn into Vileplume
        #check if original species could evolve (Bellosom couldn't)
        couldevo=GameData::Species.get(species).get_evolutions
        #check if current species can evolve
        evo = GameData::Species.get(newspecies).get_evolutions
        if evo.length<1 && couldevo.length<1
        else
          species=newspecies
        end #end of evolving script
        party[i].name=species.name # party[i].name=PBSpecies.getName(species)
        party[i].species=species
        party[i].calc_stats
        party[i].reset_moves
      end #end of for
    end
  end
}
)
Thanks to Joltik, this is such a great script!
 
Last edited:
Back
Top