- 50
- Posts
- 7
- Years
- Seen Oct 20, 2023
Set Wild Pokémon's Levels Dynamically POKEEEMERALD
Not to break you down, but your code can be a little improved. I assume your code calculates the mean and assign it to fixedLVL. It is untested but this version should essentially do the same as you posted:
Spoiler:
Set Wild Pokémon's Levels Dynamically POKEEEMERALD
And now, you'll learn how to make Wild Pokémon's level being around the same as yours, and is easier than trainer's one...
just go to
src\wild_encounter.c
and search this:
static u8 ChooseWildMonLevel(const struct WildPokemon *wildPokemon)
Now, just replace this part:
// Make sure minimum level is less than maximum level
if (wildPokemon->maxLevel >= wildPokemon->minLevel)
{
min = wildPokemon->minLevel;
max = wildPokemon->maxLevel;
}
else
{
min = wildPokemon->maxLevel;
max = wildPokemon->minLevel;
}
range = max - min + 1;
rand = Random() % range;
with this:
u8 fixedLVL = 0;
{
if (GetMonData(&gPlayerParty[5], MON_DATA_SPECIES) != SPECIES_NONE)
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[1], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[2], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[3], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[4], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[5], MON_DATA_LEVEL)) / 6;
else if ((GetMonData(&gPlayerParty[5], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[4], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[3], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[4], MON_DATA_LEVEL)) / 5;
else if ((GetMonData(&gPlayerParty[4], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[3], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[3], MON_DATA_LEVEL)) / 4;
else if ((GetMonData(&gPlayerParty[3], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[2], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)) / 3;
else if ((GetMonData(&gPlayerParty[2], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[1], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)) / 2;
else if ((GetMonData(&gPlayerParty[1], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[0], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = GetMonData(&gPlayerParty[0], MON_DATA_LEVEL);
}
// Make sure minimum level is less than maximum level
{
min = fixedLVL-3;
max = fixedLVL+3;
}
if (min <= 0)
min = 1;
range = max - min + 1;
rand = Random() % range;
And that's it! now Wild Pokémon's levels will be minor by 3 or mayor by 3 to yours. if the "min" value is equal or minor than 0, it'll be set to one, just for the optimal calculations and a wild pokémon not having level 0 or 57.
And now, you'll learn how to make Wild Pokémon's level being around the same as yours, and is easier than trainer's one...
just go to
src\wild_encounter.c
and search this:
static u8 ChooseWildMonLevel(const struct WildPokemon *wildPokemon)
Now, just replace this part:
// Make sure minimum level is less than maximum level
if (wildPokemon->maxLevel >= wildPokemon->minLevel)
{
min = wildPokemon->minLevel;
max = wildPokemon->maxLevel;
}
else
{
min = wildPokemon->maxLevel;
max = wildPokemon->minLevel;
}
range = max - min + 1;
rand = Random() % range;
with this:
u8 fixedLVL = 0;
{
if (GetMonData(&gPlayerParty[5], MON_DATA_SPECIES) != SPECIES_NONE)
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[1], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[2], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[3], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[4], MON_DATA_LEVEL) + GetMonData(&gPlayerParty[5], MON_DATA_LEVEL)) / 6;
else if ((GetMonData(&gPlayerParty[5], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[4], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[3], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[4], MON_DATA_LEVEL)) / 5;
else if ((GetMonData(&gPlayerParty[4], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[3], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[3], MON_DATA_LEVEL)) / 4;
else if ((GetMonData(&gPlayerParty[3], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[2], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[2], MON_DATA_LEVEL)) / 3;
else if ((GetMonData(&gPlayerParty[2], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[1], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = (GetMonData(&gPlayerParty[0], MON_DATA_LEVEL)+GetMonData(&gPlayerParty[1], MON_DATA_LEVEL)) / 2;
else if ((GetMonData(&gPlayerParty[1], MON_DATA_SPECIES) == SPECIES_NONE) && (GetMonData(&gPlayerParty[0], MON_DATA_SPECIES) != SPECIES_NONE))
fixedLVL = GetMonData(&gPlayerParty[0], MON_DATA_LEVEL);
}
// Make sure minimum level is less than maximum level
{
min = fixedLVL-3;
max = fixedLVL+3;
}
if (min <= 0)
min = 1;
range = max - min + 1;
rand = Random() % range;
And that's it! now Wild Pokémon's levels will be minor by 3 or mayor by 3 to yours. if the "min" value is equal or minor than 0, it'll be set to one, just for the optimal calculations and a wild pokémon not having level 0 or 57.
Not to break you down, but your code can be a little improved. I assume your code calculates the mean and assign it to fixedLVL. It is untested but this version should essentially do the same as you posted:
Code:
static u8 ChooseWildMonLevel(const struct WildPokemon *wildPokemon)
{
u8 min;
u8 max;
u8 range;
u8 rand;
u8 count = gPlayerPartyCount;
u8 fixedLVL = 0;
while (count-- > 0)
{
if (GetMonData(&gPlayerParty[count], MON_DATA_SPECIES) != SPECIES_NONE){
fixedLVL += (GetMonData(&gPlayerParty[count], MON_DATA_LEVEL);
}
}
fixedLVL = fixedLVL / gPlayerPartyCount;
// Make sure minimum level is less than maximum level
{
min = fixedLVL-3;
max = fixedLVL+3;
}
if (min <= 0)
min = 1;
range = max - min + 1; // note that range will always be equal to 7 in this case: fixedLVL+3 - (fixedLVL-3) + 1 = fixedLVL - fixedLVL + 3 +3 +1 = 7
rand = Random() % range;
...
Last edited: