You should consider joining our Discord to ask for support.

We created a support channel using the new Discord Forum feature!

You can also visit our new website, it has a help section in English and French

0 like 0 dislike
411 views
in Script help by (540 points)

Trying to get an ability that heals the user 1/4th of the damage dealt when using a bite move, but since I'm not familiar with abilities at all I can't even get this one to trigger and could use help.

#Heal user for 1/4th damage dealt when using bite moves

module Battle

  module Effects

    class Ability

      class Vampirism < Ability

        def on_post_damage(handler, hp, target, launcher, skill)

          newHp = (hp/4)

          return if target != @target || target.effects.has?(:heal_block)

          return unless skill&.bite?

          handler.scene.visual.show_ability(target)

          logic.damage_handler.heal(target, newHp)

        end

      end

      register(:vampirism, Vampirism)

    end

  end

end

2 Answers

0 like 0 dislike
by (540 points)
 
Best answer

Got it working, decided to nerf it a bit. Checks for liquid ooze, heal block, and if the user is holding big root!

#Heal user for 1/8th damage dealt when using bite moves

module Battle

  module Effects

    class Ability

      class Vampirism < Ability

        def on_post_damage(handler, hp, target, launcher, skill)

  new_hp = (hp/8).floor.clamp(1, Float::INFINITY) #Sets it to a minimum of 1

  new_hp = new_hp*130/100 if(launcher.item_db_symbol == :big_root) #Big root check

  log_data("Launcher item DB symbol: #{launcher.item_db_symbol}")

  log_data("Target item DB symbol: #{target.item_db_symbol}")

  log_data("Damage = #{hp} new_hp = #{new_hp}")

  log_data("Bite move: #{skill&.bite?}")

  log_data("Heal block effect: #{launcher.effects.has?(:heal_block)}") 

          return unless skill&.bite? && target != @target && !launcher.effects.has?(:heal_block) #Heal block check

          handler.scene.visual.show_ability(launcher) #Shows that vampirism activated

  if (target.ability_db_symbol == :liquid_ooze) #Liquid ooze check

    handler.scene.visual.show_ability(target) #Shows that liquid ooze activated

            handler.damage_change(new_hp, launcher, launcher, nil) #Damages user

  else

    handler.logic.damage_handler.heal(launcher, new_hp) #Heals user

  end

        end

#In case they die, you'll still heal

def on_post_damage_death(handler, hp, target, launcher, skill)

  new_hp = (hp/8).floor.clamp(1, Float::INFINITY) #Sets it to a minimum of 1

  new_hp = new_hp*130/100 if(launcher.item_db_symbol == :big_root) #Big root check

  log_data("Launcher item DB symbol: #{launcher.item_db_symbol}")

  log_data("Target item DB symbol: #{target.item_db_symbol}")

  log_data("Damage = #{hp} new_hp = #{new_hp}")

  log_data("Bite move: #{skill&.bite?}")

  log_data("Heal block effect: #{launcher.effects.has?(:heal_block)}") 

          return unless skill&.bite? && target != @target && !launcher.effects.has?(:heal_block) #Heal block check

          handler.scene.visual.show_ability(launcher) #Shows that vampirism activated

  if (target.ability_db_symbol == :liquid_ooze) #Liquid ooze check

    handler.scene.visual.show_ability(target) #Shows that liquid ooze activated

            handler.damage_change(new_hp, launcher, launcher, nil) #Damages user

  else

    handler.logic.damage_handler.heal(launcher, new_hp) #Heals user

  end

        end

      end

      register(:vampirism, Vampirism)

    end

  end

end

0 like 0 dislike
by (28.0k points)

First of all, can you check if the target has the right ability effect.
If the player Pokémon has this ability, when writing $scene.logic.battler(0, 0).ability_effect should write something like #<Battle::Effects::Ability::Vampirism ...>

If so, then it's probable that your condition is not working, in that case you should print all part of the condition before executing it so you'll see the value and maybe understand why it doesn't work.

...