Buffel Saft

Male
Seen 15 Hours Ago
Posted 2 Days Ago
904 posts
7.2 Years
BUGGED: Evolution Moves (Emerald)

NOTE: I've just found a nasty bug with this: if a Pokemon tries to learn a move it already knows while evolving, the game will freeze. I haven't been able to find the cause, so I'd recommend using the implementation posted by Lunos instead.

In the gen VII games many Pokemon have level up moves that they learn upon evolving, regardless of what level they are. This is a fantastic addition because it means Pokemon like Feebas don't stay useless if they evolve a level too late to learn their first damaging move.

To implement this in Emerald, first open include/pokemon.h and add an extra input argument to the function "MonTryLearningNewMove":
u16 MonTryLearningNewMove(struct Pokemon *mon, bool8 firstMove, bool8 isEvolving);
Next, modify all code that calls this function to include a third input argument. There are two instances in src/evolution_scene.c where this should be set to "1", like so:
var = MonTryLearningNewMove(mon, gTasks[taskID].tLearnsFirstMove, 1);
All other instances should be set to "0". These can be found in src/party_menu.c, src/battle_script_commands.c, and src/daycare.c.

Following that, open pokemon.c and navigate to the function "MonTryLearningNewMove". Replace it with the following:
Spoiler:
u16 MonTryLearningNewMove(struct Pokemon *mon, bool8 firstMove, bool8 isEvolving)
{
    u32 retVal = 0;
    u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
    u8 level = GetMonData(mon, MON_DATA_LEVEL, NULL);

    // since you can learn more than one move per level
    // the game needs to know whether you decided to
    // learn it or keep the old set to avoid asking
    // you to learn the same move over and over again
    if (firstMove)
    {
        sLearningMoveTableID = 0;
    }
    // Added evolution moves; Pokemon will learn moves listed at level zero upon evolution
    if(isEvolving && (gLevelUpLearnsets[species][sLearningMoveTableID].level == 0))
    {
        gMoveToLearn = gLevelUpLearnsets[species][sLearningMoveTableID].move;
        retVal = GiveMoveToMon(mon, gMoveToLearn);
        sLearningMoveTableID++;
        return retVal;        
    }
    if(isEvolving && (gLevelUpLearnsets[species][sLearningMoveTableID].level > 0))
    {
        while (gLevelUpLearnsets[species][sLearningMoveTableID].level != level)
         {
            sLearningMoveTableID++;
            if (gLevelUpLearnsets[species][sLearningMoveTableID].move == LEVEL_UP_END)
                return 0;
         }
    }

    if (firstMove)
    {
        while (gLevelUpLearnsets[species][sLearningMoveTableID].level != level)
        {
            sLearningMoveTableID++;
            if (gLevelUpLearnsets[species][sLearningMoveTableID].move == LEVEL_UP_END)
                return 0;
        }
    }
    if (gLevelUpLearnsets[species][sLearningMoveTableID].level == level)
    {
        gMoveToLearn = gLevelUpLearnsets[species][sLearningMoveTableID].move;
        sLearningMoveTableID++;
        retVal = GiveMoveToMon(mon, gMoveToLearn);
    }
    return retVal;
}

Finally, add some evolution moves to src\data\pokemon\level_up_learnsets.h. These must be the first entries in each Pokemon's list, and must be learned at level zero e.g.
Spoiler:
static const struct LevelUpMove sMarshtompLevelUpLearnset[] = {
    LEVEL_UP_MOVE( 0, MOVE_MUD_SHOT),
    LEVEL_UP_MOVE( 1, MOVE_MUD_SHOT),
    LEVEL_UP_MOVE( 1, MOVE_TACKLE),
    LEVEL_UP_MOVE( 1, MOVE_GROWL),
    LEVEL_UP_MOVE( 1, MOVE_WATER_GUN),
    LEVEL_UP_MOVE( 1, MOVE_MUD_SLAP),
    LEVEL_UP_MOVE( 4, MOVE_WATER_GUN),
    LEVEL_UP_MOVE( 9, MOVE_MUD_SLAP),
    LEVEL_UP_MOVE(12, MOVE_FORESIGHT),
    LEVEL_UP_MOVE(18, MOVE_BIDE),
    LEVEL_UP_MOVE(22, MOVE_MUD_BOMB),
    LEVEL_UP_MOVE(28, MOVE_ROCK_SLIDE),
    LEVEL_UP_MOVE(32, MOVE_PROTECT),
    LEVEL_UP_MOVE(38, MOVE_MUDDY_WATER),
    LEVEL_UP_MOVE(42, MOVE_TAKE_DOWN),
    LEVEL_UP_MOVE(48, MOVE_EARTHQUAKE),
    LEVEL_UP_MOVE(52, MOVE_ENDEAVOR),
    LEVEL_UP_END
};