• 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

129
Posts
14
Years
  • Age 24
  • Seen Sep 4, 2023
Hello everyone!

There are some codes around to make pokémon battles scale with your party level to make the game more challenging, some basic versions can be found even in Essentials.
Some of the codes evolve the Pokémon, however the available ones so far didn't handle well cases like multiple evolutions (making a Bellossom a Vileplume) or didn't properly evolve pokémon that has 2 evolutions not by level (say Pichu -> Pikachu -> Raichu).
Inspired on some codes by Umbreon I made my own version that fixes all that!

Features:
Balancing Wild Pokemon
Difficulty Levels for Trainers
Pokémon are automatically evolved when appropriate

Details:
For Wild Pokémon:
For battles in the wild, the effect is always there. Currently it matches your party to a difficulty level based on number of badges, average level and maximum level of your party. Then based on this classification it balances battles out.

For Trainer Battles:
The codes uses a switch to turn on/off the effect for trainers and a variable that sets the difficulty level of that trainer by hand. All the rest is similar to the mechanics of wild pokémon, except levels for trainers are slightly more challenging than for wild pokémon.

Everything is explained in comments so it should be easy to modify.
To install it, just copy this script and put it above Main:

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 = MAXIMUMLEVEL     #from 56 to MAXIMUMLEVEL
  Switch = 100               #Switch that turns on Trainer Difficulty Control
  Trainer_dif = 50           #Variable that ontrols 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=PBExperience::MAXLEVEL if newlevel>PBExperience::MAXLEVEL
     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 = MAXIMUMLEVEL if nl > MAXIMUMLEVEL
      pkmn = PokeBattle_Pokemon.new(newspecies, nl)
      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 < 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 == -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=PBSpecies.getName(species)
     pokemon.species=species
     pokemon.calcStats
     pokemon.resetMoves
     }
     
Events.onTrainerPartyLoad+=proc {|sender,e|
   if e[0] # Trainer data should exist to be loaded, but may not exist somehow
     trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
     items=e[0][1]   # An array of the trainer's items they can use
     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=PBExperience::MAXLEVEL if level>PBExperience::MAXLEVEL
      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 = MAXIMUMLEVEL if nl > MAXIMUMLEVEL
      pkmn = PokeBattle_Pokemon.new(newspecies, nl)
      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 < 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 == -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=PBSpecies.getName(species)
      party[i].species=species
      party[i].calcStats
      party[i].resetMoves
      end #end of for
     end
     end
     }

This is my first code, so I hope you can find it useful!
Credits are appreciated.
Thanks!
Joltik

Edit 17/06/18
Fixed a small typo in the end.
 
Last edited:
28
Posts
5
Years
  • Age 32
  • Seen Aug 5, 2022
Nice, this is basically what multiple region games needs. Is this backwards compatible? i.e. 14
 
28
Posts
5
Years
  • Age 32
  • Seen Aug 5, 2022
Tried it and Line 212: syntaxerror occurred.
Maybe it's not compatible with 14? Any feedback for this?
 
129
Posts
14
Years
  • Age 24
  • Seen Sep 4, 2023
Tried it and Line 212: syntaxerror occurred.
Maybe it's not compatible with 14? Any feedback for this?

This error is not due to compatibility. It was just missing a } in the end, when I copied it here. Fixed it. Lemme know if it works now.
Thanks for pointing it out.
 
Last edited:

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
Looks a great script! Ty to share!

But, one question:

To my game, all legendary battle, i have a specific swith, and your script cancel my swith. So, have a black list? or how can add this?

Ty ty!

EDIT:

DONE!

Spoiler:

Now i will try to create a switch for any region lol
1th region 1-151
etc etc
 
Last edited:
5
Posts
6
Years
  • Age 28
  • Seen Mar 3, 2021
Love the script. For it to work with trainers, do I need to set each Trainers difficulty manually then? I turn on the switch, it just doesn't seem like the levels are as high as they should be.
 
Last edited:

sonicfan7895

Just a dude, I guess
122
Posts
13
Years
If this doesn't count as necro-ing, I will be very happy...

I'm having the same problem as Doomwolf3146. I've been adjusting the Trainer Difficulty section as often as I can, and so much so that it's not even funny, and the maximum levels I can get out of this thing are level 53. And I have a maximum level set for 175 for my fan project. Granted I have the badges removed from one of my fan projects, and this one in particular is the one where levels don't exceed 53. Is there any workaround for this? Would like Pokemon battles to be a little more progressive in both of my fan projects.
 
180
Posts
6
Years
  • Age 20
  • Seen Apr 15, 2024
i don't understand how to use it for trainers...
Wich variable should i use?
 
Last edited:

Zeak6464

Zeak #3205 - Discord
1,101
Posts
11
Years
  • Age 31
  • USA
  • Seen Oct 9, 2023
i don't understand how to use it for trainers...
Wich variable should i use?

if you want trainer difficulty while using this script then
"Switch = 100 #Switch that turns on Trainer Difficulty Control"
would have to be on , but if not then your still okay.

This script is always on this script also affect Wild Battles along with Trainers.
 
180
Posts
6
Years
  • Age 20
  • Seen Apr 15, 2024
if you want trainer difficulty while using this script then
"Switch = 100 #Switch that turns on Trainer Difficulty Control"
would have to be on , but if not then your still okay.

This script is always on this script also affect Wild Battles along with Trainers.

Ohhh, and with this?
Trainer_dif = 50
What numbers should take the variable to control de trainer level balancing?
 

WolfPP

Spriter/ Pixel Artist
1,309
Posts
5
Years
Where can i add a switch for the evolutions, lets say, when the switch is off, the pokemon won't appear evolved?

Try to put 'game_switches[xxx]' above:
Code:
loop do #beginning of loop to evolve species
Also, pay attention to put a 'end' to that.
 
Last edited:
68
Posts
5
Years
  • Age 27
  • Seen Aug 25, 2023
the script cancels the movements that I put to the pokemon. Is there a way to stop that?
 
Last edited:
162
Posts
7
Years
  • Age 35
  • Seen today
Hi, I'm trying to use this ... Thanks for your work ... I wanted to ask ...

I just need to put the script and activate the switch ?

I have 3 badges, my team is around level 28-30. I activate the switch and a trainer with a team in level 19 appears with level 12 ...
 
2
Posts
3
Years
  • Age 21
  • Seen Jul 6, 2020
I know this is super old does anyone know if there is a way to use this script to add to the levels rather than replace them? I'd like to make it so that I can set the levels of wild Pokemon manually and then use this script to add 10 levels to all wild pokemon for each badge obtained. Is this possible?
 
11
Posts
3
Years
  • Age 31
  • Seen Mar 19, 2021
I made a modification to be able to change through a switch when the script will take effect on wild pokemons or not.
Spoiler:
 
3
Posts
3
Years
  • Age 39
  • Seen Apr 4, 2024
I am trying to get this script and Visible Overworld Wild Encounters Version 1.10.2 - by derFischae to work together. The game runs fine, however the over-world sprites don't show the evolution, I am not sure which script to be looking at to try and edit. any help would be awesome.
 
Back
Top