• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • PokéCommunity supports the Stop Killing Games movement. If you're a resident of the UK or EU, consider signing one of the petitions to stop publishers from destroying games. Click here for more information!
  • 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] Ability that reflects damage back onto the attacker

  • 79
    Posts
    9
    Years
    • Seen Jan 12, 2024
    Hello, I'm trying to create an ability that removes 25% of the damage taken from "light based moves" and reflects the removed damage back onto the attacker. For example, if a light move would normally deal 100 damage, the ability would reduce it to 75 damage, and the 25 damage that was removed would hurt the attacker.

    What I have so far, is:

    in Pokebattle_Move:

    Code:
    [SPOILER]  def isLightMove?
      return true if ( isConst?(@id,PBMoves,:SIGNALBEAM) ||
                       isConst?(@id,PBMoves,:SOLARBEAM) ||
                       isConst?(@id,PBMoves,:JUDGEMENT) ||
                       isConst?(@id,PBMoves,:TECHNOBLAST) 
                       isConst?(@id,PBMoves,:LUSTERPURGE) ||
                       isConst?(@id,PBMoves,:POWERGEM) ||
                       isConst?(@id,PBMoves,:DOOMDESIRE) ||
                       isConst?(@id,PBMoves,:FLASHCANNON) ||
                       isConst?(@id,PBMoves,:DAZZLINGGLEAM) ||
                       isConst?(@id,PBMoves,:LIGHTOFRUIN) ||
                       isConst?(@id,PBMoves,:ORIGINPULSE) ||
                       isConst?(@id,PBMoves,:PHOTONGEYSER) ||
                       isConst?(@id,PBMoves,:SOLARBLADE) ||
                       isConst?(@id,PBMoves,:MIRRORSHOT) ||
                       isConst?(@id,PBMoves,:TAILGLOW) ||
                       isConst?(@id,PBMoves,:FLASH) ||
                       isConst?(@id,PBMoves,:MOONLIGHT) ||
                       isConst?(@id,PBMoves,:LIGHTSCREEN) ||
                       isConst?(@id,PBMoves,:REFLECT) ||
                       isConst?(@id,PBMoves,:AURORABEAM) ||
                       isConst?(@id,PBMoves,:HYPERBEAM) ||
                       isConst?(@id,PBMoves,:MOONGEISTBEAM) ||
                       isConst?(@id,PBMoves,:SPOTLIGHT))
      end[/SPOILER]

    farther down in pbCalcDamage:

    Code:
        if opponent.hasWorkingAbility(:MIRRORSHIELD) && isLightMove?
            finaldamagemult=(finaldamagemult*0.75).round
        end

    Then in Pokebattle_Battler, under "if damage>0"

    Code:
          if target.hasWorkingAbility(:MIRRORSHIELD) && move.isLightMove? 
            user.pbReduceHP((turneffects[PBEffects::TotalDamage])/3)
            @battle.pbDisplay(_INTL("{1} is hurt by #{target.pbThis}'s Mirror Shield!",user.pbThis))
          end

    (since the ability is multiplying the damage by 75%, dividing the damage by 3 brings it to the 25% that I want)

    The problem is that I'm receiving this error:


    Spoiler:


    Which is strange, because I copied and altered from other abilities in the same section, so I'm not sure why "*" would cause an error. At first I thought it was coming from an interaction between the ability's Pokebattle_Move script and Pokebattle_Battler script, but removing the battler script still has the same error. Any help would be greatly appreciated!
     
    EDIT

    Turns out the script was in the wrong place, in Pokebattle_move, underneath "if !attacker.hasMoldBreaker"

    Code:
          if opponent.hasWorkingAbility(:MIRRORSHIELD) && isLightMove?
            finaldamagemult=(finaldamagemult*0.75).round
          end

    and in Pokebattle_battler, above destiny bond

    Code:
        if target.hasWorkingAbility(:MIRRORSHIELD) && thismove.isLightMove? 
          user.pbReduceHP((turneffects[PBEffects::TotalDamage])/3)
          @battle.pbDisplay(_INTL("{1} is hurt by #{target.pbThis}'s Mirror Shield!",user.pbThis))
        end

    It no longer returns an error, but the ability doesn't activate if the target faints from the light move. If they live it works as intended. How would I change it to make it work regardless of them fainting or not?
     
    I'm not 100% sure, but doesn't hasWorkingAbility have a second parameter that is "should this return true even if the Pokémon has fainted?"?

    Exactly what I was looking for, thank you!

    Changing if target.hasWorkingAbility(:MIRRORSHIELD) to if target.hasWorkingAbility(:MIRRORSHIELD,ignorefainted=true) makes it work as intended
     
    Back
    Top