• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • 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.

Evolution during Battle

For Pokemon Essentials 18.1 see https://www.pokecommunity.com/threads/443637

UPDATED TO VERSION 1.2. This script is for Pokémon Essentials 17.2.

This Script allows a pokemon to evolve after a level up while still in battle. Then you can continue battling with your evolved pokemon. This Script is based on EVO DURING BATTLE BY Zeak6464 (Credit: Vendily), and added bug fix by WolfPP.
However I did some editing to make it drag and drop and removed some bugs.

FEATURES:
- Includes evolution during battle
- activate and deactivate it by setting the parameter EVODURINGBATTLE

BUG FIXES FROM PREVIOUS VERSIONS:
- prevents a small bug from the previous version, that a pokemon can evolve twice (first during battle and second after battle) with just one level up - by derFischae
- prevents bug that after battle the overworld music does not start - by WolfPP
- removed bug that pokemon that learned a new move on evolving during battle could not use it until switching in and out - by derFischae

INSTALLATION:
Installation as simple as it can be. Insert a new file in the script editor above main, name it Evo_During_Battle and copy this code into it.

PROPERTIES:
If you don't want to have evo during battle, you also have to change the value of the upcoming parameter EVODURINGBATTLE to false i.e.
EVODURINGBATTLE = false

Code:
#===========================================
# EVO DURING BATTLE BY Zeak6464, Credit: Vendily
#===========================================
# UPDATED TO VERSION 1.2. This script is for Pokémon Essentials 17.
#
# This Script allows a pokemon to evolve after a level up while still in battle. Then you can continue battling with your evolved pokemon.
# This Script is based on EVO DURING BATTLE BY Zeak6464 (Credit: Vendily), and added bug fix by WolfPP.
# However I did some editing to make it drag and drop and removed some bugs.
#
# FEATURES:
# - Includes evolution during battle
# - activate and deactivate it by setting the parameter EVODURINGBATTLE
#
# BUG FIXES FROM PREVIOUS VERSIONS: 
# - prevents a small bug from the previous version, that a pokemon can evolve twice (first during battle and second after battle) with just one level up - by derFischae
# -  prevents bug that after battle the overworld music does not start -  by WolfPP
# -  removed bug that pokemon that learned a new move on evolving  during battle could not use it until switching in and out  - by derFischae
#
# INSTALLATION:
# Installation as simple as it can be. Insert a new file in the script editor above main, name it Evo_During_Battle and copy this code into it.
#
# PROPERTIES:
# If you don't want to have evo during battle, you also have to change the value of the upcoming parameter EVODURINGBATTLE to false i.e.
#      EVODURINGBATTLE = false

#============================================
#    SETTINGS
#============================================
 
EVODURINGBATTLE = true
#true - means that your pokemon can evolve during battle
#false - means that they can only evolve after a battle as usual

#============================================
#adding new method in PokeBattle_Battler
#============================================

class PokeBattle_Battler
  def name=(value)
    @name=value
  end
end

#============================================
#overriding pbEvolutionCheck in PField_Battles
#pbEvolutionCheck originally was used to be added 
#via Event.onEndBattle in (in PField_Battles)
#============================================

alias original_pbEvolutionCheck pbEvolutionCheck

def pbEvolutionCheck(currentlevels)
  return if EVODURINGBATTLE
  original_pbEvolutionCheck(currentlevels)
end


