Fixed edge case with givemon

This commit is contained in:
Eduardo Quezada D'Ottone 2021-11-04 21:22:03 -03:00
parent af5ff05338
commit aec4d78bd4

View File

@ -64,11 +64,23 @@ u8 ScriptGiveMon(u16 species, u8 level, u16 item, u32 unused1, u32 unused2, u8 u
int sentToPc;
u8 heldItem[2];
struct Pokemon mon;
u16 targetSpecies;
CreateMon(&mon, species, level, USE_RANDOM_IVS, 0, 0, OT_ID_PLAYER_ID, 0);
heldItem[0] = item;
heldItem[1] = item >> 8;
SetMonData(&mon, MON_DATA_HELD_ITEM, heldItem);
// In case a mon with a form changing item is given. Eg: SPECIES_ARCEUS with ITEM_SPLASH_PLATE will transform into SPECIES_ARCEUS_WATER upon gifted.
targetSpecies = GetFormChangeTargetSpecies(&mon, FORM_ITEM_HOLD_ABILITY, 0);
if (targetSpecies == SPECIES_NONE)
targetSpecies = GetFormChangeTargetSpecies(&mon, FORM_ITEM_HOLD, 0);
if (targetSpecies != SPECIES_NONE)
{
SetMonData(&mon, MON_DATA_SPECIES, &targetSpecies);
CalculateMonStats(&mon);
}
sentToPc = GiveMonToPlayer(&mon);
nationalDexNum = SpeciesToNationalPokedexNum(species);