• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Any way to set the Pokemon Order of a Trainer?

Sure. But you're gonna have to specify how that order should be determined.

Right, what would be the methodes to determine the order? I wanted to determine them by sheer Pokemon alone. Not really by Level or such. Since I wanted to set up certain things for the next Pokemon that follows.
 
I'll leave a few examples below:
Sort by species: $Trainer.party.sort { |a, b| a.species <=> b.species }
Sort by level: $Trainer.party.sort { |a, b| a.level <=> b.level }
 
I'll leave a few examples below:
Sort by species: $Trainer.party.sort { |a, b| a.species <=> b.species }
Sort by level: $Trainer.party.sort { |a, b| a.level <=> b.level }

Nice! I assume I could add more letters, to include a team of six? I don't have any coding expierence so I apologize if I still have questions.
 
a.level and b.level aren't Pokemon, it's just the Syntax Array Sorting for array sorting. Even if the Party has 2 Pokémon or 6, the above code will always sort by level.
 
a.level and b.level aren't Pokemon, it's just the Syntax Array Sorting for array sorting. Even if the Party has 2 Pokémon or 6, the above code will always sort by level.

Makes sense I suppose, but what about the code that sorts by species? That one would sort by species, right?
 
I think you answered yourself:
Okay, let's say I want to sort by species, with
1. Ferrothorn
2. Metagross
3. Scizor
4. Magnezone
5. Steelix
6. Exadrill
In that order, how would that code look like, and where would it have to go?
 
Okay, let's say I want to sort by species, with
1. Ferrothorn
2. Metagross
3. Scizor
4. Magnezone
5. Steelix
6. Exadrill
In that order, how would that code look like, and where would it have to go?

I'm not sure but either in Pokedex order or in Species name alphabetical order.

I think the code goes in PField_EncounterModifiers
 
And how exactly would this code look?

Go in PField_EncounterModifiers and Look for onTrainerPartyLoad and over there where you see 'YOUR CODE HERE' add party.sort{sorting method}
 
Okay, let's say I want to sort by species, with
1. Ferrothorn
2. Metagross
3. Scizor
4. Magnezone
5. Steelix
6. Exadrill
In that order, how would that code look like, and where would it have to go?

Since you have six entries here, does this mean the player could only ever have these 6 Pokémon in the party at this time? If so, you can use the following method:

Code:
order = [
  PBSpecies::FERROTHORN,
  PBSpecies::METAGROSS,
  PBSpecies::SCIZOR,
  PBSpecies::MAGNEZONE,
  PBSpecies::STEELIX,
  PBSpecies::EXCADRILL
]
$Trainer.party.sort { |a, b| order.index(a.species) <=> order.index(b.species) }

Use extendtext.exe if it doesn't fit in your script window.
 
I am sorry, again, no Coding expierence xd. What would I have to do now, to uncomment those lines?
EDIT: Okay I have found out what you mean, however now I got a syntex Error https://imgur.com/ouP8D1X https://imgur.com/VHlDku4

You need to uncomment every line from Events.onTrainerPartyLoad to the last '}'

EDIT: This code will sort the party of every trainer in your game. To fix that add "if $game_switches[123]" before the sort and "end" after the sort. This will make it so that the part will sort only if the switch 123 is on. You can change 123 to whatever you want.
 
Last edited:
Since you have six entries here, does this mean the player could only ever have these 6 Pokémon in the party at this time? If so, you can use the following method:

Code:
order = [
  PBSpecies::FERROTHORN,
  PBSpecies::METAGROSS,
  PBSpecies::SCIZOR,
  PBSpecies::MAGNEZONE,
  PBSpecies::STEELIX,
  PBSpecies::EXCADRILL
]
$Trainer.party.sort { |a, b| order.index(a.species) <=> order.index(b.species) }

Use extendtext.exe if it doesn't fit in your script window.

Ye, the AI Opponent has this exact Team at the time. Should this code go into PField_EncounterModifiers?
 
You need to uncomment every line from Events.onTrainerPartyLoad to the last '}'

EDIT: This code will sort the party of every trainer in your game. To fix that add "if $game_switches[123]" before the sort and "end" after the sort. This will make it so that the part will sort only if the switch 123 is on. You can change 123 to whatever you want.

Right, so I did as you told me, https://imgur.com/TN81ey5 and the Game Launches now, however it doesn't seem to work. I used both the "Species Script" and the "Level Script". A mistake on my end?
 
Right, so I did as you told me, https://imgur.com/TN81ey5 and the Game Launches now, however it doesn't seem to work. I used both the "Species Script" and the "Level Script". A mistake on my end?

Since you're editing an opponent's team, you should use party.sort not $Trainer.party.sort as $Trainer.party references your own party
 
Back
Top