• 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!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - 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] [Pokemon Essentials v18.1] Changing Forms Based On Move Type

zedcoeur

Zed Coeur
  • 29
    Posts
    5
    Years
    • Seen Apr 15, 2022
    Hello everyone!

    So as of late, I'm working on an ability that changes the Pokemon's form, or at least changes the type, based on a move type it was hit by, reverting to standard form at the end of the turn. So for instance, Fire and Fairy type moves would activate Form 1, and Ice and Ghost type moves would activate Form 5, end of turn activating Form 0.

    I've looked at Color Change (It's what helped me make an ability that changes a Pokemon's both primary and secondary type to one that resisted the move's type), though I'm not sure how I would be able to define specifically which form/type would become upon being hit with a specific type.

    Any help would be greatly appreciated.

    PS: For those curious, yes, this and my post about a move that changes types dependent on the last type it was hit by are for legendary Pokemon. What can I say? I like to make a genuine challenge
     
    Hello everyone!

    So as of late, I'm working on an ability that changes the Pokemon's form, or at least changes the type, based on a move type it was hit by, reverting to standard form at the end of the turn. So for instance, Fire and Fairy type moves would activate Form 1, and Ice and Ghost type moves would activate Form 5, end of turn activating Form 0.

    I've looked at Color Change (It's what helped me make an ability that changes a Pokemon's both primary and secondary type to one that resisted the move's type), though I'm not sure how I would be able to define specifically which form/type would become upon being hit with a specific type.

    Any help would be greatly appreciated.

    PS: For those curious, yes, this and my post about a move that changes types dependent on the last type it was hit by are for legendary Pokemon. What can I say? I like to make a genuine challenge

    This one is easier than the other topic.
    Based on Color Change, insteado f changing the type, change the form:
    Code:
    BattleHandlers::TargetAbilityAfterMoveUse.add(:YOUR_ABILITY,
      proc { |ability,target,user,move,switched,battle|
        next if target.damageState.calcDamage==0 || target.damageState.substitute
        next if move.calcType<0 || PBTypes.isPseudoType?(move.calcType)
        next if !isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) # Just more safety
        
        new_form = target.form 
        case move.calcType
        when PBTypes::FIRE, PBTypes::FAIRY
          new_form = 1
        when blablah
          new_form = 2
          # and so on
        end 
        next if new_form == target.form # do not say it changed form if it doesn't
        
        battle.pbShowAbilitySplash(target)
        target.setForm(new_form)
        battle.pbDisplay(_INTL("{1}'s {2} made it change forms!",target.pbThis,
           target.abilityName))
        battle.pbHideAbilitySplash(target)
      }
    )

    and at the end of the turn, revert the form back to 0 by using:
    Code:
    BattleHandlers::EOREffectAbility.add(:YOUR_ABILITY,
      proc { |ability,battler,battle|
        if isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) && battler.form != 0
          battle.pbShowAbilitySplash(battler)
          battler.form=0
          battler.pbUpdate(true)
          battle.scene.pbChangePokemon(battler,battler.pokemon)
          battle.pbDisplay(_INTL("{1} reverted back to normal!",battler.pbThis))
          battle.pbHideAbilitySplash(battler)
        end
      }
    )

    Still untested but still should be close to working :)
     
    This one is easier than the other topic.
    Based on Color Change, insteado f changing the type, change the form:
    Code:
    BattleHandlers::TargetAbilityAfterMoveUse.add(:YOUR_ABILITY,
      proc { |ability,target,user,move,switched,battle|
        next if target.damageState.calcDamage==0 || target.damageState.substitute
        next if move.calcType<0 || PBTypes.isPseudoType?(move.calcType)
        next if !isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) # Just more safety
        
        new_form = target.form 
        case move.calcType
        when PBTypes::FIRE, PBTypes::FAIRY
          new_form = 1
        when blablah
          new_form = 2
          # and so on
        end 
        next if new_form == target.form # do not say it changed form if it doesn't
        
        battle.pbShowAbilitySplash(target)
        target.setForm(new_form)
        battle.pbDisplay(_INTL("{1}'s {2} made it change forms!",target.pbThis,
           target.abilityName))
        battle.pbHideAbilitySplash(target)
      }
    )

    and at the end of the turn, revert the form back to 0 by using:
    Code:
    BattleHandlers::EOREffectAbility.add(:YOUR_ABILITY,
      proc { |ability,battler,battle|
        if isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) && battler.form != 0
          battle.pbShowAbilitySplash(battler)
          battler.form=0
          battler.pbUpdate(true)
          battle.scene.pbChangePokemon(battler,battler.pokemon)
          battle.pbDisplay(_INTL("{1} reverted back to normal!",battler.pbThis))
          battle.pbHideAbilitySplash(battler)
        end
      }
    )

    Still untested but still should be close to working :)

    Alright, so I tried this, and an error shows up saying setForm is an undefined method. I tried calling pbChangeForm and even defining it within the BattleHandlers_Abilities script, but that didn't work either
     
    Alright, so I tried this, and an error shows up saying setForm is an undefined method. I tried calling pbChangeForm and even defining it within the BattleHandlers_Abilities script, but that didn't work either

    Wait, the function setForm doesn't exist for you?
    Are you sure you use v18.1?
    Anyway, replace target.setForm(new_form) with target.form = new_form.
     
    Wait, the function setForm doesn't exist for you?
    Are you sure you use v18.1?
    Anyway, replace target.setForm(new_form) with target.form = new_form.

    I really need to double-check my versions...

    Anyways, tried that as well, and the code runs through now without an error message, but it doesn't show that it actually changed the Pokemon's form. Maybe it needs to be done in the Battle_ChangeSelf script and use that method? Perhaps a pbCheckFormOnHit function?
     
    Anyways, tried that as well, and the code runs through now without an error message, but it doesn't show that it actually changed the Pokemon's form. Maybe it needs to be done in the Battle_ChangeSelf script and use that method? Perhaps a pbCheckFormOnHit function?

    What do you mean by "it doesn't show that it actually changed the Pokemon's form"?
    The sprite doesn't change?
     
    Right, and I made sure to make sprites for each form as well. Not only that, I made it so each form would change the Pokemon's signature move to another move (much like how Kyurem changes moves based on its form), and it doesn't do that either.
     
    What do you mean by "it doesn't show that it actually changed the Pokemon's form"?
    The sprite doesn't change?

    Another thing I noticed (and this confuses me even more) is I decided to set the battle to be against one of the alternate forms, and at the end of the round, the pokemon switched to its normal form. So, that part of the ability does indeed work. It's just the BattleHandlers_Abilities script that's not actually changing the form even though it says it does in the battle display message.
     
    Another thing I noticed (and this confuses me even more) is I decided to set the battle to be against one of the alternate forms, and at the end of the round, the pokemon switched to its normal form. So, that part of the ability does indeed work. It's just the BattleHandlers_Abilities script that's not actually changing the form even though it says it does in the battle display message.

    I think I see the problem. Below the line:
    Code:
          target.form = new_form
    paste this:
    Code:
          target.pbUpdate(true)
     
    Nope, that didn't do anything either. Debug time?

    Debug time :)

    Does the game tell you that the Pokémon changed its form? Does it say "{1}'s {2} made it change forms!" after being hit by a move?

    Replace the first code of the ability with:
    Code:
    BattleHandlers::TargetAbilityAfterMoveUse.add(:YOUR_ABILITY,
      proc { |ability,target,user,move,switched,battle|
        pbMessage("1")
        next if target.damageState.calcDamage==0 || target.damageState.substitute
        pbMessage("2")
        next if move.calcType<0 || PBTypes.isPseudoType?(move.calcType)
        pbMessage("3")
        next if !isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) # Just more safety
        pbMessage("4")
        
        new_form = target.form 
        case move.calcType
        when PBTypes::FIRE, PBTypes::FAIRY
          new_form = 1
        when blablah
          new_form = 2
          # and so on
        end 
        
        pbMessage(_INTL("5 ; new_form = {1}", new_form))
        pbMessage(_INTL("6 ; target.form = {1}", target.form))
        next if new_form == target.form # do not say it changed form if it doesn't
        pbMessage("7")
        
        battle.pbShowAbilitySplash(target)
        target.pbChangeForm(new_form, _INTL("{1}'s {2} made it change forms!",target.pbThis,
           target.abilityName))
        battle.pbHideAbilitySplash(target)
      }
    )
    Test the code again, and tell me which number is shown last + the values of new_form and target.form.
     
    Debug time :)

    Does the game tell you that the Pokémon changed its form? Does it say "{1}'s {2} made it change forms!" after being hit by a move?

    Replace the first code of the ability with:
    Code:
    BattleHandlers::TargetAbilityAfterMoveUse.add(:YOUR_ABILITY,
      proc { |ability,target,user,move,switched,battle|
        pbMessage("1")
        next if target.damageState.calcDamage==0 || target.damageState.substitute
        pbMessage("2")
        next if move.calcType<0 || PBTypes.isPseudoType?(move.calcType)
        pbMessage("3")
        next if !isConst?(battler.species,PBSpecies,:YOUR_LEGENDARY) # Just more safety
        pbMessage("4")
        
        new_form = target.form 
        case move.calcType
        when PBTypes::FIRE, PBTypes::FAIRY
          new_form = 1
        when blablah
          new_form = 2
          # and so on
        end 
        
        pbMessage(_INTL("5 ; new_form = {1}", new_form))
        pbMessage(_INTL("6 ; target.form = {1}", target.form))
        next if new_form == target.form # do not say it changed form if it doesn't
        pbMessage("7")
        
        battle.pbShowAbilitySplash(target)
        target.pbChangeForm(new_form, _INTL("{1}'s {2} made it change forms!",target.pbThis,
           target.abilityName))
        battle.pbHideAbilitySplash(target)
      }
    )
    Test the code again, and tell me which number is shown last + the values of new_form and target.form.

    oookay, I found the problem. When I was putting in pbChangeForm, I had put it in as a standalone function rather than target.pbChangeForm as you have it here. Now it all works perfectly fine. Though the move still doesn't appear to change upon form change. Should I be making a case for that? Like:

    case target.form

    when 0
    pkmn.moves.each do |move|
    next if !move
    if (isConst?(move.id,PBMoves,:MOVE)
    move.id = getConst(PBMoves,:NEW_MOVE)
    end
    end

    PS: Dunno how to do code formatting on this site ^^;
     
    oookay, I found the problem. When I was putting in pbChangeForm, I had put it in as a standalone function rather than target.pbChangeForm as you have it here. Now it all works perfectly fine.

    Yay! :D

    Though the move still doesn't appear to change upon form change. Should I be making a case for that? Like:

    For the move replacement, if you want to silently change the move, I think this is a good start:
    (Put this code below the pbChangeForm line)

    Code:
            # Here is a list, but if your form numbers are not contiguous, you should 
            # change this list to a "case"
            formMoves = [
               PBMoves::MOVE_FORM_0,
               PBMoves::MOVE_FORM_1,
               PBMoves::MOVE_FORM_2,
               PBMoves::MOVE_FORM_3, 
               PBMoves::MOVE_FORM_4  
            ]
            newMove = formMoves[target.form]
            
            target.moves.each_with_index do |move,i|
              # Find the move to replace: 
              next if !move
              next if !formMoves.include?(move.id)
              
              # Replace the move in the Pokémon.
              target.pokemon.moves[i].id = newMove
              
              # Replace the move for the battler; but don't forget its PP. 
              currentPP = target.moves[i].pp
              totalPP = target.moves[i].totalpp
              target.moves[i] = PokeBattle_Move.pbFromPBMove(target.battle, target.pokemon.moves[i])
              target.moves[i].pp = currentPP
              target.moves[i].totalpp = totalPP
              break
            end

    If you want the player to be asked: "X wants to learn Y, but it already knows four moves." and so on, you should adapt the code for ROTOM (Press CTRL+SHIFT+F and look for the code defining the forms of ROTOM).

    PS: Dunno how to do code formatting on this site ^^;
    Use the full editor, the brackets [CODE_] [/CODE_] without the "_"s.
     
    Yay! :D



    For the move replacement, if you want to silently change the move, I think this is a good start:
    (Put this code below the pbChangeForm line)

    Code:
            # Here is a list, but if your form numbers are not contiguous, you should 
            # change this list to a "case"
            formMoves = [
               PBMoves::MOVE_FORM_0,
               PBMoves::MOVE_FORM_1,
               PBMoves::MOVE_FORM_2,
               PBMoves::MOVE_FORM_3, 
               PBMoves::MOVE_FORM_4  
            ]
            newMove = formMoves[target.form]
            
            target.moves.each_with_index do |move,i|
              # Find the move to replace: 
              next if !move
              next if !formMoves.include?(move.id)
              
              # Replace the move in the Pokémon.
              target.pokemon.moves[i].id = newMove
              
              # Replace the move for the battler; but don't forget its PP. 
              currentPP = target.moves[i].pp
              totalPP = target.moves[i].totalpp
              target.moves[i] = PokeBattle_Move.pbFromPBMove(target.battle, target.pokemon.moves[i])
              target.moves[i].pp = currentPP
              target.moves[i].totalpp = totalPP
              break
            end

    If you want the player to be asked: "X wants to learn Y, but it already knows four moves." and so on, you should adapt the code for ROTOM (Press CTRL+SHIFT+F and look for the code defining the forms of ROTOM).


    Use the full editor, the brackets [CODE_] [/CODE_] without the "_"s.

    Okay, so it kind of works? I took off the reversion to normal for a bit, and when I'm in my next turn, it shows that it changed to the proper move.

    The problem is, let's say the move for form 0 was called Attack-PSY and the move for form 1 was Attack-FIR. After the Pokemon gets hit and switches from form 0 to form 1, it still uses Attack-PSY rather than Attack-FIR. At this point, I'm wondering if I should treat it as Weather Ball and then call each variation in a display text like Magnitude. Maybe that would work better?

    [Update]

    Tried the Weather Ball + Magnitude method, and it worked like a charm! The move is fully functional and ready to be used in any fight!
     
    Last edited:
    Nice :)
     
    Back
    Top