- 183
- Posts
- 7
- Years
- Seen Jan 22, 2025
And after a lot of try and error, I finally managed to get this thing working.
The features that this presents are simple;
how to implement it?
just go to src/battle_main.c and inside of CreateNPCTrainerParty, define this: (thanks to DdraigZek and WiserVisor for upgrading a little bit my code and adding some cool features!)
After that, search "for (i = 0; i < monsCount; i++)
{" and just below that, add this:
And, above "gBattleTypeFlags |= gTrainers[trainerNum].doubleBattle;", paste this " dynamicLevel -= rand_diff + PartyLevelAdjust;"
It should look like this: (thanks, vxo)
Now, search "CreateMon(&party, partyData.species" and replace the whole line with this:
This'll make the changes only appear when your team is overleveled, so you'll still have to grind a little and stuff
Evolution feature! (thanks to WiserVisor )
add this below "static void HandleAction_ActionFinished(void);":
I just added the last function definition at the end of this list.
Then, at each instance of
[/code]
if (partyData.lvl >= dynamicLevel)
CreateMon(&party, partyData.species, partyData.lvl, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
else
CreateMon(&party, partyData.species, dynamicLevel - levelDifference, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
[/code]
You replace it with this:
Finally, add this to the end:
This function checks to see if the Pokemon, at the given level, will evolve. It will also check if it can evolve a second time at the given level. It returns the proper species value if it can evolve, or it returns 0 if it can't.
Hope you enjoy this!
The features that this presents are simple;
- Trainer Pokémon's level are 2 levels less, 2 more and everything in-between if you're overleveled
- takes the average of yout level by adding the level of all the pokemon in your party and dividing it by the amount of pokemon in your party, taking into consideration the highest level in your team, and its difference with the lowest to make less probable that people can take advantage of this to win
- if its a decimal number, its rounded down
- if the results gives 2 or 1, it changes the result for 3, because if not, when it makes the rest, it gives zero or minus one
how to implement it?
just go to src/battle_main.c and inside of CreateNPCTrainerParty, define this: (thanks to DdraigZek and WiserVisor for upgrading a little bit my code and adding some cool features!)
Code:
u16 dynamicLevel = 0;
// This is used to hold the level's of the player's strongest[1] and weakest[0] Pokemon
u8 LevelSpread[] = {0, 0};
// This will be used when assigning the level of the opponent's Pokemon
u16 PartyLevelAdjust;
// Change stuff like this to get the levels you want
static const u8 minDynamicLevel = 3;
static const u8 maxDynamicLevel = 98;
// Calculates Average of your party's levels
for(i = 0; i < PARTY_SIZE; i++)
{
if(GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == SPECIES_NONE)
{
if(i != 0)
dynamicLevel /= i;
break;
}
dynamicLevel += GetMonData(&gPlayerParty[i], MON_DATA_LEVEL);
if(i == 0)
{
LevelSpread[0], LevelSpread[1] = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL);
}
else
{
u8 LevelCheck = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL);
if(LevelCheck < LevelSpread[0])
LevelSpread[0] = LevelCheck;
else if(LevelCheck > LevelSpread[1])
LevelSpread[1] = LevelCheck;
}
}
if(i == PARTY_SIZE)
dynamicLevel /= i;
/* The following is used to account for a player having one or two very weak Pokemon
along with some very strong Pokemon. It weights the averaged level more towards the
player's strongest Pokemon
*/
PartyLevelAdjust = LevelSpread[1] - LevelSpread[0];
if(LevelSpread[1] - dynamicLevel < 10)
{
PartyLevelAdjust = 0;
}
else if(LevelSpread[1] - dynamicLevel < 20)
{
PartyLevelAdjust /= 10;
}
else if(LevelSpread[1] - dynamicLevel < 30)
{
PartyLevelAdjust /= 5;
}
else if(LevelSpread[1] - dynamicLevel < 40)
{
PartyLevelAdjust *= 3;
PartyLevelAdjust /= 10;
}
else if(LevelSpread[1] - dynamicLevel < 50)
{
PartyLevelAdjust *= 2;
PartyLevelAdjust /= 5;
}
else if(LevelSpread[1] - dynamicLevel < 60)
{
PartyLevelAdjust /= 2;
}
else if(LevelSpread[1] - dynamicLevel < 70)
{
PartyLevelAdjust *= 3;
PartyLevelAdjust /= 5;
}
else if(LevelSpread[1] - dynamicLevel < 80)
{
PartyLevelAdjust *= 7;
PartyLevelAdjust /= 10;
}
else if(LevelSpread[1] - dynamicLevel < 90)
{
PartyLevelAdjust *= 4;
PartyLevelAdjust /= 5;
}
//Handling values to be always be in the range,
// ( minDynamiclevel-levelDifference , maxDynamiclevel+levelDifference )
if(dynamicLevel < minDynamicLevel) dynamicLevel = minDynamicLevel;
else if(dynamicLevel > maxDynamicLevel) dynamicLevel = maxDynamicLevel;
{" and just below that, add this:
Code:
int rand_diff = Random() % 5;
switch(rand_diff)
{
case 0:
rand_diff = 2;
break;
case 1:
rand_diff = 1;
break;
case 2:
rand_diff = 0;
break;
case 3:
rand_diff = -1;
break;
case 4:
rand_diff = -2;
}
It should look like this: (thanks, vxo)
Code:} } dynamicLevel -= rand_diff + PartyLevelAdjust; } gBattleTypeFlags |= gTrainers[trainerNum].doubleBattle;
Now, search "CreateMon(&party, partyData.species" and replace the whole line with this:
Code:
if (partyData[i].lvl >= dynamicLevel)
CreateMon(&party[i], partyData[i].species, partyData[i].lvl, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
else
CreateMon(&party[i], partyData[i].species, dynamicLevel, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
Evolution feature! (thanks to WiserVisor )
Spoiler:
add this below "static void HandleAction_ActionFinished(void);":
Code:
u16 HasLevelEvolution(u16 species, u8 level);
Then, at each instance of
[/code]
if (partyData.lvl >= dynamicLevel)
CreateMon(&party, partyData.species, partyData.lvl, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
else
CreateMon(&party, partyData.species, dynamicLevel - levelDifference, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
[/code]
You replace it with this:
Code:
if (partyData[i].lvl >= dynamicLevel)
CreateMon(&party[i], partyData[i].species, partyData[i].lvl, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
else
{
if(HasLevelEvolution(partyData[i].species, dynamicLevel))
CreateMon(&party[i], HasLevelEvolution(partyData[i].species, dynamicLevel), dynamicLevel, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
else
CreateMon(&party[i], partyData[i].species, dynamicLevel, fixedIV, TRUE, personalityValue, OT_ID_RANDOM_NO_SHINY, 0);
}
Code:
u16 HasLevelEvolution(u16 species, u8 level)
{
if(gEvolutionTable[species][0].param && gEvolutionTable[species][0].param <= level)
{
if(HasLevelEvolution(gEvolutionTable[species][0].targetSpecies, level))
return HasLevelEvolution(gEvolutionTable[species][0].targetSpecies, level);
else
return gEvolutionTable[species][0].targetSpecies;
}
return 0;
}
Hope you enjoy this!
Last edited: