• 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] Adding move relearner to party screen

3
Posts
15
Years
    • Seen Apr 27, 2019
    Hello,

    I've been playing with the move relearner a bit lately. I successfully turned it into a key item, no heartscale needed.
    But now, I though it would be even better to add a "Relearn moves" option when you select a Pokemon on the party screen. I got the idea from the debug menu which allows players to teach a pokemon any move, much faster than through the "move relearner" screen.

    I somehow made it to add a "Relearn" option when selecting a Pokemon in party screen. And I "created" the script, VASTLY inspired from bits of the "PScreen_MoveRelearner" and "Editor_Utilities" scripts : I rename and use the commands "pbHasRelearnableMove?(pokemon)" and "pbChooseMoveListForSpecies(pokemon,defaultMoveID=0)" ...

    After some fiddling, it doesn't crash but ... It gives me the list of ALL moves, instead of just the moves the selected Pokemon can learn. And I tried, it lets me teach my Pokemon moves it shouldn't be able to learn.
    Note that all my Pokemon only have level up moves, but no eggmove or TM/HM move.

    Here is what the code looks like :
    Code:
    def pbLabEachNaturalMove(pokemon)
      movelist=pokemon.getMoveList
      for i in movelist
        yield i[1],i[0]
      end
    end
    
    def pbLabHasRelearnableMove?(pokemon)
      return pbLabGetRelearnableMoves(pokemon).length>0
    end
    
    def pbLabGetRelearnableMoves(pokemon)
      return [] if !pokemon || # pokemon.egg? || (pokemon.isShadow? rescue false)
      moves=[]
      pbLabEachNaturalMove(pokemon){|move,level|
        if level<=pokemon.level && !pokemon.hasMove?(move)
          moves.push(move) if !moves.include?(move)
        end
      }
      tmoves=[]
      if pokemon.firstmoves
        for i in pokemon.firstmoves
          tmoves.push(i) if !pokemon.hasMove?(i) && !moves.include?(i)
        end
      end
      moves=tmoves+moves
      return moves|[] # remove duplicates
    end
    
    
    
    def pbLabChooseMoveListForSpecies(pokemon,defaultMoveID=0)
      cmdwin = pbListWindow([],200)
      commands = []
      moveDefault = 0
      legalMoves = pbLabGetRelearnableMoves(pokemon)
      for move in legalMoves
        commands.push([move,PBMoves.getName(move)])
      end
      commands.sort! {|a,b| a[1]<=>b[1] }
      if defaultMoveID>0
        commands.each_with_index{|item,index|
          if moveDefault==0
            moveDefault = index if index[0]==defaultMoveID
          end
        }
      end
      commands2 = []
      for i in 1..PBMoves.maxValue
        if PBMoves.getName(i)!=nil && PBMoves.getName(i)!=""
          commands2.push([i,PBMoves.getName(i)])
        end
      end
      commands2.sort!{|a,b| a[1]<=>b[1] }
      if defaultMoveID>0
        commands2.each_with_index{|item,index|
          if moveDefault==0
            moveDefault = index if index[0]==defaultMoveID
          end
        }
      end
      commands.concat(commands2)
      realcommands = []
      for command in commands
        realcommands.push("#{command[1]}")
      end
      ret = pbCommands2(cmdwin,realcommands,-1,moveDefault,true) 
      cmdwin.dispose
      return (ret>=0) ? commands[ret][0] : 0
    end

    And the part in "PScreen_Party" calling this code (taken from the "Debug_Pokemon" script, "teachmove" part) :
    Code:
    elsif cmdRelearn>=0 && command==cmdRelearn
            move = pbLabChooseMoveListForSpecies(pkmn.species)
            if move!=0
              pbLearnMove(pkmn,move)
              pbRefreshSingle(pkmnid)
            end

    Does anyone knows why it gives me the full list of moves instead of just the moves the Pokemon can actually learn?

    Thanks in advance! And don't hesitate to ask if you need more details.
     
    3
    Posts
    15
    Years
    • Seen Apr 27, 2019
    The problem is solved, thanks to MGriffin at RelicCastle!

    I'm posting the solution here, if that can be of any help to someone.

    Here is the code :
    Code:
    def pbLabChooseMoveListForSpecies(pokemon,defaultMoveID=0)
      cmdwin = pbListWindow([],200)
      commands = []
      moveDefault = 0
      legalMoves = pbGetRelearnableMoves(pokemon)
      for move in legalMoves
    	commands.push([move,PBMoves.getName(move)])
      end
      commands.sort! {|a,b| a[1]<=>b[1] }
      if defaultMoveID>0
    	commands.each_with_index{|item,index|
    	  if moveDefault==0
    		moveDefault = index if index[0]==defaultMoveID
    	  end
    	}
      end
      realcommands = []
      for command in commands
    	realcommands.push("#{command[1]}")
      end
      ret = pbCommands2(cmdwin,realcommands,-1,moveDefault,true) 
      cmdwin.dispose
      return (ret>=0) ? commands[ret][0] : 0
    end

    And you call it like this :

    Code:
    move = pbLabChooseMoveListForSpecies(pkmn)
            if move!=0
              pbLearnMove(pkmn,move)
              pbRefreshSingle(pkmnid)
            end

    It call functions from the vanilla Move Relearner script, so it needs to be untouched!
     
    12
    Posts
    3
    Years
    • Seen Oct 2, 2023
    Hi there, sorry for necroposting but I would like to know how to implement this. I placed in the scripts but I don't know how to overall get it to work. I managed to get the option to appear but I don't know how to call the script I put the code in.
     
    Last edited:
    Back
    Top