Help [Scripts]Forcing AI To Hold Pokémon?

Xerado

Novice
Member
Posts
26
#1
It's me again. Sorry.
So, I was looking for a way to for an enemy trainer to hold a certain Pokémon to send out last after the rest of their team has been defeated.
And I found this on PokeCommunity:
def pbDefaultChooseNewEnemy(index,party)
enemies=[]
for i in 0..party.length-1
if pbCanSwitchLax?(index,i,false)
enemies.push(i) if i != party.length-1 || enemies.length==0
end
end
if enemies.length>0
return pbChooseBestNewEnemy(index,party,enemies)
end
return -1
end
This was posted in response to someone asking a similar question, where the bolded part is to be added to line 4269 in PokeBattle_AI in v.17.2.
I don't quite understand what the snippet implies but I think it's referring to any trainer's last Pokémon listed. Upon testing this with and without
the added code, I can confirm the AI always holds the last Pokémon specified in the PBS trainer's party until they have nothing left.
 
Last edited:

MGriffin

Trainer
Member
Posts
91
#2
Here's my guess of how this works:

enemies is a list of all the Pokémon that are to be considered for switching in (pbChooseBestNewEnemy will pick only from enemies). The bold part says "don't put the last Pokémon in the enemy list" (i != party.length-1) "unless there are no Pokémon in the enemy list" (|| enemies.length==0). This works because we are looping through the party from first to last (for i in 0..party.length-1), so if we are at the last Pokémon and the list is empty this means that only the last Pokémon is eligible to switch in (if pbCanSwitchLax?(index,i,false)).
 
Top