#============================================
#overriding pbGainExpOne in PokeBattle_Battle
#here I include the evolution procedure at 
#the end of this this method that does exp
#gain level up and learning new moves...
#
#deviding pbGainExpOne into smaller parts
#for better overview:
#   pbGainEvOne
#============================================
class PokeBattle_Battle
  alias original_pbGainExpOne pbGainExpOne
  def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
    thispoke=@party1[index]
    # Original species, not current species
    level=defeated.level
    baseexp=defeated.pokemon.baseExp
    evyield=defeated.pokemon.evYield
    # Gain effort value points, using RS effort values
    pbGainEvOne(thispoke,evyield)
    # Calculate experience
    isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
               (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
    exp=pbCalculateExpOne(index, defeated, level, expshare, partic, haveexpall, thispoke, baseexp, isOutsider)
    growthrate=thispoke.growthrate
    newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
    exp=newexp-thispoke.exp
    # Gain experience
    if exp>0
      if showmessages
        if isOutsider
          pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
        else
          pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
        end
      end
      newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
      tempexp=0
      curlevel=thispoke.level
      if newlevel<curlevel
        debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
        raise RuntimeError.new(_INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
                               newlevel,curlevel,debuginfo))
        return
      end
      if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
        thispoke.exp+=exp
      else
        tempexp1=thispoke.exp
        tempexp2=0
        # Find battler
        battler=pbFindPlayerBattler(index)
        loop do
          # EXP Bar animation
          startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
          endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
          tempexp2=(endexp<newexp) ? endexp : newexp
          thispoke.exp=tempexp2
          @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
          tempexp1=tempexp2
          curlevel+=1
          if curlevel>newlevel
            thispoke.calcStats 
            battler.pbUpdate(false) if battler
            @scene.pbRefresh
            break
          end
          oldtotalhp=thispoke.totalhp
          oldattack=thispoke.attack
          olddefense=thispoke.defense
          oldspeed=thispoke.speed
          oldspatk=thispoke.spatk
          oldspdef=thispoke.spdef
          if battler && battler.pokemon && @internalbattle
            battler.pokemon.changeHappiness("levelup")
          end
          thispoke.calcStats
          battler.pbUpdate(false) if battler
          @scene.pbRefresh
          pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
          @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
                           olddefense,oldspeed,oldspatk,oldspdef)
          # Finding all moves learned at this level
          movelist=thispoke.getMoveList
          for k in movelist
            if k[0]==thispoke.level   # Learned a new move
              pbLearnMove(index,k[1])
            end
          end
        # Evo During Battle
          return if !EVODURINGBATTLE
          newspecies=pbCheckEvolution(thispoke)
          if newspecies>0
            pbFadeOutInWithMusic(99999){
              evo=PokemonEvolutionScene.new
              evo.pbStartScreen(thispoke,newspecies)
              evo.pbEvolution
              evo.pbEndScreen
              $game_map.autoplayAsCue
              if battler
                @scene.pbChangePokemon(@battlers[battler.index],@battlers[battler.index].pokemon)
                battler.pbInitPokemon(thispoke,battler.pokemonIndex)
                battler.name=thispoke.name
              end
            }
          end
        end
      end
    end
  end

# Gain effort value points, using RS effort values
  def pbGainEvOne(thispoke,evyield)
    totalev=0
    for k in 0...6
      totalev+=thispoke.ev[k]
    end
    for k in 0...6
      evgain=evyield[k]
      evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
                   isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
      case k
      when PBStats::HP
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
      when PBStats::ATTACK
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
      when PBStats::DEFENSE
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
      when PBStats::SPATK
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
      when PBStats::SPDEF
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
      when PBStats::SPEED
        evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
                     isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
      end
      evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
      if evgain>0
        # Can't exceed overall limit
        evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
        # Can't exceed stat limit
        evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
        # Add EV gain
        thispoke.ev[k]+=evgain
        if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
          print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k}  EV gain: #{evgain}  EVs: #{thispoke.ev.inspect}"
          thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
        end
        totalev+=evgain
        if totalev>PokeBattle_Pokemon::EVLIMIT
          print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain}  EVs: #{thispoke.ev.inspect}"
        end
      end
    end
  end
  
# Calculate experience
  def pbCalculateExpOne(index, defeated, level, expshare, partic, haveexpall, thispoke, baseexp, isOutsider)
    ispartic=0
    ispartic=1 if defeated.participants.include?(index)
    haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
                  isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
    exp=0
    if expshare>0
      if partic==0 # No participants, all Exp goes to Exp Share holders
        exp=(level*baseexp).floor
        exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
      else
        if NOSPLITEXP
          exp=(level*baseexp).floor*ispartic
          exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
        else
          exp=(level*baseexp/2).floor
          exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
        end
      end
    elsif ispartic==1
      exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
    elsif haveexpall
      exp=(level*baseexp/2).floor
    end
    return if exp<=0
    exp=(exp*3/2).floor if @opponent
    if USESCALEDEXPFORMULA
      exp=(exp/5).floor
      leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
      leveladjust=leveladjust**5
      leveladjust=Math.sqrt(leveladjust)
      exp=(exp*leveladjust).floor
      exp+=1 if ispartic>0 || haveexpshare>0
    else
      exp=(exp/7).floor
    end
    #isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
    #           (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
    if isOutsider
      if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
        exp=(exp*1.7).floor
      else
        exp=(exp*3/2).floor
      end
    end
    exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
                           isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
    return exp
  end
  
end
 
Last edited:
Works great so far! Surprised nobody has commented yet. My only minor complaint is that it restarts the battle music.
 
Last edited:
I added the code to fix that. You guys need to add:
Code:
$game_map.autoplayAsCue

Am on mobile right now but pretty sure derFischae will improve their script later.
 
Works great so far! Surprised nobody has commented yet. My only minor complaint is that it restarts the battle music.

I added the code to fix that. You guys need to add:
Code:
$game_map.autoplayAsCue

