• 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] Streamlining TMs

132
Posts
9
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!
     
    1,682
    Posts
    8
    Years
    • Seen today
    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.
     
    132
    Posts
    9
    Years
  • 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:
    233
    Posts
    5
    Years
    • Seen Oct 9, 2023
    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