- 19
- Posts
- 8
- Years
- Seen Aug 5, 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
Last edited: