• 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!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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.

[Script] Trainer Rematch through sight instead of talking? (Emerald)

I would suggest looking into src/trainer_see.c. Seems like a good file to look into for that sort of thing.

I have tried looking through but I am unable to find anything of relevance sadly.

My overall plan is to make it so that all Gym Trainers must be fought again when you reenter a Gym unless you have defeated the Gym Leader as normal. But that seems to be a completely different aspect again.
 
My overall plan is to make it so that all Gym Trainers must be fought again when you reenter a Gym unless you have defeated the Gym Leader as normal. But that seems to be a completely different aspect again.

You don't need any kind of custom rematch through sight code to do that. Just add a map script in the gym that checks if you've defeated the leader, and if you haven't, clear the trainer flags of the trainers in the gym so that they can be fought again.
 
You don't need any kind of custom rematch through sight code to do that. Just add a map script in the gym that checks if you've defeated the leader, and if you haven't, clear the trainer flags of the trainers in the gym so that they can be fought again.

I didn't even know that was a thing, thanks for that. I got it working. Though is there a way to have it apply to all trainers at once or do I need to put a clearflag line for each individual trainer in the gym?
 
I didn't even know that was a thing, thanks for that. I got it working. Though is there a way to have it apply to all trainers at once or do I need to put a clearflag line for each individual trainer in the gym?
Yeah, you could do a loop that clears only the trainers you want to clear and that breaks out after the task has been accomplished.
For example, if you wanted to clear every single trainer flag in the game, you could do something like:
Code:
MapThatExists_MapScripts::
	map_script MAP_SCRIPT_ON_TRANSITION, MapThatExists_OnTransition
	.byte 0

MapThatExists_OnTransition:
	setvar VAR_TEMP_1, TRAINER_NONE + 1
	cleartrainerflag VAR_TEMP_1
	call MapThatExists_OnTransition_TrainerFlagLoop
	end

MapThatExists_OnTransition_TrainerFlagLoop:
	addvar VAR_TEMP_1, 1
	cleartrainerflag VAR_TEMP_1
	goto_if_ne VAR_TEMP_1, TRAINERS_COUNT, MapThatExists_OnTransition_TrainerFlagLoop
	return

Basically, this is using VAR_TEMP_1, a temporary variable, to host trainer flag values that are cleared thanks to the cleatrainerflag scripting command through an ON_TRANSITION Map Script.
https://github.com/pret/pokeemerald/blob/master/include/constants/map_scripts.h#L19
By adding 1 to the value of VAR_TEMP_1 and following with another call to cleartrainerflag you clear the next trainer flag.
And the script just loops until every trainer flag has been cleared. You may change the values used in this script in order to suit your needs.

It'd probably be much cleaner to write yourself a special to handle it though, depending on what usage you wanna give it.
You could, for example, add an array containing all the Gym Trainers, and then a function that clears their flags.
 
Last edited:
So I have set up a script for Rustboro Gym which I think works the way I want.

Code:
Rustborocity_Gym_OnTransition:
setvar VAR_TEMP_1, TRAINER_JOSH
call_if_unset FLAG_RECEIVED_TM39, RustboroCity_Gym_OnTransition_TrainerFlagLoop
end

RustboroCity_Gym_OnTransition_TrainerFlagLoop:
	cleartrainerflag VAR_TEMP_1
	addvar VAR_TEMP_1, 1
	goto_if_ne VAR_TEMP_1, TRAINER_TOMMY + 1, RustboroCity_Gym_OnTransition_TrainerFlagLoop
	return

If I understand the code correctly it should clear flags from the first trainer (Josh), the last trainer (Tommy), and every trainer in between but stop if it is the trainer after Tommy. Is that correct? If so this should work fine as a template.

Also, how do I go about changing the order of trainers for this purpose? I noticed sometimes trainers in a gym will be at different points in a list. Hiker Marc is at the end of trainers.h but moving him between Josh and Tommy didn't seem to solve the issue.
 
Also, how do I go about changing the order of trainers for this purpose? I noticed sometimes trainers in a gym will be at different points in a list. Hiker Marc is at the end of trainers.h but moving him between Josh and Tommy didn't seem to solve the issue.
It should. Modifying/replacing the values of their TRAINER_ labels at include/constants/opponents.h should absolutely modify their positions in memory.
 
Back
Top