• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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.

Gen 3 - Scale gyms to let players challenge them in any order - How to make gym leaders non-linear

44
Posts
6
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.


    Spoiler:


    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:


    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:



    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:



    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:


    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:


    Images:
    Spoiler:
     
    Last edited:
    89
    Posts
    4
    Years
    • Seen Jan 17, 2023
    Hey there. Great Job with the script. I just wanted to ask why did you go out of your way to post this in the Fangames section when you are clearly aware that there is an entire section for ROM Hacking Resources which you have been to and posted in earlier.
     
    44
    Posts
    6
    Years
    • Seen Oct 8, 2022
    Ha! I thought I was in that forum. I did think it was strange that it didnt ask me for a game. Oh well. Thank you! I will ask a mod to move it over.
     
    Back
    Top