I made an ability that increases a pokemons speed stat by 3 stages when it is at half health. The issue is when the Pokemon is at half health the Ability activates twice (Until it has gone up the maximum amount of stages it can in that stat)
This is the script for the ability
Second Wind if self.hasWorkingAbility(:SECONDWIND) && self.hp<=(self.totalhp/2).floor if self.pbCanIncreaseStatStage?(PBStats::SPEED,self) self.pbIncreaseStatWithCause(PBStats::SPEED,2,self,PBAbilities.getName(self.ability)) end end
I put the script in PokeBattle_Battler ---> Ability effects ---> pbAbilitiesOnSwitchIn
Well, first thing I see that this script has no limitations on how many times it is going to run. It is going to work anytime while it has the conditions met. That's why it works twice before it maxes out the boost.
You are going to need a new check (isAlreadyActive == false) and put it in the first "if" line. Then, before the second check, just put isAlreadyActive = true.
Thanks for your help. I'll have to figure it out but one last thing when I place this code in I get an error message saying that isAlreadyActive is not defined. Do you know if essentials uses a different check or am I supposed to define it somewhere first?
There are a lot of ways you could do this. One way that I think would work and would be fairly simple is to turn on a Global control switch inside the code, then above that in the conditions for the ability check to make sure that the control switch isn't on already. That way, as long as it hasn't already been activated then it will work. If it has been activated it should avoid activating again. However, you may also have to turn the control switch off again either at the end of the battle or the end of that turn. I don't know how to do that part.