• 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!
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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.

[Scripting Question] Exp. All gives too much Exp.

  • 18
    Posts
    5
    Years
    • Seen Jul 13, 2020
    Hello,
    I have recently noticed that using Exp. All - as defined in v17.2, gives the paarty much more Exp. than intended.

    For example, when not using the Exp. All, the Pokemon in battle gains 1000 Exp. points. But when I turn the Exp. All on, the Pokemon STILL gains 1000 Exp. points, and each of the remaining Pokemon gains half of the Exp. it would get by fighting alone. That means instead of getting 1000 points total, the party gains a total of 1000+(500*5)=3500 Exp. points!

    Does anyone know how to make a more reasonable distribution of the Exp? I've been digging in the code a little but couldn't find a proper way to do it.

    Thanks.
     
    Yes.
    I actually made it to work like I intended - I could share the script if anyone's interested.
     
    Always good you share the answer about you own question. :)

    Code:
    Does anyone know how to make a more reasonable distribution of the Exp? I've been digging in the code a little but couldn't find a proper way to do it.

    Did you try to use CTRL+Shift+F by searching "EXPALL"?
     
    Always good you share the answer about you own question. :)

    Code:
    Does anyone know how to make a more reasonable distribution of the Exp? I've been digging in the code a little but couldn't find a proper way to do it.

    Did you try to use CTRL+Shift+F by searching "EXPALL"?

    Yeah of course I searched for it :) That's how I found the original code. I did some tweaking to it and got it to work after a few trials and errors.

    Basically my stratrgy was to treat the expall as multiple exp. shares. So if I have an expall in my bag, each pokemon which did not participate in battle is considered as if it holds an Exp. Share.
    (It's important to note that I did not put the held-item Exp. Share in my game, but I think that it wouldn't work with the expall turned on.)

    Here's the edited code(edits are marked in red):
    in section PokeBattle_Battle:

    Code:
      def pbGainEXP
        return if !@internalbattle
        successbegin=true
        for i in 0...4 # Not ordered by priority
          if !@doublebattle && pbIsDoubleBattler?(i)
            @battlers[i].participants=[]
            next
          end
          if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
             (@battlers[i].fainted? || @battlers[i].captured)
            haveexpall=(hasConst?(PBItems,:EXPALL) && $PokemonBag.pbHasItem?(:EXPALL))
            # First count the number of participants
            partic=0
            expshare=0
            for j in @battlers[i].participants
              next if !@party1[j] || !pbIsOwner?(0,j)
              partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
            end
            if !haveexpall
              for j in [email protected]
                next if !@party1[j] || !pbIsOwner?(0,j)
                expshare+=1 if @party1[j].hp>0 && !@party1[j].egg? && 
                               (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
                               isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
              end
            [COLOR="Red"]else
              for j in [email protected]
                next if !@party1[j] || !pbIsOwner?(0,j)
                expshare+=1 if @party1[j].hp>0 && !@party1[j].egg?
              end[/COLOR]
            end
            # Now calculate EXP for the participants
            if partic>0 || expshare>0[COLOR="Red"] #deleted ||haveexpall since it's no longer needed[/COLOR]
              if !@opponent && successbegin && pbAllFainted?(@party2)
                @scene.pbWildBattleSuccess
                successbegin=false
              end
              for j in [email protected]
                next if !@party1[j] || !pbIsOwner?(0,j)
                next if @party1[j].hp<=0 || @party1[j].egg?
                haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
                              isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
                next if !haveexpshare && !@battlers[i].participants.include?(j)
                pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
              end
              if haveexpall
                showmessage=true
                for j in [email protected]
                  next if !@party1[j] || !pbIsOwner?(0,j)
                  next if @party1[j].hp<=0 || @party1[j].egg?
                  next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
                          isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
                  next if @battlers[i].participants.include?(j)
                  pbDisplayPaused(_INTL("The rest of your team gained Exp. Points thanks to the {1}!",
                     PBItems.getName(getConst(PBItems,:EXPALL)))) if showmessage
                  showmessage=false
                  pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
                end
              end
            end
            # Now clear the participants array
            @battlers[i].participants=[]
          end
        end
      end
    
      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
        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
        # Gain experience[COLOR="Red"][/COLOR]
        ispartic=0
        ispartic=1 if defeated.participants.include?(index)
        haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
                      isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
        [COLOR="Red"]haveexpshare=1 if haveexpall[/COLOR]
        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).[COLOR="Red"]ceil[/COLOR]*haveexpshare #ceil rounds up
            end
          end
        elsif ispartic==1
          exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
        [COLOR="Red"]#elsif haveexpall
        #  exp=(level*baseexp/2).floor[/COLOR]
        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)
        growthrate=thispoke.growthrate
        newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
        exp=newexp-thispoke.exp
        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
              pbSEPlay("pkmn move learnt")
              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
            end
          end
        end
      end

    I would be happy to answer any question if something's not clear :)
     
    Back
    Top