• 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 places on the 'net to talk Pokémon and more! Community members will not see the bottom screen advertisements.
  • Want to share your adventures playing Pokémon?
    Check out our new Travel Journals forum for sharing playthroughs of ROM Hacks, Fan Games, and other Pokémon content!
  • IMPORTANT: Following a takedown request, the following hacks have been delisted from PokéCommunity:

    • Pokémon Glazed
    • Pokémon: Giratina Strikes Back
    • Pokémon Flora Sky
    • Pokémon Stranded
    The downloads and discussion threads for these hacks will no longer be accessible, and staff will be unable to return questions regarding accessing this content.

[pokefirered] Help with Gym Leader Rematch

510
Posts
10
Years
  • Seen Feb 26, 2024
I'm trying to implement the ability to rematch Gym Leaders so that it works the same as rematching the Elite 4, but I'm a noob with pokefirered and its structure so I need help.

I don't know if I'm in the right place, but I was taking a look at data/maps/PokemonLeague_LoreleisRoom/scripts.inc in order to implement in data/maps/PewterCity_Gym/scripts.inc (I've got to have it work at least with Brock before I get into the others), but I don't know what exactly I need to copy.

Thanks in advance.
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
I can help, but what and when would you like to rematch them? anytime? whenever you beat the 4? or after an event? depending on your answer it will let me know how to script their rematch
 
510
Posts
10
Years
  • Seen Feb 26, 2024
Thanks. The idea was to have the ability to rematch them with a new team once you beat the elite four or the champion. But if that's too complicated, their default team will do.
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
Thanks. The idea was to have the ability to rematch them with a new team once you beat the elite four or the champion. But if that's too complicated, their default team will do.
Im currently doing pokeemerald-expansion but im sure pokefirered is similar. What I would do in your case, rematche tables aren't there for Gym leaders. So you would have to add a new entry or edit an existing one of a trainer and change the values to match the leader you want.
Thats number 1.

Number 2, would be to edit the leaders script to check for the champion flag to allow the fight to happen only after becoming champ.

3, after beating blue in the e4, edit its script and add a cleartrainerflag for the leader you want to allow to rematch, that way you can only rematch the leaders after beating blue over and over again.

if any of this doesnt make sense to u, then its gonna be hard, Im great at scripting but just not great at C code, although I love programming, let me know if any of this makes sense to u and I will help you as much as I can, as I've been there. I used to binary hack firered before the decomps came along! Man what a different landscape now!
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
It's #2 that I have a problem with. Or at least how to structure it.
sure, so editing the leader's script to check for champ flag. Im not sure which flag is set when you become champ. Check your flags to see which one is set. In emerald, the flag is called FLAG_IS_CHAMPION. I would add that to the script for Brock (for example)

Code:
script BrockGymLeader
{
    lock
    faceplayer
    if(flag(FLAG_IS_CHAMP) ==TRUE)
    {
        trainerbattle_single(TRAINER_BROCK2, Brock2_Intro, Brock2_Outro, Brock2_AfterBattle)
    }
(over here would be whatever the original script says)
}

text Brock2_Intro{"You want to fight me again?\nOk let's do it!"}
text Brock2_Outro{"You were hard to beat!\nNext time I guess!"}

script Brock2_AfterBattle
{
     msgbox("You beat me again!", msgbox_autoclose)
     cleartrainerflag(TRAINER_BROCK2)
     release
     end
}

This is how I would script it so I would battle brock after the e4, but the cleartrainerflag I added in afterbattle will make him battle you again after you beat him, you can omit it if you would like to only battle him after beating the e4 again. Adding the cleartrainerflag somewhere in the blue script in the e4 after beating him. You decide, if u got any other questions, lmk.
 
Last edited:

Lunos

Random Uruguayan User
3,105
Posts
15
Years
sure, so editing the leader's script to check for champ flag. Im not sure which flag is set when you become champ. Check your flags to see which one is set. In emerald, the flag is called FLAG_IS_CHAMPION. I would add that to the script for Brock (for example)

Code:
script BrockGymLeader
{
    lock
    faceplayer
    if(flag(FLAG_IS_CHAMP) ==TRUE)
    {
        trainerbattle_single(TRAINER_BROCK2, Brock2_Intro, Brock2_Outro, Brock2_AfterBattle)
    }
(over here would be whatever the original script says)
}

text Brock2_Intro{"You want to fight me again?\nOk let's do it!"}
text Brock2_Outro{"You were hard to beat!\nNext time I guess!"}

script Brock2_AfterBattle
{
     msgbox("You beat me again!", msgbox_autoclose)
     cleartrainerflag(TRAINER_BROCK2)
     release
     end
}

This is how I would script it so I would battle brock after the e4, but the cleartrainerflag I added in afterbattle will make him battle you again after you beat him, you can omit it if you would like to only battle him after beating the e4 again. Adding the cleartrainerflag somewhere in the blue script in the e4 after beating him. You decide, if u got any other questions, lmk.
It's important to clarify that this is written in Poryscript syntax, @LusoTrainer. It won't work by default, so make sure to integrate Poryscript into your project, if you didn't do it already.
 
510
Posts
10
Years
  • Seen Feb 26, 2024
It's important to clarify that this is written in Poryscript syntax, @LusoTrainer. It won't work by default, so make sure to integrate Poryscript into your project, if you didn't do it already.
Thanks, I didn't know about that.

I'll have to take a look later on, but can I just use the playground and copy the output for the time being?

Meanwhile, I was taking a look at the suggested script by @dGxx, and should it be something like this?

Code:
PewterCity_Gym_EventScript_Brock::
    famechecker FAMECHECKER_BROCK, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    goto_if_set FLAG_DEFEATED_CHAMP, BrockGymLeader_1
    trainerbattle_single TRAINER_LEADER_BROCK, PewterCity_Gym_Text_BrockIntro, PewterCity_Gym_Text_BrockDefeat, PewterCity_Gym_EventScript_DefeatedBrock, NO_MUSIC
    goto_if_unset FLAG_GOT_TM39_FROM_BROCK, PewterCity_Gym_EventScript_GiveTM39
    msgbox PewterCity_Gym_Text_BrockPostBattle
    release
    end

BrockGymLeader_1:
    trainerbattle_single TRAINER_BROCK2, Brock2_Intro, Brock2_Outro, Brock2_AfterBattle
    return


Brock2_AfterBattle::
    msgbox Brock2_AfterBattle_Text_0, msgbox_autoclose
    cleartrainerflag TRAINER_BROCK2
    release
    end


Brock2_AfterBattle_Text_0:
    .string "You beat me again!$"

Brock2_Intro::
    .string "You want to fight me again?\nOk let's do it!$"

Brock2_Outro::
    .string "You were hard to beat!\nNext time I guess!$"

Or should this specific part be like this?

Code:
PewterCity_Gym_EventScript_Brock::
    famechecker FAMECHECKER_BROCK, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_BROCK, PewterCity_Gym_Text_BrockIntro, PewterCity_Gym_Text_BrockDefeat, PewterCity_Gym_EventScript_DefeatedBrock, NO_MUSIC
    goto_if_unset FLAG_GOT_TM39_FROM_BROCK, PewterCity_Gym_EventScript_GiveTM39
    msgbox PewterCity_Gym_Text_BrockPostBattle
    goto_if_set FLAG_DEFEATED_CHAMP, BrockGymLeader_1
    release
    end

Thanks in advance.
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
Thanks, I didn't know about that.

I'll have to take a look later on, but can I just use the playground and copy the output for the time being?

Meanwhile, I was taking a look at the suggested script by @dGxx, and should it be something like this?

Code:
PewterCity_Gym_EventScript_Brock::
    famechecker FAMECHECKER_BROCK, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    goto_if_set FLAG_DEFEATED_CHAMP, BrockGymLeader_1
    trainerbattle_single TRAINER_LEADER_BROCK, PewterCity_Gym_Text_BrockIntro, PewterCity_Gym_Text_BrockDefeat, PewterCity_Gym_EventScript_DefeatedBrock, NO_MUSIC
    goto_if_unset FLAG_GOT_TM39_FROM_BROCK, PewterCity_Gym_EventScript_GiveTM39
    msgbox PewterCity_Gym_Text_BrockPostBattle
    release
    end

BrockGymLeader_1:
    trainerbattle_single TRAINER_BROCK2, Brock2_Intro, Brock2_Outro, Brock2_AfterBattle
    return


Brock2_AfterBattle::
    msgbox Brock2_AfterBattle_Text_0, msgbox_autoclose
    cleartrainerflag TRAINER_BROCK2
    release
    end


Brock2_AfterBattle_Text_0:
    .string "You beat me again!$"

Brock2_Intro::
    .string "You want to fight me again?\nOk let's do it!$"

Brock2_Outro::
    .string "You were hard to beat!\nNext time I guess!$"

Or should this specific part be like this?

Code:
PewterCity_Gym_EventScript_Brock::
    famechecker FAMECHECKER_BROCK, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_BROCK, PewterCity_Gym_Text_BrockIntro, PewterCity_Gym_Text_BrockDefeat, PewterCity_Gym_EventScript_DefeatedBrock, NO_MUSIC
    goto_if_unset FLAG_GOT_TM39_FROM_BROCK, PewterCity_Gym_EventScript_GiveTM39
    msgbox PewterCity_Gym_Text_BrockPostBattle
    goto_if_set FLAG_DEFEATED_CHAMP, BrockGymLeader_1
    release
    end

Thanks in advance.

Hey that looks good, yeah sorry thought that would be the way everyone would script, it was scripted with poryscript, use the RHH's video to learn how to add it to your decomp, it makes scripting so much easier, I just dont use poryscript when I edit the existing scripts, only when Im inserting new ones. Which is all I do.

After looking at your script, yes it looks right, only because Im not sure what the flag is for beating BLUE is, but if FLAG_DEFEATED_CHAMP is that flag then your script should work.

The line
Code:
goto_if_set FLAG_DEFEATED_CHAMP, BrockGymLeader_1
should be added after original battle, so brock doesnt speak as if you beat him and then he rematches you. Makes more sense like that. Although the way its set up, he will always rematch you but if you add that cleartrainerflag after being blue, you can make it only rematch you after every time you beat blue again. Let me know what you think
 
510
Posts
10
Years
  • Seen Feb 26, 2024
I think I'll leave it like this, so that rematches are available after you become champion and there's no need to do the elite four again and again.

One more question: what would I need to do so that after the rematch happens, it only becomes again available after I leave and enter the gym again?
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
I think I'll leave it like this, so that rematches are available after you become champion and there's no need to do the elite four again and again.

One more question: what would I need to do so that after the rematch happens, it only becomes again available after I leave and enter the gym again?
If you only want it to happen after you leave the gym, you could add a map script on pewter city that does the cleartrainerflag after checking the trainerflag, im not sure of the syntax but im sure u can figure it out.

You can either give another npc in pewter city the script or make it a map script. Im not sure if i would add a map script to the gym, pewter city makes more sense since thats where you will exit the gym to.
 
510
Posts
10
Years
  • Seen Feb 26, 2024
If you only want it to happen after you leave the gym, you could add a map script on pewter city that does the cleartrainerflag after checking the trainerflag, im not sure of the syntax but im sure u can figure it out.

You can either give another npc in pewter city the script or make it a map script. Im not sure if i would add a map script to the gym, pewter city makes more sense since thats where you will exit the gym to.

I guess I'll leave that for later. Meanwhile, since I have a save file on Vermillion, I just tested the script on Misty with simpler conditions and her default team, but when I press A in front of her, nothing happens.

The script is like this:

Code:
CeruleanCity_Gym_EventScript_Misty::
    famechecker FAMECHECKER_MISTY, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_MISTY, CeruleanCity_Gym_Text_MistyIntro, CeruleanCity_Gym_Text_MistyDefeat, CeruleanCity_Gym_EventScript_MistyDefeated, NO_MUSIC
    goto_if_set FLAG_DEFEATED_MISTY, MistyGymLeader_1
    goto_if_unset FLAG_GOT_TM03_FROM_MISTY, CeruleanCity_Gym_EventScript_GiveTM03
    msgbox CeruleanCity_Gym_Text_ExplainTM03
    release
    end

MistyGymLeader_1:
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

Misty2_AfterBattle::
    msgbox Misty2_AfterBattle_Text_0, MSGBOX_AUTOCLOSE
    cleartrainerflag TRAINER_LEADER_MISTY
    release
    end

Misty2_AfterBattle_Text_0:
    .string "You beat me again!$"

Misty2_Intro::
    .string "You want to fight me again?\nOk let's do it!$"

Misty2_Outro::
    .string "You were hard to beat!\nNext time I guess!$"

Is something missing?
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
I guess I'll leave that for later. Meanwhile, since I have a save file on Vermillion, I just tested the script on Misty with simpler conditions and her default team, but when I press A in front of her, nothing happens.

The script is like this:

Code:
CeruleanCity_Gym_EventScript_Misty::
    famechecker FAMECHECKER_MISTY, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_MISTY, CeruleanCity_Gym_Text_MistyIntro, CeruleanCity_Gym_Text_MistyDefeat, CeruleanCity_Gym_EventScript_MistyDefeated, NO_MUSIC
    goto_if_set FLAG_DEFEATED_MISTY, MistyGymLeader_1
    goto_if_unset FLAG_GOT_TM03_FROM_MISTY, CeruleanCity_Gym_EventScript_GiveTM03
    msgbox CeruleanCity_Gym_Text_ExplainTM03
    release
    end

MistyGymLeader_1:
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

Misty2_AfterBattle::
    msgbox Misty2_AfterBattle_Text_0, MSGBOX_AUTOCLOSE
    cleartrainerflag TRAINER_LEADER_MISTY
    release
    end

Misty2_AfterBattle_Text_0:
    .string "You beat me again!$"

Misty2_Intro::
    .string "You want to fight me again?\nOk let's do it!$"

Misty2_Outro::
    .string "You were hard to beat!\nNext time I guess!$"

Is something missing?
yeah something is wrong, caught it right away, its not similar to the brock one, but thats ok, looking at code sometimes confused the bejeezus out of you. If you check..
Code:
goto_if_set FLAG_DEFEATED_MISTY, MistyGymLeader_1
you are using the wrong flag, I thought u were gonna use the champ flag, but if you just want to battle her every time u beat her, then I guess u can keep it like that.

also on the line...

Code:
MistyGymLeader_1:
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

it seems u are using the same TRAINER_ID for her rematch, u need to make a new one like TRAINER_LEADER_MISTY2
and another reason why you are getting nothing it might be because that trainer ID has already been beaten, and you would have to cleartrainerflag that trainer to battle them again.

Code:
Misty2_AfterBattle
will only run if you beat her, since the cleartrainerflag command is after the battle you gotta find a way to insert the command before the line where you start the rematch, hopefully after the first original match.

Also one more thing, if you just want to rematch the same trainer ID with her original team, just
cleartrainerflag TRAINER_LEADER_MISTY, but if u want her to have a stronger team, make a new entry of her ID
 
Last edited:
510
Posts
10
Years
  • Seen Feb 26, 2024
yeah something is wrong, caught it right away, its not similar to the brock one, but thats ok, looking at code sometimes confused the bejeezus out of you. If you check..

you are using the wrong flag, I thought u were gonna use the champ flag, but if you just want to battle her every time u beat her, then I guess u can keep it like that.

Yes, I just changed it so that I could quickly test it with a save game I had whwre I had just beaten Misty. The intention is to put the champion flag for the final edit.

also on the line...

Code:
MistyGymLeader_1:
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

it seems u are using the same TRAINER_ID for her rematch, u need to make a new one like TRAINER_LEADER_MISTY2
and another reason why you are getting nothing it might be because that trainer ID has already been beaten, and you would have to cleartrainerflag that trainer to battle them again.

Code:
Misty2_AfterBattle
will only run if you beat her, since the cleartrainerflag command is after the battle you gotta find a way to insert the command before the line where you start the rematch, hopefully after the first original match.

Also one more thing, if you just want to rematch the same trainer ID with her original team, just
cleartrainerflag TRAINER_LEADER_MISTY, but if u want her to have a stronger team, make a new entry of her ID
Thanks. Since adding new trainer IDs with their own teams is relatively simple, I only did this so that I could test the script.

I did what you suggested and indeed the issue was the absence of cleartrainerflag TRAINER_LEADER_MISTY

I changed it to the following and it seems to work just fine now:

Code:
CeruleanCity_Gym_EventScript_Misty::
    famechecker FAMECHECKER_MISTY, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_MISTY, CeruleanCity_Gym_Text_MistyIntro, CeruleanCity_Gym_Text_MistyDefeat, CeruleanCity_Gym_EventScript_MistyDefeated, NO_MUSIC
    goto_if_set FLAG_DEFEATED_MISTY, MistyGymLeader_1
    goto_if_unset FLAG_GOT_TM03_FROM_MISTY, CeruleanCity_Gym_EventScript_GiveTM03
    msgbox CeruleanCity_Gym_Text_ExplainTM03
    release
    end

MistyGymLeader_1:
    cleartrainerflag TRAINER_LEADER_MISTY
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

Misty2_AfterBattle::
    msgbox Misty2_AfterBattle_Text_0, MSGBOX_AUTOCLOSE
    release
    end

I only have one small issue though. It's very easy to quickly do a rematch by mistake by pressing A. If I add MSGBOX_YESNO, is this how it works?

Code:
MSGBOX_YESNO
goto_if_eq VAR_RESULT, YES, Script1
goto_if_eq VAR_RESULT, NO, Script2

Once again, thanks for the help.
 
124
Posts
8
Years
  • Age 37
  • Seen yesterday
Yes, I just changed it so that I could quickly test it with a save game I had whwre I had just beaten Misty. The intention is to put the champion flag for the final edit.


Thanks. Since adding new trainer IDs with their own teams is relatively simple, I only did this so that I could test the script.

I did what you suggested and indeed the issue was the absence of cleartrainerflag TRAINER_LEADER_MISTY

I changed it to the following and it seems to work just fine now:

Code:
CeruleanCity_Gym_EventScript_Misty::
    famechecker FAMECHECKER_MISTY, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
    trainerbattle_single TRAINER_LEADER_MISTY, CeruleanCity_Gym_Text_MistyIntro, CeruleanCity_Gym_Text_MistyDefeat, CeruleanCity_Gym_EventScript_MistyDefeated, NO_MUSIC
    goto_if_set FLAG_DEFEATED_MISTY, MistyGymLeader_1
    goto_if_unset FLAG_GOT_TM03_FROM_MISTY, CeruleanCity_Gym_EventScript_GiveTM03
    msgbox CeruleanCity_Gym_Text_ExplainTM03
    release
    end

MistyGymLeader_1:
    cleartrainerflag TRAINER_LEADER_MISTY
    trainerbattle_single TRAINER_LEADER_MISTY, Misty2_Intro, Misty2_Outro, Misty2_AfterBattle
    return

Misty2_AfterBattle::
    msgbox Misty2_AfterBattle_Text_0, MSGBOX_AUTOCLOSE
    release
    end

I only have one small issue though. It's very easy to quickly do a rematch by mistake by pressing A. If I add MSGBOX_YESNO, is this how it works?

Code:
MSGBOX_YESNO
goto_if_eq VAR_RESULT, YES, Script1
goto_if_eq VAR_RESULT, NO, Script2

Once again, thanks for the help.
unfortunately the way u have scripted it, yes she will battle you every time, adding the yesno would give you that choice. Personally, I like to have all my leader rematches right before the Elite 4, to make the Elite 4 harder.

Im sure thats the syntax for the yesno box. You're welcome, Im glad I could help someone, anytime u need help, dont hesitate.
 
Back
Top