• 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 Ability/Script Question

15
Posts
7
Years
    • Seen May 6, 2021
    i was wondering if i formatted these right? Corrupt Heart is like Bad Dreams but affects all statuses and Snowbank increases Def and SpDef if hit with Water or Ice Moves. sorry imma noob at scripting i not really sure how to format scripts with multiple "variables" for lack of a better word. XD

    # Corrupt Heart
    if i.status==PBStatuses::SLEEP || BURN || POISON || FROZEN || PARALYSIS && !i.hasWorkingAbility(:MAGICGUARD)
    if i.pbOpposing1.hasWorkingAbility(:CORRUPTHEART) ||
    i.pbOpposing2.hasWorkingAbility(:CORRUPTHEART)
    PBDebug.log("[Ability triggered] #{i.pbThis}'s opponent's Corrupt Heart")
    hploss=i.pbReduceHP((i.totalhp/8).floor,true)
    pbDisplay(_INTL("{1} is being affected!",i.pbThis)) if hploss>0
    end
    end
    if i.isFainted?
    return if !i.pbFaint
    next
    end



    if opponent.hasWorkingAbility(:SNOWBANK) && isConst?(type,PBTypes,:WATER) || (type,PBTypes,:ICE)
    PBDebug.log("[Ability triggered] #{opponent.pbThis}'s Snow Bank (made #{@name} ineffective)")
    if opponent.pbCanIncreaseStatStage?(PBStats::DEFENSE,opponent) &&
    opponent.pbIncreaseStatWithCause(PBStats::DEFENSE,1,opponent,PBAbilities.getName(opponent.ability))
    opponent.pbCanIncreaseStatStage?(PBStats::SPDEF,opponent)
    opponent.pbIncreaseStatWithCause(PBStats::SPDEF,1,opponent,PBAbilities.getName(opponent.ability))
    else
    @battle.pbDisplay(_INTL("{1}'s {2} made {3} ineffective!",
    opponent.pbThis,PBAbilities.getName(opponent.ability),self.name))
    end
    return true
    end
     
    971
    Posts
    7
    Years
    • Age 21
    • Seen Nov 28, 2022
    Code:
          # Corrupt Heart
          if i.status==PBStatuses::SLEEP || BURN || POISON || FROZEN || PARALYSIS  && !i.hasWorkingAbility(:MAGICGUARD)
            if i.pbOpposing1.hasWorkingAbility(:CORRUPTHEART) ||
               i.pbOpposing2.hasWorkingAbility(:CORRUPTHEART)
              PBDebug.log("[Ability triggered] #{i.pbThis}'s opponent's Corrupt Heart")
              hploss=i.pbReduceHP((i.totalhp/8).floor,true)
              pbDisplay(_INTL("{1} is being affected!",i.pbThis)) if hploss>0
            end
          end
          if i.isFainted?
            return if !i.pbFaint
            next
          end
    
    
    
        if opponent.hasWorkingAbility(:SNOWBANK) && isConst?(type,PBTypes,:WATER) || (type,PBTypes,:ICE)
          PBDebug.log("[Ability triggered] #{opponent.pbThis}'s Snow Bank (made #{@name} ineffective)")
          if opponent.pbCanIncreaseStatStage?(PBStats::DEFENSE,opponent) &&
            opponent.pbIncreaseStatWithCause(PBStats::DEFENSE,1,opponent,PBAbilities.getName(opponent.ability))
             opponent.pbCanIncreaseStatStage?(PBStats::SPDEF,opponent)
            opponent.pbIncreaseStatWithCause(PBStats::SPDEF,1,opponent,PBAbilities.getName(opponent.ability))
          else
            @battle.pbDisplay(_INTL("{1}'s {2} made {3} ineffective!",
               opponent.pbThis,PBAbilities.getName(opponent.ability),self.name))
          end
          return true
        end

    First thing I'd like to teach you is that you should wrap code around with [ CODE ] (and then another one with [ /CODE ] at the end, both without spaces). It keeps the indentation and makes it much easier to read.

    Then on to your code, the first line "if i.status......" isn't right. When you have multiple statements, you need to repeat the actual "question". Here's what it'd look like (Notice how I'm not using [ CODE ] here because there is no indentation to be kept):

    if i.status==PBStatuses::SLEEP || i.status==PBStatuses::BURN || i.status==PBStatuses::POISON && !i.hasWorkingAbility(:MAGICGUARD)

    If "i" is sleeping, burned or poisoned in this statement, it will check to see if there's "&&", and if there is, make sure that returns true as well. By putting an "!" before a method (hasWorkingAbility, yes or no; true or false) it reverses the return value. If it would return true, the ! would make it false and thus the statement is not met. if it doesn't have it, false, it will become true.
    The rest of Corrupt Heart seems to be okay.

    for Snow Bank's if statements goes the same: (type,PBTypes,:ICE) on its own means nothing. They're arguments that need to be passed into a function, "isConst?". Note that boolean statements don't need to have arguments or "==". for example, if I made a variable "light" and gave it the "true" keyword, you can say "if light", if light is set to true it will continue the code, and "if !light" will continue the code if light is false.
    For multiple stat changes, you want to check if the stat can be lowered for every different stat. I think this should work:
    Code:
    if opponent.hasWorkingAbility(:SNOWBANK) && isConst?(type,PBTypes,:WATER) || isConst?(type,PBTypes,:ICE)
      PBDebug.log("[Ability triggered] #{opponent.pbThis}'s Snow Bank (made #{@name} ineffective)")
      if opponent.pbCanIncreaseStatStage?(PBStats::DEFENSE,opponent)
        opponent.pbIncreaseStatStageWithCause(PBStats::DEFENSE,1,opponent,PBAbilities.getName(opponent.ability))
        if opponent.pbCanIncreaseStatStage?(PBStats::SPDEF,opponent)
          opponent.pbIncreaseStatStageWithCause(PBStats::SPDEF,1,opponent,PBAbilities.getName(opponent.ability))
        end
      else
        @battle.pbDisplay(_INTL("{1}'s {2} made {3} ineffective!",
               opponent.pbThis,PBAbilities.getName(opponent.ability),self.name))
      end
      return true
    end
    I can't promise this works, I wrote it by hand without any reference other than your work :)
     
    Back
    Top