Trainer Battle Scripts
Next we're going to move on to
trainer battles, the command for these isn't as straightforward as it seems at first glance.
Code:
trainerbattle 0x[Type Of Battle] 0x[Trainer's ID in Hex] 0x0
You can find a trainer's hex ID in any trainer editing tool, but what do I mean by "type of battle"? I'm going to list these one at a time. As I'm covering both FireRed
[FR] and Emerald
[EM], keep in mind that FR has the
VS Seeker whereas EM has the
Match Call function instead, so some types of trainer battle may not work correctly in a certain ROM.
trainerbattle 0x0 [FR] [EM]
This battle type is exactly the same in FR as it is in EM, used for standard trainer battles. Here's an example script:
Avara said:
#org @start
trainerbattle 0x0 0x001 0x0 @EncounterText @DefeatText
msgbox @AfterBattle 0x6
end
#org @EncounterText
= I challenge you!
#org @DefeatText
= You beat me[.]
#org @AfterBattle
= I'll say this after you've\nbattled me.
We're just using Trainer ID
0x001 for the sake of consistency.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x1 [FR] [EM]
0x1 is used for Gym Leaders in both FR and EM. If you open up a Gym Leader's script in your ROM of choice you'll be able to see that there's quite a bit going on, such as setting or clearing trainerflags (this is mainly done to ensure any unbattled Gym trainers don't try to fight you when you're on your way out after beating the Leader). For this example script, we don't have any of that, just a basic Gym Battle that ends in the player receiving a Badge and TM as a reward for winning:
Avara said:
#org @start
lock
faceplayer
checkflag 0x231
if 0x1 goto @Defeated
trainerbattle 0x1 0x001 0x0 @EncounterText @DefeatText @WonPointer
release
end
#org @Defeated
msgbox @AfterBattle 0x6
release
end
#org @WonPointer
msgbox @BadgeInfomsg 0x6
fanfare 0x171
preparemsg @ReceivedBadgemsg
waitmsg
waitfanfare
checkitemroom 0x121 0x1
compare LASTRESULT 0x0
if 0x1 goto @BagFull
additem 0x121 0x1
msgbox @ReceivedTMmsg 0x4
closeonkeypress
setflag 0x231
msgbox @TMInfomsg 0x6
release
end
#org @BagFull
msgbox @BagFullmsg 0x6
release
end
#org @EncounterText
= I challenge you!
#org @DefeatText
= You beat me[.]
#org @AfterBattle
= I'll say this after you've\nbattled me.
#org @BadgeInfomsg
= Please, take the X Badge and this\nTM!
#org @ReceivedBadgemsg
= [player] received the X Badge\nfrom the Gym Leader.
#org @ReceivedTMmsg
= [player] received TMX!
#org @TMInfomsg
= TM01 contains X move!
#org @BagFullmsg
= You don't have enough space in\nyour bag.
Just like before, we've got pointers for the initial encounter text, the message that displays when you win the battle and for after the battle. Although the Gen III games have special flags set aside for Badge functionality, I used
0x231 here for the sake of easiness, as well as Trainer ID
0x001 again. Notice that beside
@DefeatText we have
@WonPointer which contains the section of the script that rewards the player.
fanfare 0x171 is the jingle played in Emerald when a Gym battle is won. If you've been paying close attention or have scripting experience already, you should know what everything else is for by now!
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x2 [EM]
This battle type isn't used in FireRed. It's used with the PokéNav's Match Call rematches - see the Emerald section of trainerbattle 0x5.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x3 [FR] [EM]
0x3 is unique in that it allows the script to continue once the player wins the battle, as opposed to displaying a few messages and ending.
Avara said:
...
trainerbattle 0x3 0x001 0x0 @DefeatText
...
#org @DefeatText
= You beat me[.]
Substitute the "
..."'s for whatever you like and that's pretty much it! All you need is a trainer ID and a pointer to the defeat text.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x4 [FR] [EM]
This one is used for standard double battles and is set up the same way in both FireRed and Emerald.
Avara said:
#org @start
trainerbattle 0x4 0x001 0x0 @EncounterText @DefeatText @OnlyOnePoke
msgbox @AfterBattle 0x6
end
#org @EncounterText
= We challenge you!
#org @DefeatText
= You beat us[.]
#org @AfterBattle
= We'll say this after you've\nbattled us.
#org @OnlyOnePoke
= You can't double battle with only\none Pokémon!
The trainerbattle commands concerning double battles have a nice built-in check - if the player only has one party member, the battle won't happen.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x5 [FR] [EM]
0x5 has different uses depending on your ROM.
[FR] In FireRed, it's used for VS Seeker rematches.
Avara said:
#org @start
trainerbattle 0x0 0x001 0x0 @EncounterText1 @DefeatText
special2 LASTRESULT 0x39
compare LASTRESULT 0x1
if 0x1 goto @RematchPointer
msgbox @AfterBattle 0x6
end
#org @RematchPointer
trainerbattle 0x5 0x001 0x0 @EncounterText2 @DefeatText
msgbox @AfterBattle 0x6
end
#org @EncounterText1
= I challenge you!
#org @EncounterText2
= I challenge you again!
#org @DefeatText
= You beat me[.]
#org @AfterBattle
= I'll say this after you've\nbattled me.
The first part closely resembles a standard trainer battle, using
trainerbattle 0x0 and its usual parameters. The
special2 LASTRESULT 0x39 and the following couple of lines correspond to the VS Seeker - don't worry too much about that for now!
@RematchPointer contains, as labelled, our rematch - which is set up exactly the same as a standard battle, except we've used
trainerbattle 0x5 as our prefix instead.
[EM] In Emerald, we don't have the VS Seeker - we've got Match Call instead. For single rematches, we'd need a script like this:
Avara said:
#org @start
trainerbattle 0x2 0x001 0x0 @EncounterText1 @DefeatText1 @NavPointer
special2 LASTRESULT 0x3C
compare LASTRESULT 0x1
if 0x1 goto @RematchPointer
msgbox @AfterBattle 0x6
release
end
#org @NavPointer
special 0x207
waitmovement 0x0
msgbox @PokenavMsg 0x6
setvar 0x8004 0x001
special 0x1E9
registernav 0x001
release
end
#org @RematchPointer
trainerbattle 0x5 0x001 0x0 @EncounterText2 @DefeatText2
msgbox @AfterBattle 0x6
end
#org @EncounterText1
= I challenge you!
#org @DefeatText1
= You beat me[.]
#org @PokenavMsg
= Do you have a PokéNav?
#org @EncounterText2
= I challenge you again!
#org @DefeatText2
= You beat me again[.]
#org @AfterBattle
= I'll say this after you've\nbattled me.
Again, we're focusing mainly on the battle stuff, so don't worry too much about what the specials are there for. Notice that we've used
trainerbattle 0x2 for the first part, which otherwise looks like a standard battle script; only we've got
@NavPointer at the end to allow this trainer to be registered in the player's PokéNav. Our
@RematchPointer looks the same as a standard trainer battle, only with
0x5 as the battle type instead of 0x0.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x6 [EM]
Do you remember how trainerbattle 0x1, commonly used for Gym Leaders, allowed you to go to an extra pointer
after the defeat text(
"You beat me..."), but
before the default final message(
"I'll say this after you've battled me")? Trainerbattle 0x6 also allows for this in double battles. In EM it's used often with Gabby&Ty. It has no known use in FireRed.
Avara said:
#org @start
trainerbattle 0x6 0x001 0x0 @EncounterText @DefeatText @OnlyOnePoke @ExtraPointer
msgbox @AfterBattle 0x6
release
end
#org @EncounterText
= We challenge you!
#org @DefeatText
= You beat us[.]
#org @AfterBattle
= We'll say this after you've\nbattled us.
#org @OnlyOnePoke
= You can't double battle with only\none Pokémon!
#org @ExtraPointer
...
Seems familiar by now, right? At least, I hope it does =P
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x7 [FR] [EM]
This type of trainerbattle has different uses in either ROM.
[FR] In FR 0x7 tied to the VS Seeker, this time for double battle rematches! It's used in conjunction with trainerbattle 0x4, like this:
Avara said:
#org @start
trainerbattle 0x4 0x001 0x0 @EncounterText1 @DefeatText @OnlyOnePoke
special2 LASTRESULT 0x39
compare LASTRESULT 0x1
if 0x1 goto @RematchPointer
msgbox @AfterBattle 0x6
end
#org @RematchPointer
trainerbattle 0x7 0x001 0x0 @EncounterText2 @DefeatText @OnlyOnePoke
msgbox @AfterBattle 0x6
end
#org @EncounterText1
= We challenge you!
#org @EncounterText2
= We challenge you again!
#org @DefeatText
= You beat us[.]
#org @AfterBattle
= We'll say this after you've\nbattled us.
#org @OnlyOnePoke
= You can't double battle with only\none Pokémon!
It's similar to the single VS Seeker battle script, only it has the built-in check to ensure the player can't take part in the double battle with a single Pokémon.
[EM] In Emerald, trainerbattle 0x7 is used with 0x4 and 0x8 for double battle rematches through Match Call.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x8 [EM]
The only instance I can think of for trainerbattle 0x8 is Tate & Liza's Gym - seeing as all the Gym Leaders have double battle rematches in EM, it's used with 0x7. So, it's like a double Gym battle followed by a double battle rematch.
Avara said:
#org @start
trainerbattle 0x8 0x001 0x0 @EncounterText1 @DefeatText @OnlyOnePoke @ExtraPointer
special2 LASTRESULT 0x3C
compare LASTRESULT 0x1
if 0x1 goto @RematchPointer
msgbox @AfterBattle 0x6
release
end
#org @ExtraPointer
fanfare 0x171
preparemsg @ReceivedBadgemsg
waitmsg
waitfanfare
...
release
end
#org @RematchPointer
trainerbattle 0x7 0x001 0x0 @EncounterText2 @DefeatText @OnlyOnePoke
msgbox @AfterBattle 0x6
end
#org @EncounterText1
= We challenge you!
#org @EncounterText2
= We challenge you again!
#org @DefeatText
= You beat us[.]
#org @AfterBattle
= We'll say this after you've\nbattled us.
#org @OnlyOnePoke
= You can't double battle with only\none Pokémon!
#org @ReceivedBadgemsg
= [player] received the X Badge\nfrom the Gym Leaders.
-----------------------------------------------------------------------------------------------------------------------------------------------------
trainerbattle 0x9 [FR]
Not used in Emerald, trainerbattle 0x9 is a FR-exclusive that's used for your first rival battle in Oak's Lab. Let's have a look:
Avara said:
...
trainerbattle 0x9 0x001 0x0 @DefeatText @WinText
...
#org @DefeatText
= You beat me[.]
#org @WinText
= I'm the best!
It's quite similar to
trainerbattle 0x3 in that you can safely have whatever you want before and after it.
@DefeatText will display if the opponent loses as usual, but
@WinText will display if the opponent wins against the player. Why have I got a
special 0x0 after the battle? That special silently heals the player's Pokémon, so that it's safe for them to go on if they lose.
Not only does it let you display different end-of-battle text depending on whether or not the player loses, it also displays Professor Oak's tutorial-text during the battle.
What if you want to remove Oak's commentary? It's extremely easy - open your FireRed ROM in a hex editor, such as
HxD, and navigate to 080484. Fill the next 8 bytes with 0s like so:
Hit save and test. Bye, Oak!
-----------------------------------------------------------------------------------------------------------------------------------------------------