The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script [Essentials v17] Advanced Level Balacing + Evolution

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Reply
 
Thread Tools
  #1    
Old June 16th, 2018 (6:25 AM). Edited 4 Weeks Ago by Joltik.
Joltik's Avatar
Joltik Joltik is offline
     
    Join Date: Jan 2010
    Gender: Male
    Nature: Modest
    Posts: 125
    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.
    __________________

    Check out my DeviantArt account! My game project is called Pokemon Subrosia.
    My DeviantArt | Old DeviantArt
    Reply With Quote

    Relevant Advertising!

      #2    
    Old June 16th, 2018 (8:23 PM).
    Ai.Cy's Avatar
    Ai.Cy Ai.Cy is offline
       
      Join Date: May 2018
      Posts: 28
      Nice, this is basically what multiple region games needs. Is this backwards compatible? i.e. 14
      Reply With Quote
        #3    
      Old June 17th, 2018 (1:48 AM).
      Joltik's Avatar
      Joltik Joltik is offline
         
        Join Date: Jan 2010
        Gender: Male
        Nature: Modest
        Posts: 125
        Quote:
        Originally Posted by Ai.Cy View Post
        Nice, this is basically what multiple region games needs. Is this backwards compatible? i.e. 14
        I'm not sure, In principle it should be. Give it a try!
        __________________

        Check out my DeviantArt account! My game project is called Pokemon Subrosia.
        My DeviantArt | Old DeviantArt
        Reply With Quote
          #4    
        Old June 17th, 2018 (6:17 AM).
        Ai.Cy's Avatar
        Ai.Cy Ai.Cy is offline
           
          Join Date: May 2018
          Posts: 28
          Tried it and Line 212: syntaxerror occurred.
          Maybe it's not compatible with 14? Any feedback for this?
          Reply With Quote
            #5    
          Old June 17th, 2018 (9:30 AM). Edited June 17th, 2018 by Joltik.
          Joltik's Avatar
          Joltik Joltik is offline
             
            Join Date: Jan 2010
            Gender: Male
            Nature: Modest
            Posts: 125
            Quote:
            Originally Posted by Ai.Cy View Post
            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.
            __________________

            Check out my DeviantArt account! My game project is called Pokemon Subrosia.
            My DeviantArt | Old DeviantArt
            Reply With Quote
              #6    
            Old June 17th, 2018 (1:55 PM). Edited June 17th, 2018 by Ai.Cy.
            Ai.Cy's Avatar
            Ai.Cy Ai.Cy is offline
               
              Join Date: May 2018
              Posts: 28
              I tried doing that yesterday, still does not work. I tried adding { at line 122 still does not work.

              If you have the time can you try it here?
              https://www28.zippyshare.com/v/En2HB06d/file.html
              Reply With Quote
                #7    
              Old 4 Weeks Ago (5:18 AM).
              Joltik's Avatar
              Joltik Joltik is offline
                 
                Join Date: Jan 2010
                Gender: Male
                Nature: Modest
                Posts: 125
                Quote:
                Originally Posted by Ai.Cy View Post
                I tried doing that yesterday, still does not work. I tried adding { at line 122 still does not work.

                If you have the time can you try it here?
                https://www28.zippyshare.com/v/En2HB06d/file.html
                I added on more modification now, but if it doesn't work with what is there now, then it is most likely not compatible with v14.
                __________________

                Check out my DeviantArt account! My game project is called Pokemon Subrosia.
                My DeviantArt | Old DeviantArt
                Reply With Quote
                Reply

                Quick Reply

                Join the conversation!

                Create an account to post a reply in this thread, participate in other discussions, and more!

                Create a PokéCommunity Account

                Sponsored Links
                Thread Tools

                Posting Rules
                You may not post new threads
                You may not post replies
                You may not post attachments
                You may not edit your posts

                BB code is On
                Smilies are On
                [IMG] code is On
                HTML code is Off

                Forum Jump


                All times are GMT -8. The time now is 6:45 PM.