mirror of https://github.com/pret/pokeemerald.git
Page:
Allow Running From Trainer Battles
Pages
Ability Switcher via special
Add A PokeVial Item
Add Ability to Avoid Battle Damage in Debug Menu
Add Ability to Swap Bikes Whenever
Add Choice Specs Scarf hold item effects
Add Description Submenu
Add Difficulty Mode
Add In‐Cart Rumble
Add Nuzlocke Challenge
Add PC Access in PokeNav
Add Physical Special Split
Add Sleep Mode
Add Thief Ball
Add a EV IV Stat Editor UI
Add a debug menu
Adding Multi region Support
Adding Support for Connectivity with Other Hacks Whilst Maintaining Connectivity with Vanilla
Adding Time Based Encounters
Adding Walking Animations to All NPCs
Adding a New Trainer Class
Adding a New Trainer Front Picture
Adding a Pokémon Type & Disabling the Mystery Type
Adding new event object or overworld sprites
All Trees Permanently Get Cut
Allow All Pokemon to Evolve Without Trading
Allow Both Latios and Latias Appear.
Allow Feebas to be caught on any Valid Fishing Spot in Route 119 rather than only Three
Allow Jumping Over Ledges with Acro Bike
Allow Move Relearner to Teach Moves that Pre Evolutions Know
Allow Running From Trainer Battles
Allow running indoors
Amulet Coin Effects If Anyone In Party is Holding It
Automatically make the keyboard switch to lowercase after the first character
Better White Out Money Calculation
Button Press to Skip Copyright Screen
Chain Fishing
Change Enemy Trainer Parties Depending on Difficulty
Change Someone's PC to Lanette's PC from the Start of the Game
Change Starter Pokémon
Change Time Based Evolution Times
Change initial PC items
Changing the Battle Music Depending on the Opponent
Colored stats by nature in summary screen
Converting to FR Tilesets
Custom Battle Mugshots
Custom Border Dimensions
Debugging using gdb (Windows, WSL2, Visual Studio Code mGBA)
Debugging using printf
Disable Bag Use In Battle
Disable Catching Pokemon
Disable Pokémon animation on Birch's intro Pokémon
Disabling Union Room check when entering Pokémon Centers
Dynamic Trade Names
Dynamic overworld palette system
Enable the Reset RTC Feature
Enable trade with FRLG without beating the game
Expanding The Metatile Count
Extra save space with three lines of code
Faster HP Drain
Feature Branches
Fish Will Now Always Get on Hook
Fix AI's Switch In Battle
Fix Snow Weather
Fixing the aspect ratio of the Pokémon logo on the title screen
Forcing Battle Animations for Major Battles
Full Screen Start Menu by Archie and Mudskip
Gen 6 Exp Share
Gen 6 style Exp. Share Alternative Option
Get Match Calls Only If Caller Wants a Rematch
Get Rid of Battery Run Dry Error Message
Get Rid of Pokemon Disobeying You
Holding Select Allows For A Second Register Item
Home
How the Game Works
How to Support Savefile Backwards Compatibility
How to add a new Pokémon species
How to add a new ability
How to add a new region map
How to create a new regular trainer battle
How to delete a map
Implement Missing Text Function RESET_FONT
Implementing Catch EXP
Implementing ipatix's High Quality Audio Mixer
Implementing the “textcolor” script command from FRLG and give object events their own text colour
Improve Partner Battle Code
Improve the Loading of Battle Terrain
Improving the WaitForVBlank function
Increase money limit
Infinite TM usage
Instead of Asking to Stop learning a New Move, You'll be Asked to Continue Learning
Item Automatically Goes to PC if Bag is Full
Keep the Camera from Making Waves
LGPE Style Bonus Premier Balls
Learn moves upon evolution
List Menu Text Coloring
Make Cleanse Tag Avoid All Wild Encounters and Usable If Held By Anyone in Your Party; Make PokeDoll Do the Same for Trainers Seeing You
Make Daycare Faster at Leveling Pokémon
Make Key Items That Cannot Be Used In The Field Not Show A Use or Register Option
Make L Button Be Turbo A When L=A Option Is Set
Make Ledge Jumps Check Collision
Make Move Relearner Teach Egg Moves With A Flag
Make Multiple Secret Bases
Make Norman's Slaking Have Ability Intimidate
Make Pokemon Not Heal When Going into PC
Make Pokemon that Require a Fateful Encounter to be Legal to Always Be Set to Legal
Make space for EWRAM Data for Summary screen
Make the Bag Able to Hold 120 Items Instead of 30
Make the Person in the Intro Match the the Save File
Map Based Trainer Battle Music
Move Item
Multipage Options Menu
Name Rater Allows Traded Pokemon to be Renamed
New Birch's Briefcase With Fully Custom Starters by Archie and Mudskip
New Custom Menu Border Themes (Basic)
New Main Menu UI With Mugshot by Archie and Mudskip
New Options Plus ‐ Multipage Options Menu with Faster Text, HP‐EXP Bar Speeds and Metric
Nickname your Pokémon from the party menu
Not showing dex entries until getting the Pokédex
Omnidirectional Jump
Optimization ‐ Remove Expensive and Redundant `BuildColorMaps()` Function
Option to Skip Copyright and Intro
Overview: Items and their Effects
Overview: The Party Menu
Overview∶ The Game Loop
Overview∶ The Task System
Per Shop\Mart Item Prices
Plural Giveitem
Pokecenters Disregard Eggs
Prompt for reusing Repels
Push B in wild battle moves to Run
Push B to Toggle Running Shoes
Pushing B When Asked To Stop Learning Move Will Cancel Teaching The Move
Quickly Run from a Battle by Holding Right While the Wild Pokémon's Name Appears
Raise Odds of Catching a Pokemon by Pressing B When the Ball Shakes
Random Info, Tips, and Tricks
Reflections
Remove 'Select' Sound From Specific Map Events
Remove Warp Fadescreen
Remove badge boosts
Remove the backup save file
Remove the extra save confirmation
Remove the functionally redundant move grammar tables
Repeated Field Medicine Use
Reuse filler save space for Variables and Flags
Revert Brendan May Sprites to Ruby Sapphire
Set Metatile IDs From Another Map
Set Up Item Balls on a Map Without Needing New Scripts
Shifting to Pokémon Already in Battle Exits the Shift Menu
Shiny Creation With a Flag
Shop Items By Badge Count
Show IVs EVs in Summary Screen
Show Species That You're Switching For in the Party Menu
Show Type Effectiveness In Battle Using Pre Existing Function and Disable in Option Menu
Show a throbber animation while the game is saving
Shuckle makes Berry Juice
Something doesn't work I need help etc.
Spawn Invisible Player
Speedy Nurse Joy
Spinda Second Frame Spot Addition
Stair Warps
Supplementary Scripting Macros
Surfing Dismount Ground Effects
Temporarily Replace Player or Enemy Party Pokemon
The Basics of Scripting
Toggle Trainer Sight
Trainer Backsprite Editing
Trainer Class Based Poké Balls
Trainer Scripts
Trainers No Longer Spin to Face You Right As You Pass Them
Trigger Map Scripts By Flag
Triple layer metatiles
Tutorials
Tweaking the count of health beeps
Uniquely Shuffle Array
Update Sitrus Berry's effect to Gen 4 standard
Use HMs Without Any Pokemon in your Party Knowing Them
Useful Modding Tools
Useful Scripting Specials
Why You Should (Almost) Always Be Using 32‐Bit Variables in Your Code
Why should I use this over binary hacking
13
Allow Running From Trainer Battles
voloved edited this page 2023-04-29 15:20:26 -04:00
Table of Contents
By devolov
Goal: Allow running from a battle with an NPC trainer. When you run from them, you can still talk to them to battle, they just won't "see" you until you either change maps or walk in front of someone else who can battle you.
------------------------------ src/battle_setup.c ------------------------------
index 03bc0a08e7..e17db26d14 100644
@@ -113,8 +113,9 @@ EWRAM_DATA static u8 *sTrainerBattleEndScript = NULL;
EWRAM_DATA static u8 *sTrainerABattleScriptRetAddr = NULL;
EWRAM_DATA static u8 *sTrainerBBattleScriptRetAddr = NULL;
EWRAM_DATA static bool8 sShouldCheckTrainerBScript = FALSE;
EWRAM_DATA static u8 sNoOfPossibleTrainerRetScripts = 0;
+EWRAM_DATA static u32 sPrevTrainerSeeing = 0;
// The first transition is used if the enemy pokemon are lower level than our pokemon.
// Otherwise, the second transition is used.
static const u8 sBattleTransitionTable_Wild[][2] =
@@ -1271,9 +1272,13 @@ void SetUpTwoTrainersBattle(void)
bool32 GetTrainerFlagFromScriptPointer(const u8 *data)
{
u32 flag = TrainerBattleLoadArg16(data + 2);
- return FlagGet(TRAINER_FLAGS_START + flag);
+ bool8 trainerFlagValue = FlagGet(TRAINER_FLAGS_START + flag);
+ if (flag != sPrevTrainerSeeing && !trainerFlagValue){
+ sPrevTrainerSeeing = flag;
+ FlagClear(FLAG_RAN_FROM_TRAINER);
+ }
+ return (trainerFlagValue || FlagGet(FLAG_RAN_FROM_TRAINER));
}
// Set trainer's movement type so they stop and remain facing that direction
// Note: Only for trainers who are spoken to directly
@@ -1412,10 +1422,16 @@ static void CB2_EndTrainerBattle(void)
{
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
if (!InBattlePyramid() && !InTrainerHillChallenge())
{
- RegisterTrainerInMatchCall();
- SetBattledTrainersFlags();
+ if (gBattleOutcome == B_OUTCOME_RAN){
+ FlagSet(FLAG_RAN_FROM_TRAINER);
+ }
+ else
+ {
+ FlagClear(FLAG_RAN_FROM_TRAINER);
+ RegisterTrainerInMatchCall();
+ SetBattledTrainersFlags();
+ }
}
}
}
------------------------------ src/trainer_see.c ------------------------------
index 7b7533a337..642b6bd0f1 100644
@@ -421,16 +421,14 @@ static u8 CheckTrainer(u8 objectEventId)
{
if (GetHillTrainerFlag(objectEventId))
return 0;
}
- else
- {
- if (GetTrainerFlagFromScriptPointer(scriptPtr))
- return 0;
- }
approachDistance = GetTrainerApproachDistance(&gObjectEvents[objectEventId]);
if (approachDistance != 0)
{
+ if (GetTrainerFlagFromScriptPointer(scriptPtr))
+ return 0;
if (scriptPtr[1] == TRAINER_BATTLE_DOUBLE
|| scriptPtr[1] == TRAINER_BATTLE_REMATCH_DOUBLE
------------------------------- src/event_data.c -------------------------------
index 50f6f68da4..4a00bcac40 100644
@@ -44,8 +44,9 @@ void InitEventData(void)
void ClearTempFieldEventData(void)
{
memset(gSaveBlock1Ptr->flags + (TEMP_FLAGS_START / 8), 0, TEMP_FLAGS_SIZE);
memset(gSaveBlock1Ptr->vars + ((TEMP_VARS_START - VARS_START) * 2), 0, TEMP_VARS_SIZE);
+ FlagClear(FLAG_RAN_FROM_TRAINER);
FlagClear(FLAG_SYS_ENC_UP_ITEM);
FlagClear(FLAG_SYS_ENC_DOWN_ITEM);
FlagClear(FLAG_SYS_USE_STRENGTH);
FlagClear(FLAG_SYS_CTRL_OBJ_DELETE);
-------------------------- include/constants/flags.h --------------------------
index 7f36cacc8f..2a25e074f6 100644
@@ -1241,9 +1241,9 @@
-#define FLAG_UNUSED_0x4AC 0x4AC // Unused Flag
+#define FLAG_RAN_FROM_TRAINER 0x4AC
#define FLAG_UNUSED_0x4AD 0x4AD // Unused Flag
#define FLAG_UNUSED_0x4AE 0x4AE // Unused Flag
#define FLAG_UNUSED_0x4AF 0x4AF // Unused Flag
#define FLAG_UNUSED_0x4B0 0x4B0 // Unused Flag
------------------------------ src/battle_main.c ------------------------------
@@ -4552,14 +4577,26 @@ static void HandleTurnActionSelectionState(void)
*(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE;
*(gBattleStruct->stateIdAfterSelScript + gActiveBattler) = STATE_BEFORE_ACTION_CHOSEN;
return;
}
else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER
&& !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK))
&& gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN)
{
- BattleScriptExecute(BattleScript_PrintCantRunFromTrainer);
- gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
+ ; // Allow to passthrough to the below logic of IsRunningFromBattleImpossible
}
- else if (IsRunningFromBattleImpossible() != BATTLE_RUN_SUCCESS
+ if (IsRunningFromBattleImpossible() != BATTLE_RUN_SUCCESS
&& gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN)
{
gSelectionBattleScripts[gActiveBattler] = BattleScript_PrintCantEscapeFromBattle;
gBattleCommunication[gActiveBattler] = STATE_SELECTION_SCRIPT;
*(gBattleStruct->selectionScriptFinished + gActiveBattler) = FALSE;
------------------------------ src/battle_setup.c ------------------------------
index 184f1f2336..be89322a0a 100644
@@ -1497,8 +1497,10 @@ const u8 *BattleSetup_GetScriptAddrAfterBattle(void)
}
const u8 *BattleSetup_GetTrainerPostBattleScript(void)
{
+ if (FlagGet(FLAG_RAN_FROM_TRAINER))
+ return EventScript_TryGetTrainerScript; // Stops things like registering to Pokenav after the battle ends
if (sShouldCheckTrainerBScript)
{
sShouldCheckTrainerBScript = FALSE;
if (sTrainerBBattleScriptRetAddr != NULL)
----------------------------- data/trainer_script.inc -----------------------------
delay 30
return
EventScript_TryGetTrainerScript::
+ goto_if_set FLAG_RAN_FROM_TRAINER, EventScript_TryGetTrainerScript_Cont
special ShouldTryGetTrainerScript
goto_if_eq VAR_RESULT, TRUE, EventScript_GotoTrainerScript
+EventScript_TryGetTrainerScript_Cont:
releaseall
end
EventScript_GotoTrainerScript::
gotobeatenscript
Make Important Trainer Battles Ones That You Still Can't Run From
Some battles (Battle Frontier, Rival, Elite Four), may be ones that you don't want to run from. The following tweak can be added in battle_main.c
:
static void HandleEndTurn_BattleLost(void);
static void HandleEndTurn_RanFromBattle(void);
static void HandleEndTurn_MonFled(void);
static void HandleEndTurn_FinishBattle(void);
static void SpriteCB_UnusedBattleInit(struct Sprite *sprite);
static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite);
+static bool8 IsTrainerCantRunFrom(void);
EWRAM_DATA u16 gBattle_BG0_X = 0;
return BATTLE_RUN_FORBIDDEN;
}
return BATTLE_RUN_SUCCESS;
}
+static u8 IsTrainerCantRunFrom(void){
+ u8 trainerClass;
+ if (gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL))
+ return BATTLE_RUN_FORBIDDEN;
+ trainerClass = gTrainers[gTrainerBattleOpponent_A].trainerClass;
+ switch (trainerClass)
+ {
+ case TRAINER_CLASS_AQUA_LEADER:
+ case TRAINER_CLASS_MAGMA_LEADER:
+ case TRAINER_CLASS_TEAM_AQUA:
+ case TRAINER_CLASS_TEAM_MAGMA:
+ case TRAINER_CLASS_AQUA_ADMIN:
+ case TRAINER_CLASS_MAGMA_ADMIN:
+ case TRAINER_CLASS_LEADER:
+ case TRAINER_CLASS_CHAMPION:
+ case TRAINER_CLASS_RIVAL:
+ case TRAINER_CLASS_ELITE_FOUR:
+ return BATTLE_RUN_FORBIDDEN;
+ default:
+ return BATTLE_RUN_SUCCESS;
+ }
+}
+
void SwitchPartyOrder(u8 battler)
{
s32 i;
else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER
&& !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK))
&& gBattleBufferB[gActiveBattler][1] == B_ACTION_RUN)
{
- gBattleCommunication[gActiveBattler]++;
+ if (IsTrainerCantRunFrom())
+ {
+ BattleScriptExecute(BattleScript_PrintCantRunFromTrainer);
+ gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
+ return;
+ }
+ else
+ {
+ ; // Allow to passthrough to the below logic of IsRunningFromBattleImpossible
+ }
}
For proper wording, in battle_messages.c
:
----------------------------- src/battle_message.c -----------------------------
index 11f7f8d5f3..8cc21e0fc5 100644
@@ -332,9 +332,10 @@ static const u8 sText_PlayerLostToTwo[] = _("Player lost to {B_LINK_OPPONENT1_NA
static const u8 sText_PlayerBattledToDrawLinkTrainer[] = _("Player battled to a draw against\n{B_LINK_OPPONENT1_NAME}!");
static const u8 sText_PlayerBattledToDrawVsTwo[] = _("Player battled to a draw against\n{B_LINK_OPPONENT1_NAME} and {B_LINK_OPPONENT2_NAME}!");
static const u8 sText_WildFled[] = _("{PLAY_SE SE_FLEE}{B_LINK_OPPONENT1_NAME} fled!");
static const u8 sText_TwoWildFled[] = _("{PLAY_SE SE_FLEE}{B_LINK_OPPONENT1_NAME} and\n{B_LINK_OPPONENT2_NAME} fled!");
-static const u8 sText_NoRunningFromTrainers[] = _("No! There's no running\nfrom a TRAINER battle!\p");
+static const u8 sText_NoRunningFromTrainers[] = _("No! There's no running\nfrom this TRAINER battle!\p");
static const u8 sText_CantEscape[] = _("Can't escape!\p");
static const u8 sText_DontLeaveBirch[] = _("PROF. BIRCH: Don't leave me like this!\p");
static const u8 sText_ButNothingHappened[] = _("But nothing happened!");
static const u8 sText_ButItFailed[] = _("But it failed!");