• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Scottie, Todd, Serena, Kris - 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] Custom ability mechanic not working

  • 217
    Posts
    15
    Years
    • Seen Nov 29, 2021
    So I wanted a very simple solution to Pokemon having two abilities, which was to have a new field and patch it into hasWorkingAbility. However it doesn't seem to be working. (To test, I assigned Charmander the "Primary" DROUGHT, then went into battle.)

    Here's my code:

    From the Compiler:
    Code:
         "Primary"=>[74,"E",PBAbilities],

    From PokeBattle_Battler:
    Code:
      attr_accessor :primary
    Code:
    def pbInitPokemon(pkmn,pkmnIndex)
    ...
        @primary      = pkmn.primary
    Code:
    def pbInitBlank
    ...
        @primary      = 0
    Code:
      def hasWorkingAbility(ability,ignorefainted=false)
        return false if self.isFainted? && !ignorefainted
        return false if @effects[PBEffects::GastroAcid]
        return true if isConst?(@ability,PBAbilities,ability)
        return true if isConst?(@primary,PBAbilities,ability)
      end

    From PokeBattle_Pokemon (this bit I have no idea what I'm doing so it may be the cause):
    Code:
    ################################################################################
    # Primary Ability
    ################################################################################
    # Returns the ID of this Pokemon's ability.
      def primary
        prim=abilityIndex
        prims=getAbilityList
        ret1=0; ret2=0
        for i in 0...prims.length
          next if !prims[i][0] || prims[i][0]<=0
          return prims[i][0] if prims[i][1]==prim
          ret1=prims[i][0] if prims[i][1]==0
          ret2=prims[i][0] if prims[i][1]==1
        end
        prim=(@personalID&1) if prim>=2
        return ret2 if prim==1 && ret2>0
        return ret1
      end
    
    # Returns whether this Pokémon has a particular ability.
      def hasPrimary?(value=0)
        if value==0
          return self.primary>0
        else
          if value.is_a?(String) || value.is_a?(Symbol)
            value=getID(PBAbilities,value)
          end
          return self.primary==value
        end
        return false
      end
    
    # Returns the list of abilities this Pokémon can have.
      def getPrimaryList
        prims=[]; ret=[]
        dexdata=pbOpenDexData
        pbDexDataOffset(dexdata,@species,2)
        prims.push(dexdata.fgetw)
        prims.push(dexdata.fgetw)
        pbDexDataOffset(dexdata,@species,40)
        prims.push(dexdata.fgetw)
        prims.push(dexdata.fgetw)
        prims.push(dexdata.fgetw)
        prims.push(dexdata.fgetw)
        dexdata.close
        for i in 0...prims.length
          next if !prims[i] || prims[i]<=0
          ret.push([prims[i],i])
        end
        return ret
      end
     
    Back
    Top