• 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!
  • 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] Check if a two turns move is going to fail at the start of the move

  • 4
    Posts
    8
    Years
    • Seen May 31, 2024
    I'm new to coding and am trying to make a modified version of Sky Attack, but the catch is that if a non-Dark Pokemon tries to use it, if will fail, similar to how Dark Void can only be used by Darkrai. While it works as intended for the most part, it seems to only actually check if the move is usable (thus displaying the "But it failed!" message) during the second turn of the attack, while the first turn is spent charging regardless if the user is Dark or not. Is it possible to make the check happen during the turn the move is selected? Here is how the code looks now:
    Code:
    class PokeBattle_Move_159 < PokeBattle_Move
      def pbMoveFailed(attacker,opponent)
        return true if !attacker.pbHasType?(:DARK)
        return false
      end
    
      def pbTwoTurnAttack(attacker)
        @immediate=false
        if !@immediate && attacker.hasWorkingItem(:POWERHERB)
          @immediate=true
        end
        return false if @immediate
        return attacker.effects[PBEffects::TwoTurnAttack]==0
      end
    
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        if @immediate || attacker.effects[PBEffects::TwoTurnAttack]>0
          pbShowAnimation(@id,attacker,opponent,1,alltargets,showanimation) # Charging anim
          @battle.pbDisplay(_INTL("{1} became cloaked in a deep darkness!",attacker.pbThis))
        end
        if @immediate
          @battle.pbCommonAnimation("UseItem",attacker,nil)
          @battle.pbDisplay(_INTL("{1} became fully charged due to its Power Herb!",attacker.pbThis))
          attacker.pbConsumeItem
        end
        return 0 if attacker.effects[PBEffects::TwoTurnAttack]>0
        return super(attacker,opponent,hitnum,alltargets,showanimation)
      end
     
    Of course it is! Try to put below pbEffect instead, like:
    Code:
    class PokeBattle_Move_159 < PokeBattle_Move
      def pbTwoTurnAttack(attacker)
        @immediate=false
        if !@immediate && attacker.hasWorkingItem(:POWERHERB)
          @immediate=true
        end
        return false if @immediate
        return attacker.effects[PBEffects::TwoTurnAttack]==0
      end
    
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        if !attacker.pbHasType?(:DARK)
          @battle.pbDisplay(_INTL("But it failed!"))
          return -1
        end
        if @immediate || attacker.effects[PBEffects::TwoTurnAttack]>0
          pbShowAnimation(@id,attacker,opponent,1,alltargets,showanimation) # Charging anim
          @battle.pbDisplay(_INTL("{1} became cloaked in a deep darkness!",attacker.pbThis))
        end
        if @immediate
          @battle.pbCommonAnimation("UseItem",attacker,nil)
          @battle.pbDisplay(_INTL("{1} became fully charged due to its Power Herb!",attacker.pbThis))
          attacker.pbConsumeItem
        end
        return 0 if attacker.effects[PBEffects::TwoTurnAttack]>0
        return super(attacker,opponent,hitnum,alltargets,showanimation)
      end
     
    Thanks for the help WolfPP! But its still kinda weird. While it still works as inteded when used by a Dark, when used otherwise it stills tries to attack for 2 turns, but now it displays the failed message on each turn insted of only the last. And even weirder, when equipped with a Power Herb, it lasts for only 1 turn but the Herb is not consumed... Those two turn moves are way too confusing...
     
    Try this.

    Code:
    class PokeBattle_Move_159 < PokeBattle_Move
      def pbTwoTurnAttack(attacker)
        @immediate=false
        if !@immediate && attacker.hasWorkingItem(:POWERHERB)
          @immediate=true
        end
        if !attacker.pbHasType?(:DARK)
          @immediate=true
        end
        return false if @immediate
        return attacker.effects[PBEffects::TwoTurnAttack]==0
      end
    
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        if @immediate || attacker.effects[PBEffects::TwoTurnAttack]>0 
            if !attacker.pbHasType?(:DARK)
                @battle.pbDisplay(_INTL("But it failed!"))
          return -1
            end
    pbShowAnimation(@id,attacker,opponent,1,alltargets,showanimation) # Charging anim
          @battle.pbDisplay(_INTL("{1} became cloaked in a deep darkness!",attacker.pbThis))
        end
        if @immediate
            if !attacker.pbHasType?(:DARK)
                @battle.pbDisplay(_INTL("But it failed!"))
                 return -1
            end
     @battle.pbCommonAnimation("UseItem",attacker,nil)
          @battle.pbDisplay(_INTL("{1} became fully charged due to its Power Herb!",attacker.pbThis))
          attacker.pbConsumeItem
        end
        return 0 if attacker.effects[PBEffects::TwoTurnAttack]>0
        return super(attacker,opponent,hitnum,alltargets,showanimation)
      end
    . I'm on mobile, so the formatting might be off. But please tell me if this works or no.
     
    Thanks Golisopod User! There was missing 1 "end" on the last line of the code, but now it works as intended! The fact it has to triple check to stop the move fully baffles me...
     
    Back
    Top