Skip to content

Add a Macro that Returns 1.9 Following Pokémon to their Ball for Scripts

Bivurnum edited this page Aug 12, 2024 · 1 revision

created by Bivurnum
works with pokeemerald-expansion 1.9.0+

Working with the new following Pokemon can be kind of a hassle during scripted scenes, especially when moving the player around with applymovement, so I created a macro that hides the follower in their Pokéball until the player's controls have been released again.

Note

Currently, this macro does nothing if OW_SUBSTITUTE_PLACEHOLDER is set to FALSE, as it does not play nice with gen 9 Pokémon that do not spawn in a follower.

First, go to src/event_object_movement.c and add this function to the end of the file:

void ReturnFollowingMonToBall(void)
{
    struct ObjectEvent *objectEvent = GetFollowerObject();
    struct Sprite *sprite = &gSprites[objectEvent->spriteId];
    u16 species;
    bool8 shiny;
    u8 form;

    if (OW_POKEMON_OBJECT_EVENTS == FALSE
     || OW_FOLLOWERS_ENABLED == FALSE
     || !GetFollowerInfo(&species, &form, &shiny)
     || SpeciesToGraphicsInfo(species, form) == NULL
     || (gMapHeader.mapType == MAP_TYPE_INDOOR && SpeciesToGraphicsInfo(species, form)->oam->size > ST_OAM_SIZE_2)
     || FlagGet(FLAG_TEMP_HIDE_FOLLOWER))
    {
        RemoveFollowingPokemon();
        return;
    }

    ClearObjectEventMovement(objectEvent, sprite);
    ObjectEventSetHeldMovement(objectEvent, MOVEMENT_ACTION_ENTER_POKEBALL);
}

Then, go to include/event_object_movement.h and add this line near the end of the file (but before #endif //GUARD_EVENT_OBJECT_MOVEMENT_H):

void ReturnFollowingMonToBall(void);

Then, go to src/scrcmd.c and add this function to the end of the file:

bool8 ScrCmd_ballfollowingmon(struct ScriptContext *ctx)
{
    if (OW_FOLLOWERS_ENABLED == TRUE && FlagGet(FLAG_SYS_POKEMON_GET) && OW_SUBSTITUTE_PLACEHOLDER == TRUE) {
        ReturnFollowingMonToBall();
    }
    return FALSE;
}

Then, go to data/script_cmd_table.inc and add this line to the end of the list in gScriptCmdTable:

	.4byte ScrCmd_ballfollowingmon  				@ 0xe5

If any other macros have already been added, you should change @ 0xe5 to the next number in the sequence. For example, if the line before this one ends with @ 0xe9, you should change the one for the line you are adding to @ 0xea.

Now, go to asm/macros/event.inc and add this just above @ Supplementary:

	@ Returns Pokemon follower to ball
	.macro ballfollowingmon
	.byte 0xe5
	delay 16
	.endm

If you changed @ 0xe5 to another value in your addition to script_cmd_table.inc, you will need to change .byte 0xe5 here to reflect that different value.
You can also change the name ballfollowingmon to whatever you want to use in your scripts. For example, if you prefer something shorter, you could change it to ballmon. Only change what it is called in this file, or the macro will not work right.

That's all it takes! Now you can use the new macro in your scripts.

Example

For example, we can incorporate this macro into the script for the mart employee in Oldale Town, like so:

OldaleTown_EventScript_MartEmployee::
	lock
	faceplayer
	goto_if_set FLAG_RECEIVED_POTION_OLDALE, OldaleTown_EventScript_ExplainPotion
	goto_if_set FLAG_TEMP_1, OldaleTown_EventScript_ExplainPotion
	setflag FLAG_TEMP_1
+	ballfollowingmon
	playbgm MUS_FOLLOW_ME, FALSE
	msgbox OldaleTown_Text_IWorkAtPokemonMart, MSGBOX_DEFAULT
	closemessage
	switch VAR_FACING
	case DIR_SOUTH, OldaleTown_EventScript_GoToMartSouth
	case DIR_NORTH, OldaleTown_EventScript_GoToMartNorth
	case DIR_EAST, OldaleTown_EventScript_GoToMartEast
	end

It will funtion like this in game: