• 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] Having trouble with coding a form change mid battle

2
Posts
1
Years
    • Seen Oct 1, 2023
    Hey guys!

    I've never coded before, and decided to tackle a custom ability.

    Essentially, I want the specific pokemon to change into a different sprite when they become Poisoned.

    I tried my best to make this happen, replicating the Form Change info from Castform, but, it isn't working. Nothing happens when the Pokemon is Poisoned.

    If someone could help, I'd be extremely grateful!

    Here is the code I have atm!

    Code:
     if isSpecies?(:AIPOM)
          if hasActiveAbility?(:HUNGRYFORNOODLES)
            newForm = 0
            case pbHasAnyStatus?
            when :POISON then newForm = 1
            end
            if @form != newForm
              @battle.pbShowAbilitySplash(self, true)
              @battle.pbHideAbilitySplash(self)
              pbChangeForm(newForm, _INTL("{1} transformed!", pbThis))
            end
          else
            pbChangeForm(0, _INTL("{1} transformed!", pbThis))
          end
        end
     
    Last edited by a moderator:

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    The problem resides in these lines:
    Code:
            case pbHasAnyStatus?
            when :POISON then newForm = 1
            end
    You should use "case" only when you want to check a value and have different outcomes depending on that value. Also note that there is a syntax error; there is no "then" after a "when". If you write on one line, you have to replace "then" with ";".
    In your case here, you could write:

    Code:
            case @status
            when :POISON ; newForm = 1 
            when :BURN ; newForm = 2 # This is an example, you don't need to define a form for burn.
            end

    Now, the function "pbHasAnyStatus?" only returns true or false if the Pokémon has a status or not, but it doesn't return said status. Now, you want to trigger the ability only if the Pokémon is poisoned, which you can check with the dedicated function "poisoned?":

    Code:
            if poisoned?
              newForm = 1 
            end

    Now here is more information on the code. I don't know which version of Essentials you are using; I'll assume you are using v20.
    When defining an ability or an item, it's a good idea to check out the instances of Battle::AbilityEffects (they were called "BattleHandlers" in V18). Battle::AbilityEffects are a very elegant way to define effects that abilities may have (similar code exists for items).
    In your example, you want to trigger a form change when your Pokémon gets poisoned. What other abilities are triggered when a status is inflicted? There is one I can think of: Synchronize. So look for the code of Synchronize (on RPG Maker, Ctrl+Shift+F to search all the scripts at once).
    You can find its code:

    Code:
    Battle::AbilityEffects::OnStatusInflicted.add(:SYNCHRONIZE,
      proc { |ability, battler, user, status|
        # And lots of code
      }
    }

    You can copy this for your "HUNGRYFORNOODLES":

    Code:
    Battle::AbilityEffects::OnStatusInflicted.add(:HUNGRYFORNOODLES,
      proc { |ability, battler, user, status|
        # We're filling this code here
      }
    }

    Now AbilityEffects use different keywords compared to the other functions. You shouldn't write "return", but "next".
    So, if you want your ability to trigger only when poison is inflicted, you should go "next" if the status is not poison:

    Code:
    Battle::AbilityEffects::OnStatusInflicted.add(:HUNGRYFORNOODLES,
      proc { |ability, battler, user, status|
        next if status != :POISON
        # We're filling this code here
      }
    }

    And then the rest of your code should fit in, with some adaptation:

    Code:
    Battle::AbilityEffects::OnStatusInflicted.add(:HUNGRYFORNOODLES,
      proc { |ability, battler, user, status| # "user" refers to the Pokémon that is using the move that poisoned you. The targeted Pokémon is "battler"
        next if status != :POISON # Don't trigger this code if the status is not poison.
        newForm = 1 # The new form is necessarily 1, according to your code.
        if battler.form != newForm # don't trigger if the Pokémon has already changed its form
            battler.battle.pbShowAbilitySplash(battler)
            battler.pbChangeForm(newForm, _INTL("{1} transformed!", battler.pbThis))
            battler.battle.pbHideAbilitySplash(battler) # Put this after the code you want to activate, so the player sees the effect before the ability splash disappears.
        end
      }
    }

    You should be good to go :)
     
    2
    Posts
    1
    Years
    • Seen Oct 1, 2023
    I tried to implement the code you gave me - I'm having some real issues! Please forgive me, this is my first ever project and I've never Coded, so, I'm struggling a little!

    Battle::AbilityEffects::AfterMoveUseFromTarget.add(:HUNGRYFORNOODLES,
    proc { |ability, target, battler, user, status|
    next if status != :POISON
    newform = 1
    if battler.form != newform
    battler.battle.pbShowAbilitySplash(battler)
    battler.pbChangeForm(newForm, _INTL("{1} transformed!", battler.pbThis))
    battler.battle.pbHideAbilitySplash(battler)
    end
    }
    )

    I'm experimenting with it, but when my Pokemon is poisoned, it's not changing their form at all - Everything is just staying the same, unfortunately!

    Also, would it be possible to cure the poison when entering the overworld (Ending a battle, but not during a battle?)

    I'm so sorry to ask a lot!

    My original code was based on Colour change, but, instead of Changing type when hit by a move, it would change form, but then changed that from hit by a move to being poisoned, if you were wondering how I got my original jank code!
     
    Back
    Top