• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • 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.

[Scripting Question] Need Help With New Ability

  • 19
    Posts
    2
    Years
    • Age 22
    • He/Him
    • Seen Apr 30, 2025
    Okay, so, I've been working on a custom ability called Inflation for a Pokemon called Squicopter (Lame name I know but it'll probably change). Basically, the Pokemon inflates and deflates like a balloon depending on its HP, and as a result will take a certain amount of damage each time, like Multiscale. However, whenever a Pokemon tries to hit Squicopter with the ability active, an error message pops up. I checked the backtrace, and this is the only plausible area for where there could be an issue. Here's said script.

    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        mults[:final_damage_multiplier] /= 2 if battle.isSpecies?(:SQUICOPTER) && target.hp > taget.totalhp / 1.5
      }
    )
    
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        mults[:final_damage_multiplier] /= 1.6 if battler.isSpecies?(:SQUICOPTER) && target.hp <= taget.totalhp / 1.5
      }
    )
    
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        mults[:final_damage_multiplier] /= 1.2 if battler.isSpecies?(:SQUICOPTER) && target.hp <= target.totalhp / 2
      }
    )
    
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|   
        mults[:final_damage_multiplier] /= 0.8 if battler.isSpecies?(:SQUICOPTER) && target.hp <= target.totalhp / 4
      }
    )

    Basically the idea is that it takes x2 less damage at 4/4 health, x1.6 at 3/4 health, x1.2 at 2/4 health, and x0.8 at 1/4 health. But what's the issue? I tried to copying code from both Multiscale and other form changing abilities like Zen Mode, but I'm still unsure if this is actually the correct way of doing this.
     
    Posting the actual error would help. I have no idea if this is a syntax issue, a nill class issue, or what.

    Btw, all of your code is overwriting themselves since they are all duplicating the same ability handler. So only the last entry for Inflation is being checked.
     
    Here's the error.

    Spoiler:


    As for the duplicates, yeah I was worried about that. I tried to put it all under one using elsif, but it didn't work properly. Do you have any suggestions as to how to do it?
     
    Here's the error.

    Spoiler:


    As for the duplicates, yeah I was worried about that. I tried to put it all under one using elsif, but it didn't work properly. Do you have any suggestions as to how to do it?

    The error is due to you calling for "battler" when no such thing is defined in this code. What you're looking for is "target", since target in this instance is referring to the owner of the ability when hit. Hence why you're checking for target.hp in the first place.

    In fact, I would just remove the entire species check altogether. I don't really see the need for it, if this ability is going to be exclusive to that particular species any way. Removing it entirely would resolve the error.

    And lastly, there's no real reason why you couldn't combine all four of these into a single handler using "elsif". It probably didn't work earlier due to your error. Also, I would check your damage calculations. Dividing by 0.8 actually increases the final damage calculation, it doesn't reduce it.
     
    Well, I changed the code to this.

    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        mults[:final_damage_multiplier] /= 2 if target.hp > taget.totalhp / 1.5
      elsif
        mults[:final_damage_multiplier] /= 1.6 if target.hp <= taget.totalhp / 1.5
      elsif
        mults[:final_damage_multiplier] /= 1.2 if target.hp <= target.totalhp / 2  
      elsif
        mults[:final_damage_multiplier] /= 0.8 if target.hp <= target.totalhp / 4
      }
    )

    But like last time, I can't start the game due to a syntax error.

    Spoiler:


    As for the whole battler thing, I'm not sure what exactly you're referring to. I certainly don't see in under ability effects, and otherwise, I just used code similar to other form-changing abilities in places such as Battler_ChangeSelf. And for the 0.8, the point is that when it's at 1/4 health or lower, it actually takes MORE damage. So I think I didn't do anything wrong there. The ability is only a benefit when it's above 1/4, in order to prevent it from being too broken.
     
    Well, I changed the code to this.

    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        mults[:final_damage_multiplier] /= 2 if target.hp > taget.totalhp / 1.5
      elsif
        mults[:final_damage_multiplier] /= 1.6 if target.hp <= taget.totalhp / 1.5
      elsif
        mults[:final_damage_multiplier] /= 1.2 if target.hp <= target.totalhp / 2  
      elsif
        mults[:final_damage_multiplier] /= 0.8 if target.hp <= target.totalhp / 4
      }
    )

    But like last time, I can't start the game due to a syntax error.

    Spoiler:

    Well you're definitely gonna be getting syntax errors with that, it's not formatted correctly at all. You have to actually begin an "if" statement in order to use an "elsif". You don't have an if statement, you just have four unrelated "do x if y" statements. You can't just throw an "elsif" anywhere by itself, it needs to be actually paired with something to determine the truth value of something.

    It needs to be read like "If A is true then do B, else if C is true then do D, else if E is true then do F" etc.

    As so:
    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        if target.hp > taget.totalhp / 1.5
          mults[:final_damage_multiplier] /= 2 
        elsif target.hp <= taget.totalhp / 1.5
          mults[:final_damage_multiplier] /= 1.6 
        elsif target.hp <= target.totalhp / 2 
          mults[:final_damage_multiplier] /= 1.2  
        elsif target.hp <= target.totalhp / 4
          mults[:final_damage_multiplier] /= 0.8
        end
      }
    )

    As for the whole battler thing, I'm not sure what exactly you're referring to. I certainly don't see in under ability effects, and otherwise, I just used code similar to other form-changing abilities in places such as Battler_ChangeSelf. And for the 0.8, the point is that when it's at 1/4 health or lower, it actually takes MORE damage. So I think I didn't do anything wrong there. The ability is only a benefit when it's above 1/4, in order to prevent it from being too broken.

    By "battler", I was referring to your literal use of "battler" in battler.isSpecies?(:SQUICOPTER). No where in this code is "battler" defined, hence why you were getting an error. It may be defined in Battler_ChangeSelf, but that has nothing to do with the code found here. This code specifies for you exactly which variables are defined in the line |ability, user, target, move, mults, baseDmg, type|. Where "user" is referring to the user of the move that is attacking the ability holder, and "target" is referring to the ability holder.
     
    Well, I changed the code to yours, but while I managed to boot up the game, whenever an enemy attacked me, another error popped up. Here it is:

    [Pokémon Essentials version 20.1]
    [v20.1 Hotfixes 1.0.3]

    Spoiler:


    Is there another area the problem could be in?
     
    Well, I changed the code to yours, but while I managed to boot up the game, whenever an enemy attacked me, another error popped up. Here it is:

    [Pokémon Essentials version 20.1]
    [v20.1 Hotfixes 1.0.3]

    Spoiler:


    Is there another area the problem could be in?

    Look at your spelling. The error is telling you what the typo is.
    I just copy/pasted the code you had, so what you originally had must've contained typos.
     
    Well, the Pokemon are able to damage me now, but I'm not sure if the ability is really working. It doesn't seem consistent. Like when I'm under 3/4 health, inflation pops up, but at 2/4, it doesn't. The amount of damage I take doesn't always seem right either. It's hard to explain without showing you. But here's the code.

    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        if target.hp > target.totalhp / 1.5
          mults[:final_damage_multiplier] /= 2 
        elsif target.hp <= target.totalhp / 1.5
          mults[:final_damage_multiplier] /= 1.6 
        elsif target.hp <= target.totalhp / 2 
          mults[:final_damage_multiplier] /= 1.2  
        elsif target.hp <= target.totalhp / 4
          mults[:final_damage_multiplier] /= 0.8
        end
      }
    )

    I also checked the change self scripts, so here it is. I don't think any of these inflation messages actually popped up. Only the name of the ability.

    Code:
       # Squicopter - Inflation
        if isSpecies?(:SQUICOPTER) && self.ability == :INFLATION
          if @hp <= @totalhp / 1.5
            if @form != 1
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 1, _INTL("{1} is slightly deflated!", abilityName))
            end
          elsif @hp > @totalhp / 1.5
            if @form != 0
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 0, _INTL("{1} is inflated!", abilityName))
            end
          elsif @hp <= @totalhp / 2
            if @form != 2
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 2, _INTL("{1} is somewhat deflated!", abilityName))
            end
          elsif @hp <= @totalhp / 4
            if @form != 3
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 3, _INTL("{1} is fully deflated!", abilityName))
            end
          end
        end
     
    Well, the Pokemon are able to damage me now, but I'm not sure if the ability is really working. It doesn't seem consistent. Like when I'm under 3/4 health, inflation pops up, but at 2/4, it doesn't. The amount of damage I take doesn't always seem right either. It's hard to explain without showing you. But here's the code.

    Code:
    Battle::AbilityEffects::DamageCalcFromTarget.add(:INFLATION,
      proc { |ability, user, target, move, mults, baseDmg, type|
        if target.hp > target.totalhp / 1.5
          mults[:final_damage_multiplier] /= 2 
        elsif target.hp <= target.totalhp / 1.5
          mults[:final_damage_multiplier] /= 1.6 
        elsif target.hp <= target.totalhp / 2 
          mults[:final_damage_multiplier] /= 1.2  
        elsif target.hp <= target.totalhp / 4
          mults[:final_damage_multiplier] /= 0.8
        end
      }
    )

    I also checked the change self scripts, so here it is. I don't think any of these inflation messages actually popped up. Only the name of the ability.

    Code:
       # Squicopter - Inflation
        if isSpecies?(:SQUICOPTER) && self.ability == :INFLATION
          if @hp <= @totalhp / 1.5
            if @form != 1
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 1, _INTL("{1} is slightly deflated!", abilityName))
            end
          elsif @hp > @totalhp / 1.5
            if @form != 0
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 0, _INTL("{1} is inflated!", abilityName))
            end
          elsif @hp <= @totalhp / 2
            if @form != 2
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 2, _INTL("{1} is somewhat deflated!", abilityName))
            end
          elsif @hp <= @totalhp / 4
            if @form != 3
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(@form = 3, _INTL("{1} is fully deflated!", abilityName))
            end
          end
        end

    The way in which you order your "elseif's" matters. It checks them in descending order, and if the conditions are true with one of them, it'll run the code for that elsif, and ignore everything after it.

    So going down how you listed things in your code, it will check things in this order:
    • if @hp <= @totalhp / 1.5 aka "Is the Pokemon's HP less than/equal to 66%?"
      If true, the rest of the code below is ignored and no further checks are made.

    • elsif @hp > @totalhp / 1.5 aka "Is the Pokemon's HP greater than/equal to 66%?"
      If true, the rest of the code below is ignored and no further checks are made.

    • elsif @hp <= @totalhp / 2 aka "Is the Pokemon's HP less than/equal to 50%?"
      If true, the rest of the code below is ignored and no further checks are made.

    • elsif @hp <= @totalhp / 4 aka "Is the Pokemon's HP less than/equal to 25%?"
      This is the final check.


    If you follow the logic, it should be clear why it's not working. The checks for 50% and 25% HP never occur, because if the Pokemon's HP is within those low ranges, it will automatically mean that the conditions for the first check (equal to or below 66%) is satisfied first, so that's the code that is run, with everything else being ignored. To remedy this, I would reorganize your statement so that it checks for the lowest amount of HP first, up to the highest. This way, there isn't any way for the code to get "stuck". The same would also have to be done for the ability code itself, too.

    Secondly, you need to remove the @form = from each instance of pbCheckForm. All you need is the form number to change into.
     
    Back
    Top