• 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] Need some help with Jaw Lock

  • 10
    Posts
    5
    Years
    • Seen Dec 22, 2020
    So I wanted to try to script a move myself for the first time. I'm having a few difficulties though. I'm trying to recreate the move Jaw Lock from Gen 8.
    Current state: Upon using Jaw Lock, it correctly shows the message "Both Pokémon can no longer escape!", but I can still switch out my Pokemon.
    Here's what I did.

    In PBEffects under the part where it says "These effects apply to the battle (i.e. both sides)":
    Code:
    JawLock         = 14

    In PokeBattle_MoveEffects:
    Code:
    ################################################################################
    # Deals damage and makes both the target and the user unable to switch out. 
    #(Jaw Lock)
    ################################################################################
    class PokeBattle_Move_266 < PokeBattle_Move
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        if pbIsDamaging?
          ret=super(attacker,opponent,hitnum,alltargets,showanimation)
          if opponent.damagestate.calcdamage>0 && !opponent.damagestate.substitute &&
             !opponent.isFainted?
            if opponent.effects[PBEffects::JawLock]==0 || attacker.effects[PBEffects::JawLock]==0
              @battle.field.effects[PBEffects::JawLock]=1
              @battle.pbDisplay(_INTL("Both Pokémon can no longer escape!",opponent.pbThis))
            end
          end
          return ret
        end
      end
    end

    In PokeBattle_Battle in the "pbCanSwitch?" part:
    Code:
        if @field.effects[PBEffects::JawLock]>0
          pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
          return false
        end

    Again in PokeBattle_Battle in the "pbEndOfRoundPhase" part:
    Code:
        # Jaw Lock
        if @field.effects[PBEffects::JawLock]==1
          for i in 0...4
            @field.effects[PBEffects::JawLock]=0 if @battlers[i].isFainted?
          end
        end
     
    You are checking if the Jaw Lock effect is applied to either battler when you have it defined as a field effect. It overlaps Disable, which defaults to 0, so it still activates, but that's clearly not intended.

    Also, you loop over all the batters in the end of round phase, but in a single battle, the double battle indices are both technically considered fainted, so each round automatically resets the effect.

    This last one is just a nit pick, but why set 0 and 1, when you can set it to true and false. that's a bit more explicit and lets you do just if @field.effects[PBEffects::JawLock] or if [email protected][PBEffects::JawLock] to check true and false respectively.
     
    Thanks a lot for the help! I'm still really new to scripting, so yeah, I was bound to make some mistakes like that...

    - I kind of had a logic problem because I only wanted to check for the user of Jaw Lock and the one attacked cuz the other Pokemon of a double battle should still be able to be switch. But now I see how a field effect is the complete wrong thing for that because it'd affect all four Pokemon in a double battle I'm guessing...
    - Wolf's solution with making two seperate effects for the User and the Defender is really smart and simple now that I think about it... Way better than making a field effect and trying to somehow make it only affect two of four Pokemon, as I was trying to accomplish
    - Huh, didn't know it counts the two not existing Pokemon in a single battle as fainted, that makes a lot of sense to me now
    - The thing with using True and False is smart as well, gonna keep that in mind for the future

    Thanks a bunch again to you two, I learned a lot (:
     
    Back
    Top