# Help with an Evolution on Faint Trigger?

#### SJFzone

##### Novice
Member
I had this idea to evolve Vaporeon, Jolteon, and Flareon when they faint if their happiness was high enough while a Ho-Oh is in the party, as a reference to the fan theory that the Legendary Beasts are reincarnated versions of the OG eeveelutions. I've gotten close to that goal, but the only default triggers in Essentials for evolution are level, item, or trade, not faint. I got to the point where they evolve when their HP is below 5 after they level up, with the code pasted below, but I feel it would be better if it triggers when HP reaches 0 instead of level up. Where does the game trigger evolutions for the different triggers, (pbMiniCheckEvolution, pbMiniCheckEvolutionItem, PBEvolution, whatever it might be) so I can find it and create a new trigger for reaching 0 HP? Any help would be appreciated.

when PBEvolution::HasInPartyFaint #Legendary Dogs
return poke if pokemon.hp<=5 && pokemon.happiness>=220

(I'd imagine the pokemon.hp<=5 would be removed when the 0 HP trigger is used, but this is what I have now.

#### NettoHikari

##### Cooltrainer
Member
The first issue is that "pbEvolutionCheck", which is the main method for checking evolution, automatically blocks it for all fainted Pokemon. You can remove that restriction by removing
Ruby:
next if pokemon.hp==0 && !USENEWBATTLEMECHANICS
from that method, though keep in mind that this will also allow fainted Pokemon who evolve by leveling up or through an item to evolve, too.

The second issue is that the method "pbMiniCheckEvolution" triggers when a Pokemon levels up, and "pbMiniCheckEvolutionItem" triggers when an item is used on a Pokemon, so you wouldn't want to put your code in either method. You probably need to make your own mini check method, like "pbMiniCheckEvolutionFaint", and then modify the method "pbCheckEvolution" (different from "pbEvolutionCheck") like so:
Ruby:
def pbCheckEvolution(pokemon,item=0,faint=false)
if faint
return pbCheckEvolutionEx(pokemon){|pokemon,evonib,level,poke|
next pbMiniCheckEvolutionFaint(pokemon,evonib,level,poke)
}
elsif item==0
return pbCheckEvolutionEx(pokemon){|pokemon,evonib,level,poke|
next pbMiniCheckEvolution(pokemon,evonib,level,poke)
}
else
return pbCheckEvolutionEx(pokemon){|pokemon,evonib,level,poke|
next pbMiniCheckEvolutionItem(pokemon,evonib,level,poke,item)
}
end
end

You can probably figure this part out, but the method "pbMiniCheckEvolutionFaint" would look very similar to the other two methods:
Ruby:
def pbMiniCheckEvolutionFaint(pokemon,evonib,level,poke)
case evonib
when PBEvolution::HasInPartyFaint
return poke if pokemon.hp == 0
end
return -1
end

Finally, you'd need "pbCheckEvolution" to trigger separately with "faint" set to true, which you can do in "pbEvolutionCheck" by finding this line and adding the line below:
Ruby:
newspecies = Kernel.pbCheckEvolution(pokemon) # Find this
newspecies = Kernel.pbCheckEvolution(pokemon,0,true) if newspecies <= 0 # Add this below

As you can see, this became a lot more complicated since you're trying to add an evolution method where the Pokemon's level doesn't actually matter. Hopefully this makes sense!

#### SJFzone

##### Novice
Member
Thank you so much, your help was incredible and it worked like a charm!

A couple things for those who read this later, as I was confused at first:
1. The next if statement that you have to remove and the newspecies = statement are both located in PField_Battles
2. When you remove the "next if" statement, make sure you change the next line to be a "next if" statement, too, so the whole definition will look like this below.

Code:
def pbEvolutionCheck(currentlevels)
for i in 0...currentlevels.length
pokemon = $Trainer.party[i] next if pokemon && (!currentlevels[i] || pokemon.level!=currentlevels[i]) newspecies = Kernel.pbCheckEvolution(pokemon) newspecies = Kernel.pbCheckEvolution(pokemon,0,true) if newspecies <= 0 if newspecies>0 evo = PokemonEvolutionScene.new evo.pbStartScreen(pokemon,newspecies) evo.pbEvolution evo.pbEndScreen end end end #### NettoHikari ##### Cooltrainer Member 2. When you remove the "next if" statement, make sure you change the next line to be a "next if" statement, too, so the whole definition will look like this below. Hm, wouldn't this break normal evolution by level up, though? Actually, I think you should rearrange pbEvolutionCheck to look like this: Ruby: def pbEvolutionCheck(currentlevels) for i in 0...currentlevels.length pokemon =$Trainer.party[i]
newspecies = Kernel.pbCheckEvolution(pokemon,0,true)
if pokemon && (!currentlevels[i] || pokemon.level!=currentlevels[i])
newspecies = Kernel.pbCheckEvolution(pokemon) if newspecies <= 0
end
if newspecies>0
evo = PokemonEvolutionScene.new
evo.pbStartScreen(pokemon,newspecies)
evo.pbEvolution
evo.pbEndScreen
end
end
end
This way it's first checking if it can evolve from fainting, then checks if it can evolve by normal level up, and if either of those are true it'll start the evolution.

#### SJFzone

##### Novice
Member
Hm, wouldn't this break normal evolution by level up, though?
Strange, it wouldn't trigger evolutions for me unless I changed that line. Just tested level-up out on a Magikarp and looks like it works either way, but hey! Now anyone who wants to do this has two different ways of formatting the code! Thanks again for all your help, I'll definitely try using your second option if anything comes up.

#### NettoHikari

##### Cooltrainer
Member
Strange, it wouldn't trigger evolutions for me unless I changed that line. Just tested level-up out on a Magikarp and looks like it works either way, but hey! Now anyone who wants to do this has two different ways of formatting the code! Thanks again for all your help, I'll definitely try using your second option if anything comes up.
Ah, you're right, I didn't realize that the original default pbEvolutionCheck only triggered pbCheckEvolution if the Pokemon had changed levels. I was pretty certain that your version would break level-up evolutions, because the line
Code:
next if pokemon && (!currentlevels[i] || pokemon.level!=currentlevels[i])
should mean to skip checking the Pokemon if it changed level during battle, but I guess if it still worked then that's good. Kinda peculiar, though.

#### SJFzone

##### Novice
Member
Ah, you're right, I didn't realize that the original default pbEvolutionCheck only triggered pbCheckEvolution if the Pokemon had changed levels. I was pretty certain that your version would break level-up evolutions, because the line
Code:
next if pokemon && (!currentlevels[i] || pokemon.level!=currentlevels[i])
should mean to skip checking the Pokemon if it changed level during battle, but I guess if it still worked then that's good. Kinda peculiar, though.
Hold on, you're right! I tested it out with a rare candy, not in battle. In battle, it IS broken my way! Okay, that clears things up.