Skip to content

Shiny Creation With a Flag

ghoulslash edited this page Jun 17, 2021 · 2 revisions

Create Shiny Pokemon with a Flag

credits to ghoulslash

1. Create a flag

Define a flag named FLAG_SHINY_CREATION in include/constants/flags.h

2. Make it do something

  1. Open pokemon.c and find CreateBoxMon
  2. Make the following changes:
-    SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality);

    //Determine original trainer ID
    if (otIdType == OT_ID_RANDOM_NO_SHINY) //Pokemon cannot be shiny
    {
        u32 shinyValue;
        do
        {
            value = Random32();
            shinyValue = HIHALF(value) ^ LOHALF(value) ^ HIHALF(personality) ^ LOHALF(personality);
        } while (shinyValue < SHINY_ODDS);
    }
    else if (otIdType == OT_ID_PRESET) //Pokemon has a preset OT ID
    {
        value = fixedOtId;
    }
    else //Player is the OT
    {
        value = gSaveBlock2Ptr->playerTrainerId[0]
              | (gSaveBlock2Ptr->playerTrainerId[1] << 8)
              | (gSaveBlock2Ptr->playerTrainerId[2] << 16)
              | (gSaveBlock2Ptr->playerTrainerId[3] << 24);

+        if (FlagGet(FLAG_SHINY_CREATION))
+        {
+            u8 nature = personality % NUM_NATURES;  // keep current nature
+            do {
+                personality = Random32();
+                personality = ((((Random() % SHINY_ODDS) ^ (HIHALF(value) ^ LOHALF(value))) ^ LOHALF(personality)) << 16) | LOHALF(personality);
+            } while (nature != GetNatureFromPersonality(personality));
+        }
    }


+    SetBoxMonData(boxMon, MON_DATA_PERSONALITY, &personality);

FLAG_SHINY_CREATION is NOT cleared internally because you might want to make multiple shiny pokemon. Feel free to add FlagClear(FLAG_SHINY_CREATION) at the end of CreateBoxMon to make sure only one shiny mon is created.

Clone this wiki locally