def pbLoadTrainer(trainerid,trainername,partyid=0)
success=false
items=[]
party=[]
opponent=nil
trainers=load_data("Data/trainers.dat")
for trainer in trainers
name=trainer[1]
thistrainerid=trainer[0]
thispartyid=trainer[4]
next if trainerid!=thistrainerid || name!=trainername || partyid!=thispartyid
items=trainer[2].clone
name=pbGetMessageFromHash(MessageTypes::TrainerNames,name)
for i in RIVALNAMES
if isConst?(trainerid,PBTrainers,i[0]) && $game_variables[i[1]]!=0
name=$game_variables[i[1]]
end
end
opponent=PokeBattle_Trainer.new(name,thistrainerid)
opponent.setForeignID($Trainer) if $Trainer
for poke in trainer[3]
species=poke[TPSPECIES]
[COLOR="Red"]if $game_switches[41]==true
level=pbBalancedLevel($Trainer.party) - rand(9)
if level<=1
level=2 + rand(3)
end
if level>100
level=100 - rand(8)
end[/COLOR]
# if level>
# level=pbBalancedLevel($Trainer.party) - rand(3)
# end
else
level=poke[TPLEVEL]
end
pokemon=PokeBattle_Pokemon.new(species,level,opponent)
pokemon.form=poke[TPFORM]
pokemon.resetMoves
pokemon.item=poke[TPITEM]
if poke[TPMOVE1]>0 || poke[TPMOVE2]>0 || poke[TPMOVE3]>0 || poke[TPMOVE4]>0
k=0
for move in [TPMOVE1,TPMOVE2,TPMOVE3,TPMOVE4]
pokemon.moves[k]=PBMove.new(poke[move])
k+=1
end
pokemon.moves.compact!
end
pokemon.setAbility(poke[TPABILITY])
pokemon.setGender(poke[TPGENDER])
if poke[TPSHINY] # if this is a shiny Pokémon
pokemon.makeShiny
else
pokemon.makeNotShiny
end
pokemon.setNature(poke[TPNATURE])
iv=poke[TPIV]
for i in 0...6
pokemon.iv[i]=iv&0x1F
pokemon.ev[i]=[85,level*3/2].min
end
pokemon.happiness=poke[TPHAPPINESS]
pokemon.name=poke[TPNAME] if poke[TPNAME] && poke[TPNAME]!=""
if poke[TPSHADOW] # if this is a Shadow Pokémon
pokemon.makeShadow rescue nil
pokemon.pbUpdateShadowMoves(true) rescue nil
pokemon.makeNotShiny
end
pokemon.ballused=poke[TPBALL]
pokemon.calcStats
party.push(pokemon)
end
success=true
break
end
return success ? [opponent,items,party] : nil
end
def pbConvertTrainerData
data=load_data("Data/trainertypes.dat")
trainertypes=[]
for i in 0...data.length
record=data[i]
if record
trainertypes[record[0]]=record[2]
end
end
MessageTypes.setMessages(MessageTypes::TrainerTypes,trainertypes)
pbSaveTrainerTypes()
pbSaveTrainerBattles()
end