• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Other✓] Function Help

853
Posts
3
Years
    • Seen Nov 9, 2023
    Made a new ability and got it working just need some helping getting it to work with my custom health functions.

    What i did was in the pokemon.c I changed the shedinja health equation. First I flipped the two, so shedinja has normal health, and everything else has the old shedinja max 1 hp, and no growth on lvl up. Then I set it so instead of it being based on species shedinja, its on shedinja's ability wonder guard.

    That's worked fine, But now that I've added a new ability and with an "OR" statement to my function I can't get my second logical argument to use the same function as the first, while leaving everything else to use the second function.

    I gave up on using "else" in the first part, since I read that else applies itself to the innermost if function, so that just ensured that my second statement used the health function I didn't want it to. Right now I'm trying to get it work with specific statements and != operands.



    Attached is my file with a summary txt, with the lines for the relevant functions.
    I'm close to it being right, I just need a little help.
     

    Attachments

    • build_pokemon.c
      117.5 KB · Views: 2
    • summaryfile.txt
      197 bytes · Views: 2
    Last edited:
    247
    Posts
    6
    Years
    • Seen May 12, 2024
    I'm close to it being right, I just need a little help.

    Here's your issue. Let's walk through the code, imagining we're looking at a Shedinja with the ability Dispirit Guard.
    Code:
    	#ifdef ABILITY_WONDERGUARD
    	if (GetMonAbility(mon) == ABILITY_WONDERGUARD)
    	{
    We would not enter this if-statement, since this Shedinja doesn't have Wonderguard. This would then mean that we would jump over this statement:
    Code:
                            #ifdef SPECIES_SHEDINJA
    			#ifdef ABILITY_DISPIRITGUARD
    		if (GetMonAbility(mon) == ABILITY_DISPIRITGUARD && species == SPECIES_SHEDINJA)
    		{
    This statement is within the "if (GetMonAbility(mon) == ABILITY_WONDERGUARD)" statement, so we don't get a chance to enter it. In fact, you will never enter this statement, because you would need a Pokemon that has the ability Wonderguard to enter the first statement, and then that same Pokemon would also need the ability Dispiritguard to enter the second if-statement. It is impossible for this to occur.
    Then, once we are beyond the scope of the "if (GetMonAbility(mon) == ABILITY_WONDERGUARD)" statement, we see this statement:
    Code:
    if ((GetMonAbility(mon) != ABILITY_WONDERGUARD) || (GetMonAbility(mon) != ABILITY_DISPIRITGUARD && species != SPECIES_SHEDINJA))
    	{
    		newMaxHP = 1;
    	}
    The logic in this if-statement is as follows: If the Pokemon does not have the ability Wonderguard, it will have a new max hp of 1. This Pokemon will also have a new max hp of 1 if the Pokemon does not have Dispiritguard and is also not Shedinja. This statement would mean that our Shedinja, which has the ability Dispritguard, would have a max hp of 1 due to the first half of this if-statement. Our Shedinja doesn't have Wonderguard, thus it has 1 hp.

    Now, here's how I would rewrite this section of code:
    Code:
    #ifdef ABILITY_WONDERGUARD
    	if (GetMonAbility(mon) == ABILITY_WONDERGUARD)
    	{
    		u32 n = 2 * baseHP + ivs[STAT_HP];
    		newMaxHP = MathMin((((n + evs[STAT_HP] / 4) * level) / 100) + level + 10, 0xFFFF);
            }
    	#ifdef SPECIES_SHEDINJA
    	#ifdef ABILITY_DISPIRITGUARD
    	else if (GetMonAbility(mon) == ABILITY_DISPIRITGUARD && species == SPECIES_SHEDINJA)
    	{
    		u32 n = 2 * baseHP + ivs[STAT_HP];
    		newMaxHP = MathMin((((n + evs[STAT_HP] / 4) * level) / 100) + level, 0xFFFF);
    	}
    	else
    	{
    		newMaxHP = 1;
    	}
    		#endif
    		#endif
    	#endif
    If you want to be sure that this code works, I've provided a few examples in the spoiler below that you can walk through to see the process this code would go through with different Pokemon.

    Examples
    Spoiler:
     
    Back
    Top