Jump to content

Recommended Posts

Posted

Hi all, I'm a little stuck trying to programmatically create a shiny egg in a Gen 4 save file. I have a PK4 object that I've initialized (called mew), and to my understanding, an egg will hatch shiny based on its personality value (the PID) lining up with the save file's secret id and trainer id. In doing that, I initialized the pokemon like this but don't know how to set the PID:
 

        // Assume mew is a PK4() object that I've constructed and have set other attrivbutes (species, held item, etc.)   
		// Set the trainer ID according to the save file
        mew.TrainerTID7 = this.currentSave.TrainerTID7;
        mew.TrainerSID7 = this.currentSave.TrainerSID7;

        uint trainer_id = pokemon.TrainerTID7;
        uint secret_id = pokemon.TrainerSID7;
        uint pid = ShinyUtil.GetShinyPID(trainer_id, secret_id, 0, 0);

		mew.PID = pid;

 

I see that there is a ShinyUtil class that should help me generate a shiny PID for the egg, but I don't think I'm using the function right. My egg currently doesn't register as a shiny when I check the exported save file in Pkhex. I wonder if I'm maybe not running the right function? It seems strange that I'd have to feed getshinypid a pid when I'm actively trying to get a shiny pid? I also have no idea what the last arg is supposed to take. Some help would be appreciated!

Posted

In generation 4, shininess is determined based on who hatches the pokemon. You're using two separate objects to fetch the trainer ID.

The code you pasted does not compile on the latest PKHeX.Core dll, because `ShinyUtil.GetShinyPID` requires different typed arguments.

    public static uint GetShinyPID(in ushort tid, in ushort sid, in uint pid, in uint type)
    {
        var low = pid & 0xFFFF;
        return ((type ^ tid ^ sid ^ low) << 16) | low;
    }

TrainerTID7 is a uint, not a ushort.

When in doubt, look for how PKHeX itself uses the methods:

image.png

As you can see, you need to provide the 16-bit trainer values. You're passing in a 0 for the old PID, so the shiny PID that comes out will be less "random" with the lowest 16 bits being 0.

  • Like 1
Posted (edited)

Thank you! Yep looking back at my code you are right I was using the wrong types.

 

And yes you're right about the two objects being used, I had passed the pokemon object by reference in a helper function and just copied it here- that's why it's not consistent.

 

Update: btw in case anyone wanted to know if it worked, calling GetShinyPID as shown above works! Since objects are passed by reference, I wrote this function in a class to make a PK4 object shiny:
 

internal void MakeShiny(PK4 pokemon) { 
  // Get IDs
  ushort trainer_id = pokemon.TID16;
  ushort secret_id = pokemon.SID16;
  uint pid = ShinyUtil.GetShinyPID(trainer_id, secret_id, 0, 0);

  pokemon.PID = pid;  

}


 

Edited by evievi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...