• 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] Check only type 1 or 2

46
Posts
7
Years
  • I'm trying to make the rival have the same type as you and I can't seem to find a method to make it where the script only checks type-1. I want to prevent the condition branching looking up type-2 with HasType?. Is there a way of doing this?
     

    WolfPP

    Spriter/ Pixel Artist
    1,309
    Posts
    5
    Years
  • Since the def for it is this one:
    Code:
      def pbHasType?(type)
        if type.is_a?(Symbol) || type.is_a?(String)
          type = getConst(PBTypes,type)
        end
        return false if type==nil || type<0
        ret = (self.type1==type || self.type2==type)
        ret |= (@effects[PBEffects::Type3]==type) if @effects[PBEffects::Type3]>=0
        return ret
      end

    We have other code to get the primary type:
    Code:
      def pbHasPrimaryType?(type)
        ret=false
        if type.is_a?(Symbol) || type.is_a?(String)
          ret=isConst?(self.type1,PBTypes,type.to_sym)
          if @effects[PBEffects::Type3]>=0
            ret=isConst?(@effects[PBEffects::Type3],PBTypes,type.to_sym)
          end
        end
        return ret
      end
     
    46
    Posts
    7
    Years
  • Since the def for it is this one:
    Code:
      def pbHasType?(type)
        if type.is_a?(Symbol) || type.is_a?(String)
          type = getConst(PBTypes,type)
        end
        return false if type==nil || type<0
        ret = (self.type1==type || self.type2==type)
        ret |= (@effects[PBEffects::Type3]==type) if @effects[PBEffects::Type3]>=0
        return ret
      end

    We have other code to get the primary type:
    Code:
      def pbHasPrimaryType?(type)
        ret=false
        if type.is_a?(Symbol) || type.is_a?(String)
          ret=isConst?(self.type1,PBTypes,type.to_sym)
          if @effects[PBEffects::Type3]>=0
            ret=isConst?(@effects[PBEffects::Type3],PBTypes,type.to_sym)
          end
        end
        return ret
      end

    Can't seem to get it working. I think you also need to have pbHasPrimaryType? in PSystem_PokemonUtilities as well. I've been trying a few things and still haven't gotten it to work
     
    286
    Posts
    5
    Years
    • Seen May 15, 2024
    I think you need something from Pokebattle_Pokemon. the "pb" methods are for in battle only I believe. Check out these methods in Pokebattle_Pokemon:
    Code:
    ################################################################################
    # Types
    ################################################################################
    # Returns whether this Pokémon has the specified type.
      def hasType?(type)
        if type.is_a?(String) || type.is_a?(Symbol)
          return isConst?(self.type1,PBTypes,type) || isConst?(self.type2,PBTypes,type)
        else
          return self.type1==type || self.type2==type
        end
      end
    
    # Returns this Pokémon's first type.
      def type1
        dexdata=pbOpenDexData
        pbDexDataOffset(dexdata,self.fSpecies,8)
        ret=dexdata.fgetb
        dexdata.close
        return ret
      end
    
    # Returns this Pokémon's second type.
      def type2
        dexdata=pbOpenDexData
        pbDexDataOffset(dexdata,self.fSpecies,9)
        ret=dexdata.fgetb
        dexdata.close
        return ret
      end
     
    233
    Posts
    5
    Years
    • Seen Oct 9, 2023
    We have other code to get the primary type:
    Code:
      def pbHasPrimaryType?(type)
        ret=false
        if type.is_a?(Symbol) || type.is_a?(String)
          ret=isConst?(self.type1,PBTypes,type.to_sym)
          if @effects[PBEffects::Type3]>=0
            ret=isConst?(@effects[PBEffects::Type3],PBTypes,type.to_sym)
          end
        end
        return ret
      end

    You don't need to check Type3, especially if you're not checking during a battle (it's undefined out of battle!).

    Can you please give more context as to what you're trying to do exactly? I'm going to assume you want only the rival's starter Pokemon to have the same type as the player's starter Pokemon for all battles in the game, but if that's wrong please correct me. If it is that, then you need to store "type1" into some global variable at the start of the game, and then change the "type1" variable of the rival's starter every time it switches into battle. You can set aside some variable to store type1 in a Script command like so:
    Code:
    pbSet(VAR_ID, $Trainer.party[0].type1)
    where VAR_ID is whatever ID you want (and this should be run after giving the player their starter). Then you could add this section to the end of the function "pbAbilitiesOnSwitchIn":
    Code:
    if onactive && @battle.pbIsOpposing?(self.index) && self.species==PBSpecies::STARTERSPECIES
      if opponent.is_a?(Array) # Double battle
        if self.index == 1 && opponent[0].trainertype == PBTrainers::RIVALNAME
          self.type1 = pbGet(VAR_ID)
        elsif self.index == 3 && opponent[1].trainertype == PBTrainers::RIVALNAME
          self.type1 = pbGet(VAR_ID)
        end
      elsif opponent.is_a?(PokeBattle_Trainer) && opponent.trainertype == PBTrainers::RIVALNAME # Single battle
        self.type1 = pbGet(VAR_ID)
      end
    end
    where STARTERSPECIES is the species of your rival's starter and RIVALNAME is the internal name of your rival trainer.
     
    46
    Posts
    7
    Years
  • Basically I'm trying to get a condition branch to look at the type1 of the player's party so that way it can set a variable to a different number that will then determine which team the rival will have.
     
    233
    Posts
    5
    Years
    • Seen Oct 9, 2023
    Well, you can just loop through each Pokemon in the player's party and see if any of their type1's match the type you're checking:
    Code:
    def pbHasType1?(type)
      for i in $Trainer.party
        return true if i.type1 == type
      end
      return false
    end
     
    46
    Posts
    7
    Years
  • Well, you can just loop through each Pokemon in the player's party and see if any of their type1's match the type you're checking:
    Code:
    def pbHasType1?(type)
      for i in $Trainer.party
        return true if i.type1 == type
      end
      return false
    end

    I've tried using this however the value isn't changing for the variable
     
    46
    Posts
    7
    Years
  • I've been able to get it to work. I used added more to NettoHikari's code and also made a variant for type 2.
    Code:
    # Returns true if there is a Pokémon with the type1 in the player's party.
    def pbHasType1?(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        type = getID(PBTypes,type)
      end
      for i in $Trainer.party
        return true if i.type1 == type
      end
      return false
    end
    
    
    # Returns true if there is a Pokémon with the type2 in the player's party.
    def pbHasType2?(type)
      if type.is_a?(String) || type.is_a?(Symbol)
        type = getID(PBTypes,type)
      end
      for i in $Trainer.party
        return true if i.type2 == type
      end
      return false
    end

    Thanks for everyone's help. It's been much appreciated.
     
    Back
    Top