# ------------------------------------------------------------------------------
# Written by Stochastic, except for customTrainerBattle method which is a
# modified version of pbTrainerBattle method.
# ------------------------------------------------------------------------------
BR_DRAW = 5
BR_LOSS = 2
BR_WIN = 1
# ------------------------------------------------------------------------------
# species - Name of the species, e.g. "PIKACHU"
# level - Level
# moveset - Optional. Array of moves, e.g. [:MUDSLAP, :THUNDERBOLT, :VINEWHIP]
# If not specified, pokemon will be created with moves learned by leveling.
# The pokemon doesn't need to be able to learn the given moves, they can be
# arbitary.
# ------------------------------------------------------------------------------
def createPokemon(species, level, moveset=nil)
begin
poke = PokeBattle_Pokemon.new(species, level)
poke.moves = convertMoves(moveset) if moveset
poke.shinyflag = false
return poke
rescue
return PokeBattle_Pokemon.new("PIKACHU", 5)
end
end
def convertMoves(moves)
moves.map! {|m| PBMove.new(getMoveID(m))}
return moves
end
# provide move like this; :TACKLE
def getMoveID(move)
return getConst(PBMoves,move)
end
# ------------------------------------------------------------------------------
# Creates a trainer with specified id, name, party, and optionally, items.
# Does not depend on defined trainers, only on trainer types
# ------------------------------------------------------------------------------
def createTrainer(trainerid,trainername,party,items=[])
name = pbGetMessageFromHash(MessageTypes::TrainerNames, trainername)
opponent = PokeBattle_Trainer.new(name, trainerid)
opponent.setForeignID($Trainer) if $Trainer
opponent.party = party
return [opponent,items,party]
end
# ------------------------------------------------------------------------------
# Initiates trainer battle. This is a modified pbTrainerBattle method.
#
# trainer - custom PokeBattle_Trainer provided by the user
# endspeech - what the trainer says in-battle when defeated
# doublebattle - Optional. Set it to true if you want a double battle
# canlose - Optional. Set it to true if you want your party to be healed after battle,
#and if you don't want to be sent to a pokemon center if you lose
# ------------------------------------------------------------------------------
def customTrainerBattle(trainer,endspeech,doublebattle=false,canlose=false)
trainerparty=0 # added by SH
if $Trainer.pokemonCount==0
Kernel.pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
return BR_LOSS # changed by SH
end
if !$PokemonTemp.waitingTrainer && $Trainer.ablePokemonCount>1 &&
pbMapInterpreterRunning?
thisEvent=pbMapInterpreter.get_character(0)
triggeredEvents=$game_player.pbTriggeredTrainerEvents([2],false)
otherEvent=[]
for i in triggeredEvents
if i.id!=thisEvent.id && !$game_self_switches[[$game_map.map_id,i.id,"A"]]
otherEvent.push(i)
end
end
if otherEvent.length==1
if trainer[2].length<=3
$PokemonTemp.waitingTrainer=[trainer,thisEvent.id,endspeech,doublebattle]
return BR_LOSS # changed by SH
end
end
end
if $PokemonGlobal.partner && ($PokemonTemp.waitingTrainer || doublebattle)
othertrainer=PokeBattle_Trainer.new(
$PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
othertrainer.id=$PokemonGlobal.partner[2]
othertrainer.party=$PokemonGlobal.partner[3]
playerparty=[]
for i in 0...$Trainer.party.length
playerparty=$Trainer.party
end
for i in 0...othertrainer.party.length
playerparty[6+i]=othertrainer.party
end
fullparty1=true
playertrainer=[$Trainer,othertrainer]
doublebattle=true
else
playerparty=$Trainer.party
playertrainer=$Trainer
fullparty1=false
end
if $PokemonTemp.waitingTrainer
combinedParty=[]
fullparty2=false
if false
if $PokemonTemp.waitingTrainer[0][2].length>3
raise _INTL("Opponent 1's party has more than three Pokémon, which is not allowed")
end
if trainer[2].length>3
raise _INTL("Opponent 2's party has more than three Pokémon, which is not allowed")
end
elsif $PokemonTemp.waitingTrainer[0][2].length>3 || trainer[2].length>3
for i in 0...$PokemonTemp.waitingTrainer[0][2].length
combinedParty=$PokemonTemp.waitingTrainer[0][2]
end
for i in 0...trainer[2].length
combinedParty[6+i]=trainer[2]
end
fullparty2=true
else
for i in 0...$PokemonTemp.waitingTrainer[0][2].length
combinedParty=$PokemonTemp.waitingTrainer[0][2]
end
for i in 0...trainer[2].length
combinedParty[3+i]=trainer[2]
end
fullparty2=false
end
scene=pbNewBattleScene
battle=PokeBattle_Battle.new(scene,playerparty,combinedParty,playertrainer,
[$PokemonTemp.waitingTrainer[0][0],trainer[0]])
trainerbgm=pbGetTrainerBattleBGM(
[$PokemonTemp.waitingTrainer[0][0],trainer[0]])
battle.fullparty1=fullparty1
battle.fullparty2=fullparty2
battle.doublebattle=battle.pbDoubleBattleAllowed?()
battle.endspeech=$PokemonTemp.waitingTrainer[2]
battle.endspeech2=endspeech
battle.items=[$PokemonTemp.waitingTrainer[0][1],trainer[1]]
else
scene=pbNewBattleScene
battle=PokeBattle_Battle.new(scene,playerparty,trainer[2],playertrainer,trainer[0])
battle.fullparty1=fullparty1
battle.doublebattle=doublebattle ? battle.pbDoubleBattleAllowed?() : false
battle.endspeech=endspeech
battle.items=trainer[1]
trainerbgm=pbGetTrainerBattleBGM(trainer[0])
end
if Input.press?(Input::CTRL) && $DEBUG
Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
Kernel.pbMessage(_INTL("AFTER LOSING..."))
Kernel.pbMessage(battle.endspeech)
Kernel.pbMessage(battle.endspeech2) if battle.endspeech2
if $PokemonTemp.waitingTrainer
pbMapInterpreter.pbSetSelfSwitch(
$PokemonTemp.waitingTrainer[1],"A",true
)
$PokemonTemp.waitingTrainer=nil
end
return BR_WIN # changed by SH
end
Events.onStartBattle.trigger(nil,nil)
battle.internalbattle=true
pbPrepareBattle(battle)
restorebgm=true
decision=0
pbBattleAnimation(trainerbgm,trainer[0].trainertype,trainer[0].name) {
pbSceneStandby {
decision=battle.pbStartBattle(canlose)
}
if $PokemonGlobal.partner
pbHealAll
for i in $PokemonGlobal.partner[3]; i.heal; end
end
if decision==2 || decision==5
if canlose
for i in $Trainer.party; i.heal; end
for i in 0...10
Graphics.update
end
else
$game_system.bgm_unpause
$game_system.bgs_unpause
Kernel.pbStartOver
end
else
Events.onEndBattle.trigger(nil,decision)
if decision==1
if $PokemonTemp.waitingTrainer
pbMapInterpreter.pbSetSelfSwitch(
$PokemonTemp.waitingTrainer[1],"A",true
)
end
end
end
}
Input.update
$PokemonTemp.waitingTrainer=nil
return decision # changed by SH
end
# lead and ace are the species of the trainer's lead and ace Pokemon, respectively
# possibilities is an array with all the possible choices. Defaults to empty
# number is the total number of Pokemon on the team. Defaults to six.
# - this value does include the lead and the ace, so add 2.
# - the code has error handlers that prevent the creation of teams larger than six, or of teams larger than the array above will allow.
# name is the trainer's name. Defaults to Bobby
# class is the type of trainer they are (Ace Trainer, Gym Leader, etc.). Defaults to Youngster.
# This version of the code is for making the Pokemon have "default" moves.
# Easier to use, but less precise
def defaultRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",trainerid=PBTrainers::YOUNGSTER)
# Allow for multiple types of inputting species types
# numbers, strings of the Pokemon's name, or the internal name
if lead.is_a?(String) || lead.is_a?(Symbol)
lead=getConst(PBSpecies,lead)
end
if ace.is_a?(String) || ace.is_a?(Symbol)
lead=getConst(PBSpecies,ace)
end
for i in 0...possibilities.length
if possibilities.is_a?(String) || possibilities.is_a?(Symbol)
possibilities=getConst(PBSpecies,possibilities)
end
end
# Allow for multiple methods of inputting trainer type names
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
trainerid=getConst(PBTrainers,trainerid)
end
# create the "lead" pokemon
poke1=createPokemon(lead,64) # change the 64 to be the level you want the Pokemon to be
team=[poke1]
# create the "grunt" pokemon
grunts=[possibilities.length,number-2,4].min
if grunts>0
for i in 0...grunts
# choosing a random Pokemon from the list of possibilities
poke=rand(possibilities.length)
poke2=createPokemon(possibilities[poke],64) # again, change 64 to the proper level
team.push(poke2)
# removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
possibilities[poke]=nil
possibilities.compact!
end
end
# create the "ace" pokemon
poke3=createPokemon(ace,64) # change the 64 to be the level you want the Pokemon to be
team.push(poke3)
# create the trainer
return createTrainer(trainerid,name,team)
end
# this version of the code allows you to define Pokemon complete with moves, specific abilities, etc.
# more custom and precise, but requires more initialization
def definedRandomTeam(lead,ace,possiblities=[],number=6,name="Bobby",trainerid=PBTrainers::YOUNGSTER)
# Allow for multiple methods of inputting trainer type names
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
trainerid=getConst(PBTrainers,trainerid)
end
# add the lead
team=[lead]
# add the grunts
grunts=[possibilities.length,number-2,4].min
if grunts>0
for i in 0...grunts
# choosing a random Pokemon from the list of possibilities
poke=rand(possibilities.length)
team.push(possibilities[poke])
# removing the chosen Pokemon from the list of possibilities so it doesn't get picked again.
possibilities[poke]=nil
possibilities.compact!
end
end
# add the ace
team.push(ace)
# create the trainer
return createTrainer(trainerid,name,team)
end