- 44
- Posts
- 7
- Years
- Seen Oct 8, 2022
How to make gym leaders non-linear
I have been working on and off on an open world gen3 pokemon rom hack since 2013. The idea was to make the world available from the beginning and have the trainers fight the gym leaders in any order they would like. However, this never happened because I could not figure out a way to make it happen, and everyone in the pokemon rom hacking community said it was impossible. Then came Pokemon Crystal Clear. I thought, okay, if this person could do it in Gen2, then I should be able to do it in Gen3.
That was about two years ago. Latley I spent several days thinking about the process and then it hit me. Instead of an extremely long algorithm to check and see which badge was obtained and from where, lets make a system where EVERY gym could give you badge 1-8. That would be much easier and less code too!
In this tutorial I will be showing you how to make every gym leader available to give you badges 1-8 at any time. It would be up to you to edit the pokemon they have with the given level difficulty. You can also do the same thing with the trainers in the gyms, but I think I will opt out and just remove them all together to save me time.
Tools Needed:
Advance Map
Free Space Finder
Advance Trainer
Script Editor (XSE in this tutorial)
PLEASE!!! Make sure you type ALL changes into a Text document first BEFORE you put it into your rom. Some names we will be 'Find and Replace'ing to make this easier.
In this document we will be covering the second gym leader. Before making changes to the second gym COPY ALL THE GYM BATTLE CODE into a text document for editing. You can continue this process for any and all trainers needed.
Intro
Let me begin by explaining something, and if you are a veteran in the pokemon hacking community, you probably know this, but every subroutine (or #org) has a set amount of data it can hold. You can tweak it a little bit, but if you hit the limit (which is very easy to do) you will get overflow and errors. It is always good to make a new directory when creating these custom trainer activities, which are quite large (300+ lines for each one).
Let's begin by looking at a standard gym leader code, Misty.
It is 159 lines, has lots of flags, and lots of checks, with one trainer battle.
"#org 0x16AAA1" – this is the name of the code that is running
"special 0x174" this says we need to check to see if the battle is completed or not
"trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x816AAD3" This is the trainer battle, the trainer ID, the Text before the battle, the text when you win the battle and what runs when you win battle.
These three are important as we are going to be modifying this a little bit.
First we need to set up and check our own flags, the gym badges flags.
0x820 is the flag for badge 1
0x821 is badge two
0x822 is badge three, and so on.
We need to modify the first section of code to check for badges before we decide which battle needs to commence.
changes to
You may notice that I have changed the redirection of the goto's to a shortened @b1, @b2, @b3 and so on. I did this so it is easy for us to search/replace later. These are shorthand for Battle1 (gym badge 1), Battle2, etc.
Before we get too far into this, we need to paste the data we removed into another section.
This section we are going to need to gather same data from for later.
First, this section is for the 2nd gym battle, so the trainerbattle line can be copied for later and used for the second gym.
Inside this line of code we will need to gather a couple numbers for later when we do the find and replace. The number following the fourth '0x' in this line is what is known as the Text Before The Battle. I am going to be keeping this the same for all the battles, but if you want to change this later you can. For now, jot down this number for later, as we will be replacing the placeholder of 'BEFOREBATTLETEXT' with that number. The second number we need to save is the number following the fifth '0x' in this line. This is what is known as the Winning Text. This text, again, I am keeping the same for all the battles. Write down this number as we will be replacing the placeholder 'IFWINTEXT' with it later.
Second, jot down the checkflag number after the 0x. This will be needed for later for the find and replace. The name that will be in its placeholder is 'BattleCheckFlag'.
Third is the number that follows the goto 0x line of code. This is also part of the find and replace later, its placeholder will be 'AFTERFLAGTEST'.
Finally is the msgbox line. This is the line of text that is given after the battle is won and the trainer has received the badge. Save the number following 0x as this will also be part of the find and replace later. Its placeholder will be 'MSGBXATEND'
--------------------
With the information gathered above we should have this typed out in a separate text document
BEFOREBATTLETEXT : 81921EF
IFWINTEXT : 819242D
BattleCheckFlag: 297
AFTERFLAGTEST: 816AAF9
MSGBXATEND: 81922BF
Now comes the fun part, we are going to be hard-coding in these battles. You can do so by copy and pasting the below text into your text document under the first section of our created code.
If you notice I have left the second battle basically the same. The ID is the same and the other codes are the same, that is because I plan on reusing the existing battle for the second gym leader. If you want to edit this you can later.
In the above code you will notice that every trainer battle as similar code:
The second '0x' is labeled as BATTLEID. This is the trainer id of the trainer for the battle. You will need to create your own trainer ID for this battle using the Trainer Editor if you have not done so already. Every one needs to be different, so go through and make 8 different trainers for each gym. You can do this now, or wait till later. I would suggest now though, because you will need to repoint the information to a new location and you do not want to over write your work. However, it looks like that there is an empty range of trainer data from 01E to 04D. You can use those as a place holder for now.
The next section in this line of code we need to look at is @b1e. This is short hand for Battle1End. This is the ending code, which will set the flag for the gym badge, that each battle needs to have. That is the next section we will be editing.
All of this code pretty much stays the same, except we are going to change the name of the #org and the badge that is given, like so:
One final thing we want to add in is what happens if the gym leader has already been defeated. Normally this is handled by checking for their badge, but since we can no longer go off of this we are going to make our own.
First, start by copying the section that we used for AFTERFLAGTEST. It should look like this:
We are going to change this to the following, while changing the name to '@ENDTEXT'
if you noticed, we took out almost all of the code. That is because if we left all that in the player would be able to farm TMs forever. Keeping this as just a messagebox removes that possibility.
That's it! From here the rest of the code we are not changing so we can leave the same triggers and names alone.
The copied code should look like this:
Find and Replace
Now we are going to do the first part of Find and Replace. In the text document you are working in go to Edit> Replace. You are now going to replace all the values we mentioned ealier that you jotted down from the original code: Find and replace every one of them listed below.
BEFOREBATTLETEXT : 81921EF
IFWINTEXT : 819242D
BattleCheckFlag: 297
AFTERFLAGTEST: 816AAF9
MSGBXATEND: 81922BF
(as a side note, for me it always pasted my values with a space after the '0x'. To fix this, I did a search and replaced '0x ' with '0x')
Next, scroll down and replace all the 'BATTLEID' with the correct trainer ID's, if you have not already done so. Remember, if you need a placeholder for now, you can use the gym leander's trainer ID or use '01E'.
Once you have this code we need to make a new location to house the data. This is simple to do. Open up the Free Space Finder application and search for something that is 1500 bites. This should give you enough room to play around with. When you find that number, jot it down. We will need it in a minute. For me, it was : 804C2C
With this new code replace the second line 'OFFSET' with the new code (804C2C).
Head on over to Advance Map and locate your gym leader (Misty). Select here and change her offset to the offset above (for me, 804C2C) and click 'Open Script'. A new script should be created. Copy and paste all your values into this new script.
Once pasted, if there is a duplicate '#org 0x804C2C', remove it. Your code should look something like this for the first six lines:
Once transferred go into your script editor and click the 'Compile' button. If there are any errors, fix them. You will eventually be greeted with a window that has several offsets at the bottom. If you do not see a log window appear, make sure you have it enabled and try again.
To make it easier, when the Compiler Output window is opened, scroll down to almost the bottom. The section before the 'Cleaning up…' line is your offsets that need to be changed. Copy and paste these into a new text document for easy reference. Mine looked like this:
DYNAMIC_OFFSET 1
> sLabel = @b1
> lOffset = 0x801485
DYNAMIC_OFFSET 2
> sLabel = @b2
> lOffset = 0x801514
DYNAMIC_OFFSET 3
> sLabel = @b3
> lOffset = 0x80153A
DYNAMIC_OFFSET 4
> sLabel = @b4
> lOffset = 0x801560
DYNAMIC_OFFSET 5
> sLabel = @b5
> lOffset = 0x801586
DYNAMIC_OFFSET 6
> sLabel = @b6
> lOffset = 0x8015AC
DYNAMIC_OFFSET 7
> sLabel = @b7
> lOffset = 0x8015D2
DYNAMIC_OFFSET 8
> sLabel = @b8
> lOffset = 0x801614
DYNAMIC_OFFSET 9
> sLabel = @b1e
> lOffset = 0x80163A
DYNAMIC_OFFSET 10
> sLabel = @b2e
> lOffset = 0x801660
DYNAMIC_OFFSET 11
> sLabel = @b3e
> lOffset = 0x801686
DYNAMIC_OFFSET 12
> sLabel = @b4e
> lOffset = 0x8016AC
DYNAMIC_OFFSET 13
> sLabel = @b5e
> lOffset = 0x8016D2
DYNAMIC_OFFSET 14
> sLabel = @b6e
> lOffset = 0x801714
DYNAMIC_OFFSET 15
> sLabel = @b7e
> lOffset = 0x80173A
DYNAMIC_OFFSET 16
> sLabel = @b8e
> lOffset = 0x801760
> sLabel = @endtext
> lOffset = 0x804C7F
Now that we have the offsets, you guessed it, we are going to have to search and replace every one of the @b1's and @b1e's. Because @b1 has the same text in the name of @b1e, I would suggest you work backwards, starting at @b8e and going through @b1, that way you do not double overwrite things. Go through the list and do a search/find and replace.
Once the list has been searched and replaced, copy and paste your text document back into your script editor and click compile. If the Complier Output window opens without the 'offset' list at the bottom then everything worked perfectly! Click the Level Script button to flatten out your code and you are good to go.
You can now close out of your script editor, save the rom in the Map Editor and test out your gym battle.
final code - once compiled (misty):
Images:
I have been working on and off on an open world gen3 pokemon rom hack since 2013. The idea was to make the world available from the beginning and have the trainers fight the gym leaders in any order they would like. However, this never happened because I could not figure out a way to make it happen, and everyone in the pokemon rom hacking community said it was impossible. Then came Pokemon Crystal Clear. I thought, okay, if this person could do it in Gen2, then I should be able to do it in Gen3.
That was about two years ago. Latley I spent several days thinking about the process and then it hit me. Instead of an extremely long algorithm to check and see which badge was obtained and from where, lets make a system where EVERY gym could give you badge 1-8. That would be much easier and less code too!
In this tutorial I will be showing you how to make every gym leader available to give you badges 1-8 at any time. It would be up to you to edit the pokemon they have with the given level difficulty. You can also do the same thing with the trainers in the gyms, but I think I will opt out and just remove them all together to save me time.
Tools Needed:
Advance Map
Free Space Finder
Advance Trainer
Script Editor (XSE in this tutorial)
PLEASE!!! Make sure you type ALL changes into a Text document first BEFORE you put it into your rom. Some names we will be 'Find and Replace'ing to make this easier.
In this document we will be covering the second gym leader. Before making changes to the second gym COPY ALL THE GYM BATTLE CODE into a text document for editing. You can continue this process for any and all trainers needed.
Intro
Let me begin by explaining something, and if you are a veteran in the pokemon hacking community, you probably know this, but every subroutine (or #org) has a set amount of data it can hold. You can tweak it a little bit, but if you hit the limit (which is very easy to do) you will get overflow and errors. It is always good to make a new directory when creating these custom trainer activities, which are quite large (300+ lines for each one).
Let's begin by looking at a standard gym leader code, Misty.
Spoiler:
Code:
'---------------
#org 0x16AAA1
setvar 0x8004 0x3
setvar 0x8005 0x2
special 0x174
trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x816AAD3
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x16AAD3
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x821
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x16AAF9
msgbox 0x81922F7 MSG_KEEPOPEN '"The CASCADEBADGE makes all\nPOKéMO..."
checkitemroom 0x123 0x1
compare LASTRESULT 0x0
if 0x1 goto 0x816AB3A
additem 0x123 0x1
loadpointer 0x0 0x81923F1 '"[player] received TM03\nfrom MISTY..."
giveitem2 0x123 0x1 0x101
setflag 0x297
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x1A6B18
copyvar 0x8000 0x8008
compare 0x8000 0x1
if 0x1 goto 0x81A6B76
compare 0x8000 0x2
if 0x1 goto 0x81A6B7A
compare 0x8000 0x3
if 0x1 goto 0x81A6B81
compare 0x8000 0x4
if 0x1 goto 0x81A6B8B
compare 0x8000 0x5
if 0x1 goto 0x81A6BA1
compare 0x8000 0x6
if 0x1 goto 0x81A6BB4
compare 0x8000 0x7
if 0x1 goto 0x81A6BCA
compare 0x8000 0x8
if 0x1 goto 0x81A6BE0
end
'---------------
#org 0x16AB3A
msgbox 0x819240E MSG_KEEPOPEN '"You better make room for this!"
release
end
'---------------
#org 0x1A6B76
cleartrainerflag 0x8E
return
'---------------
#org 0x1A6B7A
cleartrainerflag 0x96
cleartrainerflag 0xEA
return
'---------------
#org 0x1A6B81
cleartrainerflag 0x8D
cleartrainerflag 0xDC
cleartrainerflag 0x1A7
return
'---------------
#org 0x1A6B8B
cleartrainerflag 0x84
cleartrainerflag 0x85
cleartrainerflag 0xA0
cleartrainerflag 0x109
cleartrainerflag 0x10A
cleartrainerflag 0x10B
cleartrainerflag 0x192
return
'---------------
#org 0x1A6BA1
cleartrainerflag 0x126
cleartrainerflag 0x127
cleartrainerflag 0x120
cleartrainerflag 0x121
cleartrainerflag 0x124
cleartrainerflag 0x125
return
'---------------
#org 0x1A6BB4
cleartrainerflag 0x118
cleartrainerflag 0x119
cleartrainerflag 0x11A
cleartrainerflag 0x11B
cleartrainerflag 0x1CE
cleartrainerflag 0x1CF
cleartrainerflag 0x1D0
return
'---------------
#org 0x1A6BCA
cleartrainerflag 0xB1
cleartrainerflag 0xB2
cleartrainerflag 0xB3
cleartrainerflag 0xB4
cleartrainerflag 0xD5
cleartrainerflag 0xD6
cleartrainerflag 0xD7
return
'---------------
#org 0x1A6BE0
cleartrainerflag 0x128
cleartrainerflag 0x129
cleartrainerflag 0x142
cleartrainerflag 0x143
cleartrainerflag 0x144
cleartrainerflag 0x188
cleartrainerflag 0x190
cleartrainerflag 0x191
return
'---------
' Strings
'---------
#org 0x1921EF
= Hi, you're a new face!\pOnly those TRAINERS who have a\npolicy about POKéMON can turn pro.\pWhat is your approach when you\ncatch and train POKéMON?\pMy policy is an all-out offensive\nwith WATER-type POKéMON!\c\h0B[Ke]À
#org 0x19242D
= Wow!\nYou're too much!\pAll right!\pYou can have the CASCADEBADGE to\nshow you beat me.
#org 0x1922BF
= TM03 teaches WATER PULSE.\pUse it on an aquatic POKéMON!
#org 0x1922F7
= The CASCADEBADGE makes all\nPOKéMON up to Lv. 30 obey.\pThat includes even outsiders you\ngot in trades.\pThere's more. You can now use CUT\nanytime, even out of battle.\pYou can CUT down small trees to\nopen new pathways.\pYou can also have my favorite TM.
#org 0x1923F1
= [player] received TM03\nfrom MISTY.
#org 0x19240E
= You better make room for this!
It is 159 lines, has lots of flags, and lots of checks, with one trainer battle.
"#org 0x16AAA1" – this is the name of the code that is running
"special 0x174" this says we need to check to see if the battle is completed or not
"trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x816AAD3" This is the trainer battle, the trainer ID, the Text before the battle, the text when you win the battle and what runs when you win battle.
These three are important as we are going to be modifying this a little bit.
First we need to set up and check our own flags, the gym badges flags.
0x820 is the flag for badge 1
0x821 is badge two
0x822 is badge three, and so on.
We need to modify the first section of code to check for badges before we decide which battle needs to commence.
Code:
#org 0x16AAA1
setvar 0x8004 0x3
setvar 0x8005 0x2
special 0x174
trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x816AAD3
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
changes to
Code:
#dynamic 0x800000
#org 0xOFFSET
setvar 0x8004 0x3
setvar 0x8005 0x2
special 0x174
checkflag 0xBattleCheckFlag
if 0x1 goto @ENDTEXT
checkflag 0x820
if 0x0 goto @b1
checkflag 0x821
if 0x0 goto @b2
checkflag 0x822
if 0x0 goto @b3
checkflag 0x823
if 0x0 goto @b4
checkflag 0x824
if 0x0 goto @b5
checkflag 0x825
if 0x0 goto @b6
checkflag 0x826
if 0x0 goto @b7
checkflag 0x827
if 0x0 goto @b8
release
end
You may notice that I have changed the redirection of the goto's to a shortened @b1, @b2, @b3 and so on. I did this so it is easy for us to search/replace later. These are shorthand for Battle1 (gym badge 1), Battle2, etc.
Before we get too far into this, we need to paste the data we removed into another section.
Code:
trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x816AAD3
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
This section we are going to need to gather same data from for later.
First, this section is for the 2nd gym battle, so the trainerbattle line can be copied for later and used for the second gym.
Inside this line of code we will need to gather a couple numbers for later when we do the find and replace. The number following the fourth '0x' in this line is what is known as the Text Before The Battle. I am going to be keeping this the same for all the battles, but if you want to change this later you can. For now, jot down this number for later, as we will be replacing the placeholder of 'BEFOREBATTLETEXT' with that number. The second number we need to save is the number following the fifth '0x' in this line. This is what is known as the Winning Text. This text, again, I am keeping the same for all the battles. Write down this number as we will be replacing the placeholder 'IFWINTEXT' with it later.
Second, jot down the checkflag number after the 0x. This will be needed for later for the find and replace. The name that will be in its placeholder is 'BattleCheckFlag'.
Third is the number that follows the goto 0x line of code. This is also part of the find and replace later, its placeholder will be 'AFTERFLAGTEST'.
Finally is the msgbox line. This is the line of text that is given after the battle is won and the trainer has received the badge. Save the number following 0x as this will also be part of the find and replace later. Its placeholder will be 'MSGBXATEND'
--------------------
With the information gathered above we should have this typed out in a separate text document
BEFOREBATTLETEXT : 81921EF
IFWINTEXT : 819242D
BattleCheckFlag: 297
AFTERFLAGTEST: 816AAF9
MSGBXATEND: 81922BF
Now comes the fun part, we are going to be hard-coding in these battles. You can do so by copy and pasting the below text into your text document under the first section of our created code.
Spoiler:
Code:
#org @b1
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b1e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b2
trainerbattle 0x1 0x19F 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b2e
checkflag 0x297
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b3
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b3e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b4
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b4e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b5
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b5e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b6
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b6e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b7
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b7e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN '"There are all kinds of TRAINERS in..."
release
end
#org @b8
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b8e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
'---------------
If you notice I have left the second battle basically the same. The ID is the same and the other codes are the same, that is because I plan on reusing the existing battle for the second gym leader. If you want to edit this you can later.
In the above code you will notice that every trainer battle as similar code:
Code:
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b1e
The second '0x' is labeled as BATTLEID. This is the trainer id of the trainer for the battle. You will need to create your own trainer ID for this battle using the Trainer Editor if you have not done so already. Every one needs to be different, so go through and make 8 different trainers for each gym. You can do this now, or wait till later. I would suggest now though, because you will need to repoint the information to a new location and you do not want to over write your work. However, it looks like that there is an empty range of trainer data from 01E to 04D. You can use those as a place holder for now.
The next section in this line of code we need to look at is @b1e. This is short hand for Battle1End. This is the ending code, which will set the flag for the gym badge, that each battle needs to have. That is the next section we will be editing.
Code:
'---------------
#org 0x16AAD3
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x821
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
All of this code pretty much stays the same, except we are going to change the name of the #org and the badge that is given, like so:
Spoiler:
Code:
'---------------
#org @b1e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x820
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b2e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x821
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b3e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x822
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b4e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x823
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b5e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x824
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b6e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x825
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b7e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x826
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b8e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x827
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
One final thing we want to add in is what happens if the gym leader has already been defeated. Normally this is handled by checking for their badge, but since we can no longer go off of this we are going to make our own.
First, start by copying the section that we used for AFTERFLAGTEST. It should look like this:
Code:
#org 0xAFTERFLAGTEST
msgbox 0x81922F7 MSG_KEEPOPEN '"The CASCADEBADGE makes all\nPOKéMO..."
checkitemroom 0x123 0x1
compare LASTRESULT 0x0
if 0x1 goto 0x816AB3A
additem 0x123 0x1
loadpointer 0x0 0x81923F1 '"[player] received TM03\nfrom MISTY..."
giveitem2 0x123 0x1 0x101
setflag 0x297
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
We are going to change this to the following, while changing the name to '@ENDTEXT'
Code:
#org @ENDTEXT
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
if you noticed, we took out almost all of the code. That is because if we left all that in the player would be able to farm TMs forever. Keeping this as just a messagebox removes that possibility.
That's it! From here the rest of the code we are not changing so we can leave the same triggers and names alone.
The copied code should look like this:
Spoiler:
Code:
#dynamic 0x800000
#org 0xOFFSET
checkflag 0xBattleCheckFlag
if 0x1 goto @ENDTEXT
checkflag 0x820
if 0x0 goto @b1
checkflag 0x821
if 0x0 goto @b2
checkflag 0x822
if 0x0 goto @b3
checkflag 0x823
if 0x0 goto @b4
checkflag 0x824
if 0x0 goto @b5
checkflag 0x825
if 0x0 goto @b6
checkflag 0x826
if 0x0 goto @b7
checkflag 0x827
if 0x0 goto @b8
release
end
#org @b1
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b1e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b2
trainerbattle 0x1 0x19F 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b2e
checkflag 0x297
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b3
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b3e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b4
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b4e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b5
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b5e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b6
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b6e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
#org @b7
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b7e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN '"There are all kinds of TRAINERS in..."
release
end
#org @b8
trainerbattle 0x1 0xBATTLEID 0x0 0xBEFOREBATTLETEXT 0xIFWINTEXT @b8e
checkflag 0xBattleCheckFlag
if 0x0 goto 0xAFTERFLAGTEST
msgbox 0xMSGBXATEND MSG_KEEPOPEN
release
end
'---------------
#org @b1e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x820
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b2e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x821
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b3e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x822
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b4e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x823
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b5e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x824
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b6e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x825
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b7e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x826
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @b8e
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x827
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org @ENDTEXT
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
Find and Replace
Now we are going to do the first part of Find and Replace. In the text document you are working in go to Edit> Replace. You are now going to replace all the values we mentioned ealier that you jotted down from the original code: Find and replace every one of them listed below.
BEFOREBATTLETEXT : 81921EF
IFWINTEXT : 819242D
BattleCheckFlag: 297
AFTERFLAGTEST: 816AAF9
MSGBXATEND: 81922BF
(as a side note, for me it always pasted my values with a space after the '0x'. To fix this, I did a search and replaced '0x ' with '0x')
Next, scroll down and replace all the 'BATTLEID' with the correct trainer ID's, if you have not already done so. Remember, if you need a placeholder for now, you can use the gym leander's trainer ID or use '01E'.
Once you have this code we need to make a new location to house the data. This is simple to do. Open up the Free Space Finder application and search for something that is 1500 bites. This should give you enough room to play around with. When you find that number, jot it down. We will need it in a minute. For me, it was : 804C2C
With this new code replace the second line 'OFFSET' with the new code (804C2C).
Head on over to Advance Map and locate your gym leader (Misty). Select here and change her offset to the offset above (for me, 804C2C) and click 'Open Script'. A new script should be created. Copy and paste all your values into this new script.
Once pasted, if there is a duplicate '#org 0x804C2C', remove it. Your code should look something like this for the first six lines:
Code:
'---------------
#dynamic 0x800000
#org 0x804C2C
checkflag 0x297
if 0x1 goto 0x8804C7F
checkflag 0x820
Once transferred go into your script editor and click the 'Compile' button. If there are any errors, fix them. You will eventually be greeted with a window that has several offsets at the bottom. If you do not see a log window appear, make sure you have it enabled and try again.
To make it easier, when the Compiler Output window is opened, scroll down to almost the bottom. The section before the 'Cleaning up…' line is your offsets that need to be changed. Copy and paste these into a new text document for easy reference. Mine looked like this:
Spoiler:
DYNAMIC_OFFSET 1
> sLabel = @b1
> lOffset = 0x801485
DYNAMIC_OFFSET 2
> sLabel = @b2
> lOffset = 0x801514
DYNAMIC_OFFSET 3
> sLabel = @b3
> lOffset = 0x80153A
DYNAMIC_OFFSET 4
> sLabel = @b4
> lOffset = 0x801560
DYNAMIC_OFFSET 5
> sLabel = @b5
> lOffset = 0x801586
DYNAMIC_OFFSET 6
> sLabel = @b6
> lOffset = 0x8015AC
DYNAMIC_OFFSET 7
> sLabel = @b7
> lOffset = 0x8015D2
DYNAMIC_OFFSET 8
> sLabel = @b8
> lOffset = 0x801614
DYNAMIC_OFFSET 9
> sLabel = @b1e
> lOffset = 0x80163A
DYNAMIC_OFFSET 10
> sLabel = @b2e
> lOffset = 0x801660
DYNAMIC_OFFSET 11
> sLabel = @b3e
> lOffset = 0x801686
DYNAMIC_OFFSET 12
> sLabel = @b4e
> lOffset = 0x8016AC
DYNAMIC_OFFSET 13
> sLabel = @b5e
> lOffset = 0x8016D2
DYNAMIC_OFFSET 14
> sLabel = @b6e
> lOffset = 0x801714
DYNAMIC_OFFSET 15
> sLabel = @b7e
> lOffset = 0x80173A
DYNAMIC_OFFSET 16
> sLabel = @b8e
> lOffset = 0x801760
> sLabel = @endtext
> lOffset = 0x804C7F
Now that we have the offsets, you guessed it, we are going to have to search and replace every one of the @b1's and @b1e's. Because @b1 has the same text in the name of @b1e, I would suggest you work backwards, starting at @b8e and going through @b1, that way you do not double overwrite things. Go through the list and do a search/find and replace.
Once the list has been searched and replaced, copy and paste your text document back into your script editor and click compile. If the Complier Output window opens without the 'offset' list at the bottom then everything worked perfectly! Click the Level Script button to flatten out your code and you are good to go.
You can now close out of your script editor, save the rom in the Map Editor and test out your gym battle.
final code - once compiled (misty):
Spoiler:
Code:
'---------------
#org 0x804C2C
checkflag 0x297
if 0x1 goto 0x8804C7F
checkflag 0x820
if 0x0 goto 0x8801485
checkflag 0x821
if 0x0 goto 0x8801514
checkflag 0x822
if 0x0 goto 0x880153A
checkflag 0x823
if 0x0 goto 0x8801560
checkflag 0x824
if 0x0 goto 0x8801586
checkflag 0x825
if 0x0 goto 0x88015AC
checkflag 0x826
if 0x0 goto 0x88015D2
checkflag 0x827
if 0x0 goto 0x8801614
release
end
'---------------
#org 0x804C7F
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801485
trainerbattle 0x1 0x26 0x0 0x81921EF 0x819242D 0x880163A
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801514
trainerbattle 0x1 0x19F 0x0 0x81921EF 0x819242D 0x8801660
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x80153A
trainerbattle 0x1 0x27 0x0 0x81921EF 0x819242D 0x8801686
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801560
trainerbattle 0x1 0x28 0x0 0x81921EF 0x819242D 0x88016AC
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801586
trainerbattle 0x1 0x29 0x0 0x81921EF 0x819242D 0x88016D2
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x8015AC
trainerbattle 0x1 0x2A 0x0 0x81921EF 0x819242D 0x8801714
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x8015D2
trainerbattle 0x1 0x2B 0x0 0x81921EF 0x819242D 0x880173A
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801614
trainerbattle 0x1 0x2C 0x0 0x81921EF 0x819242D 0x8801760
checkflag 0x297
if 0x0 goto 0x816AAF9
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x80163A
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x820
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x16AAF9
msgbox 0x81922F7 MSG_KEEPOPEN '"The CASCADEBADGE makes all\nPOKéMO..."
checkitemroom 0x123 0x1
compare LASTRESULT 0x0
if 0x1 goto 0x816AB3A
additem 0x123 0x1
loadpointer 0x0 0x81923F1 '"[player] received TM03\nfrom MISTY..."
giveitem2 0x123 0x1 0x101
setflag 0x297
msgbox 0x81922BF MSG_KEEPOPEN '"TM03 teaches WATER PULSE.\pUse it ..."
release
end
'---------------
#org 0x801660
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x821
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x801686
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x822
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x8016AC
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x823
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x8016D2
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x824
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x801714
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x825
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x80173A
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x826
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x801760
setvar 0x8004 0x3
setvar 0x8005 0x1
special 0x173
setflag 0x4B1
setflag 0x827
sethealingplace 0x4
setvar 0x8008 0x2
call 0x81A6B18
goto 0x816AAF9
'---------------
#org 0x1A6B18
copyvar 0x8000 0x8008
compare 0x8000 0x1
if 0x1 goto 0x81A6B76
compare 0x8000 0x2
if 0x1 goto 0x81A6B7A
compare 0x8000 0x3
if 0x1 goto 0x81A6B81
compare 0x8000 0x4
if 0x1 goto 0x81A6B8B
compare 0x8000 0x5
if 0x1 goto 0x81A6BA1
compare 0x8000 0x6
if 0x1 goto 0x81A6BB4
compare 0x8000 0x7
if 0x1 goto 0x81A6BCA
compare 0x8000 0x8
if 0x1 goto 0x81A6BE0
end
'---------------
#org 0x16AB3A
msgbox 0x819240E MSG_KEEPOPEN '"You better make room for this!"
release
end
'---------------
#org 0x1A6B76
cleartrainerflag 0x8E
return
'---------------
#org 0x1A6B7A
cleartrainerflag 0x96
cleartrainerflag 0xEA
return
'---------------
#org 0x1A6B81
cleartrainerflag 0x8D
cleartrainerflag 0xDC
cleartrainerflag 0x1A7
return
'---------------
#org 0x1A6B8B
cleartrainerflag 0x84
cleartrainerflag 0x85
cleartrainerflag 0xA0
cleartrainerflag 0x109
cleartrainerflag 0x10A
cleartrainerflag 0x10B
cleartrainerflag 0x192
return
'---------------
#org 0x1A6BA1
cleartrainerflag 0x126
cleartrainerflag 0x127
cleartrainerflag 0x120
cleartrainerflag 0x121
cleartrainerflag 0x124
cleartrainerflag 0x125
return
'---------------
#org 0x1A6BB4
cleartrainerflag 0x118
cleartrainerflag 0x119
cleartrainerflag 0x11A
cleartrainerflag 0x11B
cleartrainerflag 0x1CE
cleartrainerflag 0x1CF
cleartrainerflag 0x1D0
return
'---------------
#org 0x1A6BCA
cleartrainerflag 0xB1
cleartrainerflag 0xB2
cleartrainerflag 0xB3
cleartrainerflag 0xB4
cleartrainerflag 0xD5
cleartrainerflag 0xD6
cleartrainerflag 0xD7
return
'---------------
#org 0x1A6BE0
cleartrainerflag 0x128
cleartrainerflag 0x129
cleartrainerflag 0x142
cleartrainerflag 0x143
cleartrainerflag 0x144
cleartrainerflag 0x188
cleartrainerflag 0x190
cleartrainerflag 0x191
return
'---------
' Strings
'---------
#org 0x1922BF
= TM03 teaches WATER PULSE.\pUse it on an aquatic POKéMON!
#org 0x1921EF
= Hi, you're a new face!\pOnly those TRAINERS who have a\npolicy about POKéMON can turn pro.\pWhat is your approach when you\ncatch and train POKéMON?\pMy policy is an all-out offensive\nwith WATER-type POKéMON!\c\h0B[Ke]À
#org 0x19242D
= Wow!\nYou're too much!\pAll right!\pYou can have the CASCADEBADGE to\nshow you beat me.
#org 0x1922F7
= The CASCADEBADGE makes all\nPOKéMON up to Lv. 30 obey.\pThat includes even outsiders you\ngot in trades.\pThere's more. You can now use CUT\nanytime, even out of battle.\pYou can CUT down small trees to\nopen new pathways.\pYou can also have my favorite TM.
#org 0x1923F1
= [player] received TM03\nfrom MISTY.
#org 0x19240E
= You better make room for this!
Images:
Last edited: