• 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!
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] Custom move that doubles in power if a sound move was used the previous turn

  • 79
    Posts
    9
    Years
    • Seen Jan 12, 2024
    Hello, so I want to create an attack that doubles in power if a sound-based move was used by the attacker the previous turn. The move itself is also a sound move, so if it was used the previous turn it will also double in power.

    Here's the moves.txt entry in case that helps:

    692,FEEDBACKLOOP,Feedback Loop,D07,70,STEEL,Special,100,20,04,0,befk,"The user emits a powerful sound attack that doubles in power if a sound-based move was used the previous turn."

    I have no idea how to script the move, as I can't find any that search for moves used the previous turn. The closest I found was Rollout+Defense Curl, but Defense Curl is its own effect, and doesn't actually check the last turn.

    Thanks for any help!
     
    Maybe take a look at how the item Metronome or the move Echoed Voice works? They're not quite the same, but maybe similar enough? I guess you're looking for lastMoveUsed (or something like that, can't remember the exact name).
     
    Maybe take a look at how the item Metronome or the move Echoed Voice works? They're not quite the same, but maybe similar enough? I guess you're looking for lastMoveUsed (or something like that, can't remember the exact name).

    I came up with this script, but haven't been able to test it because of the pokemon.txt error lol

    Code:
    ################################################################################
    # Doubles in power if a sound move was used the previous turn (feedback loop)
    ################################################################################
    class PokeBattle_Move_D07 < PokeBattle_Move
      def pbBaseDamage(basedmg,attacker,opponent)
        if self.lastMoveUsed==self.isSoundBased?
          PBDebug.log("[Previous move sound move] #{attacker.pbThis} double feedback loop damage")
          return basedmg*2
        else
          return basedmg
        end
      end
    end

    I'm not sure if I should be using "self" or "attacker"

    If I wanted it to double if allies and opponents used a sound move as well, would I just add attacker.pbPartner.lastMoveUsed and opponent.lastMoveUsed ?
     
    You'd want to use attacker for lastMoveUsed. In this part of the code self refers to the move. I think you're probably right about the partner and opponent stuff.
     
    You'd want to use attacker for lastMoveUsed. In this part of the code self refers to the move. I think you're probably right about the partner and opponent stuff.

    The code I posted previously returned an undefinedmethod error, where it didn't recognize "isSoundBased?"

    I altered the code to:

    Code:
    class PokeBattle_Move_D07 < PokeBattle_Move
      def pbBaseDamage(basedmg,attacker,opponent)
        if attacker.lastMoveUsed==isSoundBased?
          PBDebug.log("[Previous move sound move] #{attacker.pbThis} double feedback loop damage")
          return basedmg*2
        else
          return basedmg
        end
      end
    end

    Which doesn't return an error, but doesn't double in power like it should.

    If I change '==' to '=' it always doubles in power, even when used the first turn of a battle.
     
    Don't you mean attacker.lastMoveUsed.isSoundBased? or something like that? Not sure if lastMoveUsed is actually a move object, or just an index into the attacker's moves.
     
    Don't you mean attacker.lastMoveUsed.isSoundBased? or something like that? Not sure if lastMoveUsed is actually a move object, or just an index into the attacker's moves.

    Code:
    class PokeBattle_Move_D07 < PokeBattle_Move
      def pbBaseDamage(basedmg,attacker,opponent)
        if attacker.lastMoveUsed.isSoundBased?
          PBDebug.log("[Previous move sound move] #{attacker.pbThis} double feedback loop damage")
          return basedmg*2
        else
          return basedmg
        end
      end
    end

    will return this error:

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: NoMethodError

    Message: undefined method `isSoundBased?' for -1:Fixnum

    PokeBattle_MoveEffects:1595:in `pbBaseDamage'

    PokeBattle_Move:651:in `pbCalcDamage'

    PokeBattle_Move:1383:in `pbEffect'

    PokeBattle_Battler:3015:in `pbProcessMoveAgainstTarget'

    PokeBattle_Battler:2971:in `each'

    PokeBattle_Battler:2971:in `pbProcessMoveAgainstTarget'

    PokeBattle_Battler:3474:in `pbUseMove'

    PokeBattle_Battler:3454:in `loop'

    PokeBattle_Battler:3477:in `pbUseMove'

    PokeBattle_Battler:3681:in `pbProcessTurn'



    This exception was logged in

    C:\Users\totte\Saved Games\Pokemon Essentials\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------
     
    Yeah, so it's as I suggested, lastMoveUsed is an index into the moveset. And may be -1 if there is no last move.
     
    Maybe you could take a look at how moves like Mimic or Sketch work. I assume they must look up the actual move via the index.

    looks like sketch has its own called lastMoveSketch, I'm guessing the part of mimic I should be looking at is:
    Code:
        for i in 0...attacker.moves.length
          if attacker.moves[i].id==@id
            newmove=PBMove.new(opponent.lastMoveUsed)
            attacker.moves[i]=PokeBattle_Move.pbFromPBMove(@battle,newmove)
            movename=PBMoves.getName(opponent.lastMoveUsed)
            @battle.pbDisplay(_INTL("{1} learned {2}!",attacker.pbThis,movename))
            return 0
          end
        end
        @battle.pbDisplay(_INTL("But it failed!"))
        return -1

    But I'm not sure how I should use it
     
    Maybe you could take a look at how moves like Mimic or Sketch work. I assume they must look up the actual move via the index.

    Hi, sorry for taking almost a month to respond, school+corona stuff. I can't seem to find a way to connect "attacker" to "isSoundBased?" If I use:

    Code:
    class PokeBattle_Move_D07 < PokeBattle_Move
      def pbModifyDamage(damagemult,attacker,opponent)
        [COLOR="Red"]if attacker.lastMoveUsed.id==attacker.id.isSoundBased?[/COLOR]
          return (damagemult/2.0).round
        end
        return damagemult
      end
    end

    I get an undefined method error for "isSoundBased?", and if I use:

    Code:
    class PokeBattle_Move_D07 < PokeBattle_Move
      def pbModifyDamage(damagemult,attacker,opponent)
        [COLOR="Red"]if attacker.lastMoveUsed.id==attacker.thismove.id.isSoundBased?[/COLOR]
          return (damagemult/2.0).round
        end
        return damagemult
      end
    end

    I get an undefined method error for "thismove" instead.

    Just using
    Code:
    [COLOR="Red"]if attacker.lastMoveUsed.id.isSoundBased?[/COLOR]

    will also return a method error for "isSoundBased?"
     
    Hi, sorry for taking almost a month to respond, school+corona stuff. I can't seem to find a way to connect "attacker" to "isSoundBased?"
    My memory is fuzzy now, but I think my suggestion about Sketch/Mimic was because they do a for loop over the moves looking for a move with the same ID as attacker.lastMoveUsed. Orrr, maybe lastMoveUsed is an index into the moves array (in which case you'd have to check for -1)?
     
    My memory is fuzzy now, but I think my suggestion about Sketch/Mimic was because they do a for loop over the moves looking for a move with the same ID as attacker.lastMoveUsed. Orrr, maybe lastMoveUsed is an index into the moves array (in which case you'd have to check for -1)?

    What do you mean by checking for -1?
     
    What do you mean by checking for -1?

    IIRC if no move has been used then it's a -1. But you wouldn't want to try and index an array with -1 because that counts from the end. This only matters if it really is an index.
     
    IIRC if no move has been used then it's a -1. But you wouldn't want to try and index an array with -1 because that counts from the end. This only matters if it really is an index.

    Sorry I'm still new at scripting, so i'm not really sure what indexing arrays is, or what -1 does.
     
    Sorry I'm still new at scripting, so i'm not really sure what indexing arrays is, or what -1 does.

    Just try looking at the Sketch code to see how it finds out which move was last used. I assume it must be looking at lastMoveUsed.
     
    Just try looking at the Sketch code to see how it finds out which move was last used. I assume it must be looking at lastMoveUsed.

    Sketch has its own thing called LastMoveUsedSketch:

    Code:
        if attacker.effects[PBEffects::Transform] ||
           opponent.lastMoveUsedSketch<=0 ||
           isConst?(PBMoveData.new(opponent.lastMoveUsedSketch).type,PBTypes,:SHADOW) ||
           blacklist.include?(PBMoveData.new(opponent.lastMoveUsedSketch).function)
          @battle.pbDisplay(_INTL("But it failed!"))
          return -1
        end
        for i in attacker.moves
          if i.id==opponent.lastMoveUsedSketch
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1 
          end
        end
        if opponent.pbOwnSide.effects[PBEffects::CraftyShield]
          @battle.pbDisplay(_INTL("But it failed!"))
          return -1
        end
        pbShowAnimation(@id,attacker,opponent,hitnum,alltargets,showanimation)
        for i in 0...attacker.moves.length
          if attacker.moves[i].id==@id
            newmove=PBMove.new(opponent.lastMoveUsedSketch)
            attacker.moves[i]=PokeBattle_Move.pbFromPBMove(@battle,newmove)
            [email protected](attacker.index)
            party[attacker.pokemonIndex].moves[i]=newmove
            movename=PBMoves.getName(opponent.lastMoveUsedSketch)
            @battle.pbDisplay(_INTL("{1} learned {2}!",attacker.pbThis,movename))
            return 0
          end
        end
        @battle.pbDisplay(_INTL("But it failed!"))
        return -1
      end
    end

    So I'm not sure what I parts should use
     
    Back
    Top