Seen 2 Days Ago
Posted 1 Week Ago
13 posts
28 Days
So I wanted to change the "held items and trade" evolutions to "use" evolutions like the evolution stones, but I'm running into an unexpected problem. Using the Up-grade as an example, I changed the Porygon line in src/data/pokemon to {{EVO_ITEM, ITEM_UP_GRADE, SPECIES_PORYGON2}}, as well as changing the Up-grade's code in src/data/items.h to .type = ITEM_USE_PARTY_MENU and .fieldUseFunc = ItemUseOutOfBattle_EvolutionStone. Additionally, in src/data/pokemon/item_effects.h I added the line [ITEM_UP_GRADE - ITEM_POTION] = gItemEffect_EvoStone.

However, this code produces the following problem:
Spoiler:


As you can see, it is alllllllmost working, given that we get the HP display for the correct Pokemon like you see with evolution stones. But then we get the same message: It won't have any effect. I've tracked down the bit of code that does this last message, located in src/party_menu.c:
Spoiler:


However, this is where I hit a brick wall. I have no idea why the above if statement evaluates to true for Porygon. The ExecuteTableBasedItemEffect_ function only exists in this file and nowhere else in the decomp, and has 3 arguments:
static bool8 ExecuteTableBasedItemEffect_(u8 partyMonIndex, u16 item, u8 monMoveIndex)
The first two don't really matter for our purposes (I think) but it's the last one that I am tearing my hair out about. monMoveIndex only exists in this file, and as such I have no idea what it is, what it does, how it decides when to be = 0 and when not to be, nor what that even means. I am totally stuck.

Lunos

Random Uruguayan User

Male
Montevideo (Uruguay)
Seen 1 Hour Ago
Posted 1 Hour Ago
2,807 posts
13 Years
So I wanted to change the "held items and trade" evolutions to "use" evolutions like the evolution stones
I don't know the exact changes you did, so here's a commit I cooked up in a moment.
You can use it to check whatever changes you may have missed.
https://github.com/LOuroboros/pokeemerald/commit/d9e0bb5b2e7c1ee63db94cf1b897073720d100a2
Note: I think it can be guessed, but the max value for the
ITEM_HAS_EFFECT
macro is the last valid item that
gItemEffectTable
will take into account.
Naturally, if you intend to use items beyond the Metal Coat, you'll have to set said max value to a different item.
Seen 2 Hours Ago
Posted 3 Hours Ago
123 posts
4.2 Years
.....
Lunos had it right on his post. Currently, when trying to use the Upgrade on Porygon, your issue is occurring here in
src/pokemon.c
, specifically in the function "PokemonUseItemEffects":
// Skip using the item if it won't do anything
    if (!ITEM_HAS_EFFECT(item))
        return TRUE;
ITEM_HAS_EFFECT
is defined in
include/constants/items.h
, which rejects any items with an id higher than LAST_BERRY_INDEX, which is set to be equal to ITEM_MARANGA_BERRY higher up in the same file. Upgrade has a higher id, and thus, it is rejected. You can change the definition of
ITEM_HAS_EFFECT
to be this:
#define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION && (item) <= ITEM_UP_GRADE)
I don't know if this will have any other strange effects, but it should allow you to evolve Porygon with the Upgrade.