Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #===============================================================================
  2. # Technical Records - By Vendily [v17]
  3. #===============================================================================
  4. # This script adds in Technical Records, the replacement to consumable TMs
  5. #  that also have the ability to allow a mon to relearn the move at a
  6. #  Move Relearner if they forget it.
  7. # Also adds in the system for Technical Records using the icon of the move type
  8. #  much like TMs.
  9. #===============================================================================
  10. # To use it, you must create a new item much like you would a TM or HM, but give
  11. #  it Item Usage 6 (if 6 is already used by some other script, you must edit
  12. #  pbIsTechnicalRecord? to use a different number)
  13. #
  14. # To use the type based icons, name the icon "itemRecordX", where X is either
  15. #  the internal name of the type, or the 3 digit padded type number.
  16. #  AKA. Either NORMAL or 000 will work for X
  17. #
  18. # You really should set INFINITETMS to true to get the most out of this script
  19. #  but it's not a requirement at all.
  20. #===============================================================================
  21.  
  22. def pbIsMachine?(item)
  23.   return pbIsTechnicalMachine?(item) || pbIsHiddenMachine?(item) || pbIsTechnicalRecord?(item)
  24. end
  25.  
  26. def pbIsTechnicalRecord?(item)
  27.   return $ItemData[item] && ($ItemData[item][ITEMUSE]==6)
  28. end
  29.  
  30. #===============================================================================
  31. # Use an item from the Bag and/or on a Pokémon
  32. #===============================================================================
  33. def pbUseItem(bag,item,bagscene=nil)
  34.   found=false
  35.   if pbIsMachine?(item)    # TM or HM or TR
  36.     if $Trainer.pokemonCount==0
  37.       Kernel.pbMessage(_INTL("There is no Pokémon."))
  38.       return 0
  39.     end
  40.     machine=pbGetMachine(item)
  41.     return 0 if machine==nil
  42.     movename=PBMoves.getName(machine)
  43.     Kernel.pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",PBItems.getName(item)))
  44.     if !Kernel.pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",movename))
  45.       return 0
  46.     elsif mon=pbMoveTutorChoose(machine,nil,true)
  47.       bag.pbDeleteItem(item) if pbIsTechnicalMachine?(item) && !INFINITETMS
  48.       if pbIsTechnicalRecord?(item)
  49.         bag.pbDeleteItem(item)
  50.         $Trainer.party[mon].trmoves.push(machine)
  51.       end
  52.       return 1
  53.     else
  54.       return 0
  55.     end
  56.   elsif $ItemData[item][ITEMUSE]==1 || $ItemData[item][ITEMUSE]==5 # Item is usable on a Pokémon
  57.     if $Trainer.pokemonCount==0
  58.       Kernel.pbMessage(_INTL("There is no Pokémon."))
  59.       return 0
  60.     end
  61.     ret=false
  62.     annot=nil
  63.     if pbIsEvolutionStone?(item)
  64.       annot=[]
  65.       for pkmn in $Trainer.party
  66.         elig=(pbCheckEvolution(pkmn,item)>0)
  67.         annot.push(elig ? _INTL("ABLE") : _INTL("NOT ABLE"))
  68.       end
  69.     end
  70.     pbFadeOutIn(99999){
  71.       scene = PokemonParty_Scene.new
  72.       screen = PokemonPartyScreen.new(scene,$Trainer.party)
  73.       screen.pbStartScene(_INTL("Use on which Pokémon?"),false,annot)
  74.       loop do
  75.         scene.pbSetHelpText(_INTL("Use on which Pokémon?"))
  76.         chosen=screen.pbChoosePokemon
  77.         if chosen>=0
  78.           pokemon=$Trainer.party[chosen]
  79.           if pbCheckUseOnPokemon(item,pokemon,screen)
  80.             ret=ItemHandlers.triggerUseOnPokemon(item,pokemon,screen)
  81.             if ret && $ItemData[item][ITEMUSE]==1 # Usable on Pokémon, consumed
  82.               bag.pbDeleteItem(item)
  83.             end
  84.             if !bag.pbHasItem?(item)
  85.               Kernel.pbMessage(_INTL("You used your last {1}.",PBItems.getName(item)))
  86.               break
  87.             end
  88.           end
  89.         else
  90.           ret=false
  91.           break
  92.         end
  93.       end
  94.       screen.pbEndScene
  95.       bagscene.pbRefresh if bagscene
  96.     }
  97.     return ret ? 1 : 0
  98.   elsif $ItemData[item][ITEMUSE]==2 # Item is usable from bag
  99.     intret=ItemHandlers.triggerUseFromBag(item)
  100.     case intret
  101.     when 0; return 0
  102.     when 1; return 1 # Item used
  103.     when 2; return 2 # Item used, end screen
  104.     when 3; bag.pbDeleteItem(item); return 1 # Item used, consume item
  105.     when 4; bag.pbDeleteItem(item); return 2 # Item used, end screen and consume item
  106.     else; Kernel.pbMessage(_INTL("Can't use that here.")); return 0
  107.     end
  108.   else
  109.     Kernel.pbMessage(_INTL("Can't use that here."))
  110.     return 0
  111.   end
  112. end
  113.  
  114. # Only called when in the party screen and having chosen an item to be used on
  115. # the selected Pokémon
  116. def pbUseItemOnPokemon(item,pokemon,scene)
  117.   if pbIsMachine?(item)    # TM or HM or TR
  118.     machine=pbGetMachine(item)
  119.     return false if machine==nil
  120.     movename=PBMoves.getName(machine)
  121.     if (pokemon.isShadow? rescue false)
  122.       Kernel.pbMessage(_INTL("Shadow Pokémon can't be taught any moves."))
  123.     elsif !pokemon.isCompatibleWithMove?(machine)
  124.       Kernel.pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename))
  125.     else
  126.       Kernel.pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",PBItems.getName(item)))
  127.       if Kernel.pbConfirmMessage(_INTL("Do you want to teach {1} to {2}?",movename,pokemon.name))
  128.         if pbLearnMove(pokemon,machine,false,true)
  129.           $PokemonBag.pbDeleteItem(item) if pbIsTechnicalMachine?(item) && !INFINITETMS
  130.           if pbIsTechnicalRecord?(item)
  131.             $PokemonBag.pbDeleteItem(item)
  132.             pokemon.trmoves.push(machine)
  133.           end
  134.           return true
  135.         end
  136.       end
  137.     end
  138.     return false
  139.   else
  140.     ret=ItemHandlers.triggerUseOnPokemon(item,pokemon,scene)
  141.     scene.pbClearAnnotations
  142.     scene.pbHardRefresh
  143.     if ret && $ItemData[item][ITEMUSE]==1 # Usable on Pokémon, consumed
  144.       $PokemonBag.pbDeleteItem(item)
  145.     end
  146.     if !$PokemonBag.pbHasItem?(item)
  147.       Kernel.pbMessage(_INTL("You used your last {1}.",PBItems.getName(item)))
  148.     end
  149.     return ret
  150.   end
  151.   Kernel.pbMessage(_INTL("Can't use that on {1}.",pokemon.name))
  152.   return false
  153. end
  154.  
  155. def pbMoveTutorChoose(move,movelist=nil,bymachine=false)
  156.   ret = false
  157.   if move.is_a?(String) || move.is_a?(Symbol)
  158.     move = getID(PBMoves,move)
  159.   end
  160.   if movelist!=nil && movelist.is_a?(Array)
  161.     for i in 0...movelist.length
  162.       if movelist[i].is_a?(String) || movelist[i].is_a?(Symbol)
  163.         movelist[i] = getID(PBSpecies,movelist[i])
  164.       end
  165.     end
  166.   end
  167.   pbFadeOutIn(99999){
  168.     movename = PBMoves.getName(move)
  169.     annot = pbMoveTutorAnnotations(move,movelist)
  170.     scene = PokemonParty_Scene.new
  171.     screen = PokemonPartyScreen.new(scene,$Trainer.party)
  172.     screen.pbStartScene(_INTL("Teach which Pokémon?"),false,annot)
  173.     loop do
  174.       chosen = screen.pbChoosePokemon
  175.       if chosen>=0
  176.         pokemon = $Trainer.party[chosen]
  177.         if pokemon.egg?
  178.           Kernel.pbMessage(_INTL("Eggs can't be taught any moves."))
  179.         elsif (pokemon.isShadow? rescue false)
  180.           Kernel.pbMessage(_INTL("Shadow Pokémon can't be taught any moves."))
  181.         elsif movelist && !movelist.any?{|j| j==pokemon.species }
  182.           Kernel.pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename))
  183.         elsif !pokemon.isCompatibleWithMove?(move)
  184.           Kernel.pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename))
  185.         else
  186.           if pbLearnMove(pokemon,move,false,bymachine)
  187.             ret = chosen
  188.             break
  189.           end
  190.         end
  191.       else
  192.         break
  193.       end  
  194.     end
  195.     screen.pbEndScene
  196.   }
  197.   return ret # Returns whether the move was learned by a Pokemon
  198. end
  199.  
  200. #===============================================================================
  201. # Load item icons
  202. #===============================================================================
  203. def pbItemIconFile(item)
  204.   return nil if !item
  205.   bitmapFileName = nil
  206.   if item==0
  207.     bitmapFileName = sprintf("Graphics/Icons/itemBack")
  208.   else
  209.     bitmapFileName = sprintf("Graphics/Icons/item%s",getConstantName(PBItems,item)) rescue nil
  210.     if !pbResolveBitmap(bitmapFileName)
  211.       bitmapFileName = sprintf("Graphics/Icons/item%03d",item)
  212.       if !pbResolveBitmap(bitmapFileName) && pbIsTechnicalRecord?(item)
  213.         move = pbGetMachine(item)
  214.         type = PBMoveData.new(move).type
  215.         bitmapFileName = sprintf("Graphics/Icons/itemRecord%s",getConstantName(PBTypes,type)) rescue nil
  216.         if !pbResolveBitmap(bitmapFileName)
  217.           bitmapFileName = sprintf("Graphics/Icons/itemRecord%03d",type)
  218.         end
  219.       end
  220.       if !pbResolveBitmap(bitmapFileName) && pbIsMachine?(item)
  221.         move = pbGetMachine(item)
  222.         type = PBMoveData.new(move).type
  223.         bitmapFileName = sprintf("Graphics/Icons/itemMachine%s",getConstantName(PBTypes,type)) rescue nil
  224.         if !pbResolveBitmap(bitmapFileName)
  225.           bitmapFileName = sprintf("Graphics/Icons/itemMachine%03d",type)
  226.         end
  227.       end
  228.     end
  229.   end
  230.   return bitmapFileName
  231. end
  232.  
  233. class PokeBattle_Pokemon
  234.   attr_accessor :trmoves
  235.  
  236.   def trmoves
  237.     @trmoves=[] if !@trmoves
  238.     return @trmoves
  239.   end
  240. end
  241.  
  242. alias tr_pbGetRelearnableMoves pbGetRelearnableMoves
  243. def pbGetRelearnableMoves(pokemon)
  244.   ret=tr_pbGetRelearnableMoves(pokemon)
  245.   trmoves=[]
  246.   for i in pokemon.trmoves
  247.     trmoves.push(i) if !pokemon.hasMove?(i) && !ret.include?(i)
  248.   end
  249.   ret=ret+trmoves
  250.   return ret|[]
  251. end