KingRazor
Pokemon Master Since 1999
- 39
- Posts
- 14
- Years
- Age 36
- Oregon, USA
- Seen Oct 23, 2022
A friend of mine has been working with this starter kit for some time now. I've been alpha testing for him.
There is a bug in the program that we have yet to be able to fix.
When a pokemon who is not the currently selected pokemon levels up, they won't learn new moves.
For example, if I start a battle with a level 10 pikachu (who learns quick attack at level 11) and then, mid-fight, switch to Charmelon, and win the fight with Charmelon, and Pikachu gains enough exp to grow to level 11, he will grow to level 11, but will not learn quick attack.
This bug also occurs when using EXP share.
Here's the code for exp gain and move learning:
There is a bug in the program that we have yet to be able to fix.
When a pokemon who is not the currently selected pokemon levels up, they won't learn new moves.
For example, if I start a battle with a level 10 pikachu (who learns quick attack at level 11) and then, mid-fight, switch to Charmelon, and win the fight with Charmelon, and Pikachu gains enough exp to grow to level 11, he will grow to level 11, but will not learn quick attack.
This bug also occurs when using EXP share.
Here's the code for exp gain and move learning:
Code:
def pbGainEXP
return if !@internalbattle
successbegin=true
for i in 0..3 # Not ordered by priority
if !@doublebattle && pbIsDoubleBattler?(i)
@battlers[i].participants=[]
next
end
if pbIsOpposing?(i) && @battlers[i].participants.length>0 && @battlers[i].hp<=0
dexdata=pbOpenDexData
battlerSpecies=@battlers[i].species
# Current species, not original species; also using R/S base EXP
pbDexDataOffset(dexdata,battlerSpecies,17)
baseexp=dexdata.fgetb
level=@battlers[i].level
dexdata.close
# First count the number of participants
partic=0
expshare=0
for j in @battlers[i].participants
@participants[j]=true # Add participant to global list
end
for j in @battlers[i].participants
next if !@party1[j] || !pbIsOwner?(0,j)
partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
end
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)
end
# Now calculate EXP for the participants
if partic>0
if !@opponent && successbegin && pbAllFainted?(@party2)
@scene.pbWildBattleSuccess
successbegin=false
end
for j in [email protected]
thispoke=@party1[j]
next if !@party1[j] || !pbIsOwner?(0,j)
ispartic=0
level=@battlers[i].level
haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE)) ? 1 : 0
for k in @battlers[i].participants
ispartic=1 if k==j
end
if thispoke.hp>0 && !thispoke.egg?
exp=0
if expshare>0
exp=((level*baseexp/7).floor/2).floor
exp=(exp/partic).floor*ispartic+(exp/expshare).floor*haveexpshare
elsif ispartic==1
exp=((level*baseexp/7).floor/partic).floor
end
isOutsider=(thispoke.trainerID!=self.pbPlayer.id || (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
exp=(exp*3/2).floor if @opponent
exp=(exp*3/2).floor if isOutsider
exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG)
growthrate=thispoke.growthrate
newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
exp=newexp-thispoke.exp;
if exp > 0
if isOutsider
pbDisplayPaused(_INTL("{1} gained a boosted\r\n{2} Exp. Points!",thispoke.name,exp))
else
pbDisplayPaused(_INTL("{1} gained\r\n{2} Exp. Points!",thispoke.name,exp))
end
#Gain effort value points, using RS effort values
totalev=0
for k in 0..5
totalev+=thispoke.ev[k]
end
dexdata=pbOpenDexData
pbDexDataOffset(dexdata,battlerSpecies,23)
for k in 0..5
evgain=dexdata.fgetb
if isConst?(thispoke.item,PBItems,:MACHOBRACE)
evgain*=2
end
if evgain>0
# Can't exceed overall limit
if totalev+evgain>510
# Bug Fix: must use "-=" instead of "="
evgain-=totalev+evgain-510
end
# Can't exceed stat limit
if thispoke.ev[k]+evgain>255
# Bug Fix: must use "-=" instead of "="
evgain-=thispoke.ev[k]+evgain-255
end
# Add EV gain
thispoke.ev[k]+=evgain
if thispoke.ev[k]>255
print "Single-stat EV limit 255 exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
thispoke.ev[k]=255
end
totalev+=evgain
if totalev>510
print "EV limit 510 exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
end
end
end
newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
tempexp=0
curlevel=thispoke.level
thisPokeSpecies=thispoke.species
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(j)
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
break if curlevel>newlevel
oldtotalhp=thispoke.totalhp
oldattack=thispoke.attack
olddefense=thispoke.defense
oldspeed=thispoke.speed
oldspatk=thispoke.spatk
oldspdef=thispoke.spdef
thispoke.calcStats
battler.pbUpdate if battler
@scene.pbRefresh
if battler.pokemon && @internalbattle
battler.pokemon.happiness+=2
battler.pokemon.happiness=255 if battler.pokemon.happiness>255
end
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
atkdata=pbRgssOpen("Data/attacksRS.dat","rb")
offset=atkdata.getOffset(thisPokeSpecies-1)
length=atkdata.getLength(thisPokeSpecies-1)>>1
atkdata.pos=offset
for k in 0..length-1
atklevel=atkdata.fgetw
move=atkdata.fgetw
if atklevel==thispoke.level
# Learned a new move
pbLearnMove(j,move)
end
end
atkdata.close
end
end
end
end
end
end
# Now clear the participants array
@battlers[i].participants=[]
end
end
end
Code:
def pbLearnMove(pkmnIndex,move)
pokemon=@party1[pkmnIndex]
return if !pokemon
pkmnname=pokemon.name
battler=pbFindPlayerBattler(pkmnIndex)
movename=PBMoves.getName(move)
for i in 0..3
if pokemon.moves[i].id==move
return
end
if pokemon.moves[i].id==0
pokemon.moves[i]=PBMove.new(move)
battler.moves[i]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[i]) if battler
pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
return
end
end
loop do
pbDisplayPaused(_INTL("{1} is trying to learn {2}.",pkmnname,movename)) #Replaces current/total PP
pbDisplayPaused(_INTL("But {1} can't learn more than four moves.",pkmnname))
if pbDisplayConfirm(_INTL("Delete a move to make room for {1}?",movename))
pbDisplayPaused(_INTL("Which move should be forgotten?"))
[email protected](pokemon,move)
if forgetmove >=0
oldmovename=PBMoves.getName(pokemon.moves[forgetmove].id)
pokemon.moves[forgetmove]=PBMove.new(move)#Replaces current/total PP
battler.moves[forgetmove]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[forgetmove]) if battler
pbDisplayPaused(_INTL("1, 2, and... ... ..."))
pbDisplayPaused(_INTL("Poof!"))
pbDisplayPaused(_INTL("{1} forgot {2}.",pkmnname,oldmovename))
pbDisplayPaused(_INTL("And..."))
pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
return
elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
return
end
elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
return
end
end
end
def pbGainEXP
return if !@internalbattle
successbegin=true
for i in 0..3 # Not ordered by priority
if !@doublebattle && pbIsDoubleBattler?(i)
@battlers[i].participants=[]
next
end
if pbIsOpposing?(i) && @battlers[i].participants.length>0 && @battlers[i].hp<=0
dexdata=pbOpenDexData
battlerSpecies=@battlers[i].species
# Current species, not original species; also using R/S base EXP
pbDexDataOffset(dexdata,battlerSpecies,17)
baseexp=dexdata.fgetb
level=@battlers[i].level
dexdata.close
# First count the number of participants
partic=0
expshare=0
for j in @battlers[i].participants
@participants[j]=true # Add participant to global list
end
for j in @battlers[i].participants
next if !@party1[j] || !pbIsOwner?(0,j)
partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
end
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)
end
# Now calculate EXP for the participants
if partic>0
if !@opponent && successbegin && pbAllFainted?(@party2)
@scene.pbWildBattleSuccess
successbegin=false
end
for j in [email protected]
thispoke=@party1[j]
next if !@party1[j] || !pbIsOwner?(0,j)
ispartic=0
level=@battlers[i].level
haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE)) ? 1 : 0
for k in @battlers[i].participants
ispartic=1 if k==j
end
if thispoke.hp>0 && !thispoke.egg?
exp=0
if expshare>0
exp=((level*baseexp/7).floor/2).floor
exp=(exp/partic).floor*ispartic+(exp/expshare).floor*haveexpshare
elsif ispartic==1
exp=((level*baseexp/7).floor/partic).floor
end
isOutsider=(thispoke.trainerID!=self.pbPlayer.id || (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
exp=(exp*3/2).floor if @opponent
exp=(exp*3/2).floor if isOutsider
exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG)
growthrate=thispoke.growthrate
newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
exp=newexp-thispoke.exp;
if exp > 0
if isOutsider
pbDisplayPaused(_INTL("{1} gained a boosted\r\n{2} Exp. Points!",thispoke.name,exp))
else
pbDisplayPaused(_INTL("{1} gained\r\n{2} Exp. Points!",thispoke.name,exp))
end
#Gain effort value points, using RS effort values
totalev=0
for k in 0..5
totalev+=thispoke.ev[k]
end
dexdata=pbOpenDexData
pbDexDataOffset(dexdata,battlerSpecies,23)
for k in 0..5
evgain=dexdata.fgetb
if isConst?(thispoke.item,PBItems,:MACHOBRACE)
evgain*=2
end
if evgain>0
# Can't exceed overall limit
if totalev+evgain>510
# Bug Fix: must use "-=" instead of "="
evgain-=totalev+evgain-510
end
# Can't exceed stat limit
if thispoke.ev[k]+evgain>255
# Bug Fix: must use "-=" instead of "="
evgain-=thispoke.ev[k]+evgain-255
end
# Add EV gain
thispoke.ev[k]+=evgain
if thispoke.ev[k]>255
print "Single-stat EV limit 255 exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
thispoke.ev[k]=255
end
totalev+=evgain
if totalev>510
print "EV limit 510 exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
end
end
end
newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
tempexp=0
curlevel=thispoke.level
thisPokeSpecies=thispoke.species
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(j)
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
break if curlevel>newlevel
oldtotalhp=thispoke.totalhp
oldattack=thispoke.attack
olddefense=thispoke.defense
oldspeed=thispoke.speed
oldspatk=thispoke.spatk
oldspdef=thispoke.spdef
thispoke.calcStats
battler.pbUpdate if battler
@scene.pbRefresh
if battler.pokemon && @internalbattle
battler.pokemon.happiness+=2
battler.pokemon.happiness=255 if battler.pokemon.happiness>255
end
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
atkdata=pbRgssOpen("Data/attacksRS.dat","rb")
offset=atkdata.getOffset(thisPokeSpecies-1)
length=atkdata.getLength(thisPokeSpecies-1)>>1
atkdata.pos=offset
for k in 0..length-1
atklevel=atkdata.fgetw
move=atkdata.fgetw
if atklevel==thispoke.level
# Learned a new move
pbLearnMove(j,move)
end
end
atkdata.close
end
end
end
end
end
end
# Now clear the participants array
@battlers[i].participants=[]
end
end
end