• 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.

Deactivate wild encounters with a flag

19
Posts
7
Years
  • Age 23
  • Seen Mar 29, 2024


DEACTIVATE WILD ENCOUNTERS WITH A FLAG


With this method, we will avoid the wild encounters, we will find pokemon if we try to fish, and can battle with encounters by script. This acts like a permanent repel

To create the system, we just need to edit the "src/field_control_avatar.c", we will find this function:

Code:
static bool8 CheckStandardWildEncounter(u16 metatileBehavior)
{
    if (sWildEncounterImmunitySteps < 4)
    {
        sWildEncounterImmunitySteps++;
        sPreviousPlayerMetatileBehavior = metatileBehavior;
        return FALSE;
    }

    if (StandardWildEncounter(metatileBehavior, sPreviousPlayerMetatileBehavior) == TRUE)
    {
        sWildEncounterImmunitySteps = 0;
        sPreviousPlayerMetatileBehavior = metatileBehavior;
        return TRUE;
    }

    sPreviousPlayerMetatileBehavior = metatileBehavior;
    return FALSE;
}

Which as its name describes it, it checks if there will be a wild encounter, so, we are going to add a conditional, which checks any flag, to let the code continue. The flags list is at "include/constants/flags.h".

To check a flag in a .c file, we will use

Code:
FlagGet(FLAG)

So, now, knowing this, we will add a conditional to check if a flag is set, I'm going to use an unused flag, you can use any (if you know what you're doing).

Code:
static bool8 CheckStandardWildEncounter(u16 metatileBehavior)
{
	if (FlagGet(FLAG_UNUSED_0x020) != 0){
	
		if (sWildEncounterImmunitySteps < 4)
		{
			sWildEncounterImmunitySteps++;
			sPreviousPlayerMetatileBehavior = metatileBehavior;
			return FALSE;
		}

		if (StandardWildEncounter(metatileBehavior, sPreviousPlayerMetatileBehavior) == TRUE)
		{
			sWildEncounterImmunitySteps = 0;
			sPreviousPlayerMetatileBehavior = metatileBehavior;
			return TRUE;
		}

		sPreviousPlayerMetatileBehavior = metatileBehavior;
		return FALSE;
	}
}

As you see, I've enclosed all the code in the conditional, and you could think why not to enclose just the second conditional, which is the one that executes the wild encounter. Well, that's just to avoid execute unnecessary code. Now, we have the .c file ready to use. That was easy, wasn't it?

Now, let's just create the script which active and deactivate the flag

Code:
Route117_CheckWildEncounter::
	checkflag FLAG_UNUSED_0x020
	vgoto_if 1, Route117_ActivatedFlag
	setflag FLAG_UNUSED_0x020
	msgbox Route117_Text_FlagActivated, MSGBOX_NPC
	end

Route117_ActivatedFlag::
	clearflag FLAG_UNUSED_0x020
	msgbox Route117_Text_FlagDeactivated, MSGBOX_NPC
	end

Route117_Text_FlagActivated: 
	.string "Wild encounter activated$"
	
Route117_Text_FlagDeactivated: 
	.string "Wild encounter deactivated$"

And that's it!

Now, just set the script label to an NPC, compile, and test it :smile:
 
Last edited:

U.Flame

Maker of Short Games
1,326
Posts
15
Years
I wonder how broken a game could be if this was an item. Like a permanent repel you can just toggle on and off?
 
19
Posts
7
Years
  • Age 23
  • Seen Mar 29, 2024
I wonder how broken a game could be if this was an item. Like a permanent repel you can just toggle on and off?

Well, apply this to an object could be pretty simple. Just copying the repel function into a new item (probably a Key Item), remove the steps counter/limitation and create a condition asigned to a flag or something like that. Yup, you can toggle it everytime you want.
 

NielsM

BSBob
12
Posts
7
Years
I've tried this out, but it doesn't seem to work.
I've tried it with quite some flags, but none work when I set them.
 

Lunos

Random Uruguayan User
3,114
Posts
15
Years
I've tried this out, but it doesn't seem to work.
I've tried it with quite some flags, but none work when I set them.
If you read the code provided in the main post, you'll see that this only allows wild encounters to happen if the value of the flag chosen is not 0. That means the wild encounters will only be disabled when the value of the chosen flag is 0, hence why IK used clearflag instead of setflag to disable them in his scripting example.

I tried it myself just now and everything works normally. Setting the flag enables the encounters and clearing it disables them.
 
Back
Top