With WolfPP's code, the battle music still restarts after the evolution during battle. But WolfPP's code assures that the overworld music restarts after completing the whole battle, instead of having no background music.
 
Love the script! Main problem is that if a Pokemon learns a move by evolution, the move won't be there until after the battle
 
Love the script! Main problem is that if a Pokemon learns a move by evolution, the move won't be there until after the battle

To make sure that a pokemon that learned a move during evolving knows its move in battle without switching in and out, you can add the following line
Code:
                battler.pbInitialize(thispoke,thispoke,true)
right below
Code:
                @scene.pbChangePokemon(@battlers[battler.index],@battlers[battler.index].pokemon)

I also added this line in the code given in the first post. So it is also possible to simply replace your current version of the Evolution During Battle script by version 1.1.
 
huge issue :( I'm not sure why but im getting this error after the evolved pokemon is about to gain exp

[Pokémon Essentials version 17.2]
Exception: TypeError
Message: cannot convert PokeBattle_Pokemon into Integer
PokeBattle_Battle:1785:in `[]'
PokeBattle_Battle:1785:in `pbGainEXP'
PokeBattle_Battle:1784:in `each'
PokeBattle_Battle:1784:in `pbGainEXP'
PokeBattle_Battle:1773:in `each'
PokeBattle_Battle:1773:in `pbGainEXP'
PokeBattle_Battler:3255:in `pbUseMove'
PokeBattle_Battler:3363:in `pbProcessTurn'
PokeBattle_Battler:3362:in `logonerr'
PokeBattle_Battler:3362:in `pbProcessTurn'
[Pokémon Essentials version 17.2]
Exception: TypeError
Message: cannot convert PokeBattle_Pokemon into Integer
PokeBattle_Battle:1785:in `[]'
PokeBattle_Battle:1785:in `pbGainEXP'
PokeBattle_Battle:1784:in `each'
PokeBattle_Battle:1784:in `pbGainEXP'
PokeBattle_Battle:1773:in `each'
PokeBattle_Battle:1773:in `pbGainEXP'
PokeBattle_Battle:3840:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:42:in `pbEndOfRoundPhase'
PokeBattle_Battle:2536:in `pbStartBattleCore'
PokeBattle_Battle:2535:in `logonerr'

and then im stuck in the battle without an opponent forever

please help
 
huge issue :( I'm not sure why but im getting this error after the evolved pokemon is about to gain exp

[Pokémon Essentials version 17.2]
Exception: TypeError
Message: cannot convert PokeBattle_Pokemon into Integer
PokeBattle_Battle:1785:in `[]'
PokeBattle_Battle:1785:in `pbGainEXP'
PokeBattle_Battle:1784:in `each'
PokeBattle_Battle:1784:in `pbGainEXP'
PokeBattle_Battle:1773:in `each'
PokeBattle_Battle:1773:in `pbGainEXP'
PokeBattle_Battler:3255:in `pbUseMove'
PokeBattle_Battler:3363:in `pbProcessTurn'
PokeBattle_Battler:3362:in `logonerr'
PokeBattle_Battler:3362:in `pbProcessTurn'
[Pokémon Essentials version 17.2]
Exception: TypeError
Message: cannot convert PokeBattle_Pokemon into Integer
PokeBattle_Battle:1785:in `[]'
PokeBattle_Battle:1785:in `pbGainEXP'
PokeBattle_Battle:1784:in `each'
PokeBattle_Battle:1784:in `pbGainEXP'
PokeBattle_Battle:1773:in `each'
PokeBattle_Battle:1773:in `pbGainEXP'
PokeBattle_Battle:3840:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:42:in `pbEndOfRoundPhase'
PokeBattle_Battle:2536:in `pbStartBattleCore'
PokeBattle_Battle:2535:in `logonerr'

and then im stuck in the battle without an opponent forever

please help

Try commenting the line battler.pbInitialize(thispoke,thispoke,true), I think that's what is causing the error. It may not be in the correct place.
 
huge issue :( I'm not sure why but im getting this error after the evolved pokemon is about to gain exp

and then im stuck in the battle without an opponent forever

please help

Thank you for your report. The issue comes from the line
Code:
                battler.pbInitialize(thispoke,thispoke,true)
right below
Code:
                @scene.pbChangePokemon(@battlers[battler.index],@battlers[battler.index].pokemon)
as suggested correctly by Skyflyer.
To correct this, you can replace this line
Code:
                battler.pbInitialize(thispoke,thispoke,true)
by
Code:
                battler.pbInitPokemon(thispoke,battler.pokemonIndex)
I will also update the script in the first post. So you can alternatively copy and paste that new version 1.2.
 
Back
Top