• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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
8
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!
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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).
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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 ?
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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.
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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.
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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
    ---------------------------
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Yeah, so it's as I suggested, lastMoveUsed is an index into the moveset. And may be -1 if there is no last move.
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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?"
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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)?
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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?
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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.
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    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.
     
    79
    Posts
    8
    Years
    • Seen Jan 12, 2024
    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