• 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.
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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!
  • 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] Streamlining TMs

  • 132
    Posts
    10
    Years
    How can I adjust this script so that the pokemon is able to learn the TM based on whether they can learn it through ANY means, be it by learning, move tutor, or the tm PBS file?

    Code:
    def pbSpeciesCompatible?(species,move)
      ret=false
      return false if species<=0
      data=load_data("Data/tm.dat")
      return false if !data[move]
      return data[move].any? {|item| item==species }
    end

    Compatibility is only determined by whether the TM is defined in tm.txt, and I'd like it to reference more than that. Any help is appreciated, thanks!
     
    Well, move tutor just looks at the TM list as well, unless you pass an optional list of Pokemon symbols to learn moves they otherwise couldn't.
    Since we only get a species as an argument, we'd need to do basically the same loop that's done in def getMoveList on the Pokemon object.
    Code:
    def pbSpeciesCompatible?(species,move)
      ret=false
      return false if species<=0
      data=load_data("Data/tm.dat")
      return true if data[move] && data[move].any? {|item| item==species }
      movelist=[]
      atkdata=pbRgssOpen("Data/attacksRS.dat","rb")
      offset=atkdata.getOffset(species-1)
      length=atkdata.getLength(species-1)>>1
      atkdata.pos=offset
      for k in 0..length-1
        level=atkdata.fgetw # just so the offset gets moved up.
        move=atkdata.fgetw
        movelist.push(move)
      end
      atkdata.close
      return movelist.include?(move)
    end

    I didn't test it though.
     
    Well, move tutor just looks at the TM list as well, unless you pass an optional list of Pokemon symbols to learn moves they otherwise couldn't.
    Since we only get a species as an argument, we'd need to do basically the same loop that's done in def getMoveList on the Pokemon object.
    Code:
    def pbSpeciesCompatible?(species,move)
      ret=false
      return false if species<=0
      data=load_data("Data/tm.dat")
      return true if data[move] && data[move].any? {|item| item==species }
      movelist=[]
      atkdata=pbRgssOpen("Data/attacksRS.dat","rb")
      offset=atkdata.getOffset(species-1)
      length=atkdata.getLength(species-1)>>1
      atkdata.pos=offset
      for k in 0..length-1
        level=atkdata.fgetw # just so the offset gets moved up.
        move=atkdata.fgetw
        movelist.push(move)
      end
      atkdata.close
      return movelist.include?(move)
    end

    I didn't test it though.

    Seems to work perfectly, thanks!

    Edit: never mind, when I try to teach a pokemon one of the TMs, every possible pokemon is able to learn it, even though that's not true. Any thoughts?
     
    Last edited:
    That's happening because the "move" parameter is getting re-assigned in the loop going through the species' move list, so the original parameter gets lost and is replaced with the last move in the move list by the end of the loop. You'll need to use a different variable name inside the loop, like so (change made in red):

    Code:
    def pbSpeciesCompatible?(species,move)
      ret=false
      return false if species<=0
      data=load_data("Data/tm.dat")
      return true if data[move] && data[move].any? {|item| item==species }
      movelist=[]
      atkdata=pbRgssOpen("Data/attacksRS.dat","rb")
      offset=atkdata.getOffset(species-1)
      length=atkdata.getLength(species-1)>>1
      atkdata.pos=offset
      for k in 0..length-1
        level=atkdata.fgetw # just so the offset gets moved up.
        [color=red]tempmove=atkdata.fgetw
        movelist.push(tempmove)[/color]
      end
      atkdata.close
      return movelist.include?(move)
    end
     
    Last edited:
    Back
    Top