I changed opps = eachOpponent -> opps = []
battler.eachOpposing {|b| opps.push(b)}
Then replaced idxbattler with battler.index in the following script line.
skill = @battle.pbGetOwnerFromBattlerIndex(battler.index).skill || 0
Still getting the "moves" error though
I'm still getting this error:
Spoiler:![]()
Just a recommendation, you should probably put the beast mode part of the different trainer ai scale.
I think I got a new error :
Spoiler:![]()
I was testing and got a random wild battle
#=============================================================================
# Decide whether the opponent should Mega Evolve their Pokémon
#=============================================================================
def pbEnemyShouldMegaEvolve?(idxBattler)
return false if @battle.wildBattle? [COLOR="Green"]# Add this line right below the definition. [/COLOR]
# And then the rest
def shouldSwitchHandler(idxBattler,battler,opps)
battler = @battle.battlers[idxBattler]
skill = @battle.pbGetOwnerFromBattlerIndex(idxBattler).skill || 0
moves = battler.moves
hp = battler.hp
thp = battler.totalhp
# opps = battler.eachOpposing
move_pri = false
move_super = false
faster = false
opp_move_pri = false
higherhp = true # Previously undefined, not sure whether it should be initialized as true or false.
hyper = false # Previously undefined
battler.moves do |m|
if m.priority>0
move_pri = true
end
opps do |o|
move_super = PBTypes.superEffective?(m.type,o.type1,o.type2) # Change here.
if battler.stats[PBStats::SPEED]>o.stats[PBStats::SPEED] && battler.status != PBStatuses::PARALYSIS
faster = true
end
oppmoves = o.moves
oppmoves do |om|
if om.priority>0
opp_move_pri = true
end
end
if hp > o.hp
higherhp = true
else
higherhp = false
end
if @battle.pbSideSize(battler.index+1)==1 &&
!battler.pbDirectOpposing.fainted? && skill>=PBTrainerAI.highSkill
opp = battler.pbDirectOpposing
if opp.effects[PBEffects::HyperBeam]>0 ||
(opp.hasActiveAbility?(:TRUANT) && opp.effects[PBEffects::Truant])
hyper = true
end
end
end
end
if move_pri && !opp_move_pri
return false
end
if skill >= PBTrainerAI.mediumSkill
if move_super && faster
return false
end
end
if skill >= PBTrainerAI.highSkill
if (higherhp && faster) || (higherhp && move_pri) || (higherhp && faster && move_super)
return false
end
end
if skill >= PBTrainerAI.bestSkill
if battler.effects[PBEffects::PerishSong]==1
return true
end
if hyper
return false
end
end
if skill >= PBTrainerAI.beastMode
if battler.effects[PBEffects::Encore]>0
idxEncoredMove = battler.pbEncoredMoveIndex
if idxEncoredMove>=0
scoreSum = 0
scoreCount = 0
battler.eachOpposing do |b|
scoreSum += pbGetMoveScore(battler.moves[idxEncoredMove],battler,b,skill)
scoreCount += 1
end
if scoreCount>0 && scoreSum/scoreCount<=20
return false
end
end
end
if battler.status==PBStatuses::POISON && battler.statusCount>0
toxicHP = battler.totalhp/16
nextToxicHP = toxicHP*(battler.effects[PBEffects::Toxic]+1)
if battler.hp<=nextToxicHP && battler.hp>toxicHP*2
return true
end
end
end
return false
end
Hey there,
I'm currently testing/fixing this script, so maybe I can help.
The most important words are wild battle.
The problem is that the function pbEnemyShouldMegaEvolve?(idxBattler) is trying to ask the owner of the battler if it should mega-evolve. What owner? None, as it is a wild battle.
Tried it with your fix but wild battle still make error :(
Is it the same error? Please post a screenshot!
I think I should post the fixed script that I'm testing. There were several errors throughout the script so you may just have found another bug.
I'll show you after, but I think it was same error
EDIT: Here you go :
Spoiler:![]()
skill = @battle.pbGetOwnerFromBattlerIndex(idxBattler) || 0