Advertisement
Vendily

Technical Records v18

Sep 3rd, 2020
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.16 KB | None | 0 0
  1. #===============================================================================
  2. # Technical Records - By Vendily [v18]
  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? and pbIsMachine? 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 001 will work for X
  17. #
  18. # You really should set INFINITE_TMS to true to get the most out of this script
  19. #  but it's not a requirement at all.
  20. #===============================================================================
  21. begin
  22. PluginManager.register({
  23.   :name    => "Technical Records",
  24.   :version => "1.0",
  25.   :link    => "https://reliccastle.com/resources/443/",
  26.   :credits => "Vendily"
  27. })
  28. rescue
  29.   raise "This script only funtions in v18."
  30. end
  31.  
  32. def pbIsMachine?(item)
  33.   ret = pbGetItemData(item,ITEM_FIELD_USE)
  34.   return ret && (ret==3 || ret==4 || ret==6)
  35. end
  36.  
  37. def pbIsTechnicalRecord?(item)
  38.   ret = pbGetItemData(item,ITEM_FIELD_USE)
  39.   return ret && ret==6
  40. end
  41.  
  42. #===============================================================================
  43. # Use an item from the Bag and/or on a Pokémon
  44. #===============================================================================
  45. def pbUseItem(bag,item,bagscene=nil)
  46.   found = false
  47.   useType = pbGetItemData(item,ITEM_FIELD_USE)
  48.   if pbIsMachine?(item)    # TM or HM or TR
  49.     if $Trainer.pokemonCount==0
  50.       pbMessage(_INTL("There is no Pokémon."))
  51.       return 0
  52.     end
  53.     machine = pbGetMachine(item)
  54.     return 0 if machine==nil
  55.     movename = PBMoves.getName(machine)
  56.     pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",PBItems.getName(item)))
  57.     if !pbConfirmMessage(_INTL("Do you want to teach {1} to a Pokémon?",movename))
  58.       return 0
  59.     elsif mon=pbMoveTutorChoose(machine,nil,true)
  60.       bag.pbDeleteItem(item) if pbIsTechnicalMachine?(item) && !INFINITE_TMS
  61.       if pbIsTechnicalRecord?(item)
  62.         bag.pbDeleteItem(item)
  63.         $Trainer.party[mon].trmoves.push(machine)
  64.       end
  65.       return 1
  66.     end
  67.     return 0
  68.   elsif useType && (useType==1 || useType==5) # Item is usable on a Pokémon
  69.     if $Trainer.pokemonCount==0
  70.       pbMessage(_INTL("There is no Pokémon."))
  71.       return 0
  72.     end
  73.     ret = false
  74.     annot = nil
  75.     if pbIsEvolutionStone?(item)
  76.       annot = []
  77.       for pkmn in $Trainer.party
  78.         elig = pbCheckEvolution(pkmn,item)>0
  79.         annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
  80.       end
  81.     end
  82.     pbFadeOutIn {
  83.       scene = PokemonParty_Scene.new
  84.       screen = PokemonPartyScreen.new(scene,$Trainer.party)
  85.       screen.pbStartScene(_INTL("Use on which Pokémon?"),false,annot)
  86.       loop do
  87.         scene.pbSetHelpText(_INTL("Use on which Pokémon?"))
  88.         chosen = screen.pbChoosePokemon
  89.         if chosen<0
  90.           ret = false
  91.           break
  92.         end
  93.         pkmn = $Trainer.party[chosen]
  94.         if pbCheckUseOnPokemon(item,pkmn,screen)
  95.           ret = ItemHandlers.triggerUseOnPokemon(item,pkmn,screen)
  96.           if ret && useType==1   # Usable on Pokémon, consumed
  97.             bag.pbDeleteItem(item)
  98.             if !bag.pbHasItem?(item)
  99.               pbMessage(_INTL("You used your last {1}.",PBItems.getName(item)))
  100.               break
  101.             end
  102.           end
  103.         end
  104.       end
  105.       screen.pbEndScene
  106.       bagscene.pbRefresh if bagscene
  107.     }
  108.     return (ret) ? 1 : 0
  109.   elsif useType && useType==2   # Item is usable from bag
  110.     intret = ItemHandlers.triggerUseFromBag(item)
  111.     case intret
  112.     when 0; return 0
  113.     when 1; return 1   # Item used
  114.     when 2; return 2   # Item used, end screen
  115.     when 3; bag.pbDeleteItem(item); return 1   # Item used, consume item
  116.     when 4; bag.pbDeleteItem(item); return 2   # Item used, end screen and consume item
  117.     end
  118.     pbMessage(_INTL("Can't use that here."))
  119.     return 0
  120.   end
  121.   pbMessage(_INTL("Can't use that here."))
  122.   return 0
  123. end
  124.  
  125. # Only called when in the party screen and having chosen an item to be used on
  126. # the selected Pokémon
  127. def pbUseItemOnPokemon(item,pkmn,scene)
  128.   # TM or HM
  129.   if pbIsMachine?(item)
  130.     machine = pbGetMachine(item)
  131.     return false if machine==nil
  132.     movename = PBMoves.getName(machine)
  133.     if pkmn.shadowPokemon?
  134.       pbMessage(_INTL("Shadow Pokémon can't be taught any moves."))
  135.     elsif !pkmn.compatibleWithMove?(machine)
  136.       pbMessage(_INTL("{1} can't learn {2}.",pkmn.name,movename))
  137.     else
  138.       pbMessage(_INTL("\\se[PC access]You booted up {1}.\1",PBItems.getName(item)))
  139.       if pbConfirmMessage(_INTL("Do you want to teach {1} to {2}?",movename,pkmn.name))
  140.         if pbLearnMove(pkmn,machine,false,true)
  141.           $PokemonBag.pbDeleteItem(item) if pbIsTechnicalMachine?(item) && !INFINITE_TMS
  142.           if pbIsTechnicalRecord?(item)
  143.             $PokemonBag.pbDeleteItem(item)
  144.             pkmn.trmoves.push(machine)
  145.           end
  146.           return true
  147.         end
  148.       end
  149.     end
  150.     return false
  151.   end
  152.   # Other item
  153.   ret = ItemHandlers.triggerUseOnPokemon(item,pkmn,scene)
  154.   scene.pbClearAnnotations
  155.   scene.pbHardRefresh
  156.   useType = pbGetItemData(item,ITEM_FIELD_USE)
  157.   if ret && useType && useType==1   # Usable on Pokémon, consumed
  158.     $PokemonBag.pbDeleteItem(item)
  159.     if !$PokemonBag.pbHasItem?(item)
  160.       pbMessage(_INTL("You used your last {1}.",PBItems.getName(item)))
  161.     end
  162.   end
  163.   return ret
  164. end
  165.  
  166. def pbMoveTutorChoose(move,movelist=nil,bymachine=false)
  167.   ret = false
  168.   move = getID(PBMoves,move)
  169.   if movelist!=nil && movelist.is_a?(Array)
  170.     for i in 0...movelist.length
  171.       movelist[i] = getID(PBSpecies,movelist[i])
  172.     end
  173.   end
  174.   pbFadeOutIn {
  175.     movename = PBMoves.getName(move)
  176.     annot = pbMoveTutorAnnotations(move,movelist)
  177.     scene = PokemonParty_Scene.new
  178.     screen = PokemonPartyScreen.new(scene,$Trainer.party)
  179.     screen.pbStartScene(_INTL("Teach which Pokémon?"),false,annot)
  180.     loop do
  181.       chosen = screen.pbChoosePokemon
  182.       if chosen>=0
  183.         pokemon = $Trainer.party[chosen]
  184.         if pokemon.egg?
  185.           pbMessage(_INTL("Eggs can't be taught any moves."))
  186.         elsif pokemon.shadowPokemon?
  187.           pbMessage(_INTL("Shadow Pokémon can't be taught any moves."))
  188.         elsif movelist && !movelist.any? { |j| j==pokemon.species }
  189.           pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename))
  190.         elsif !pokemon.compatibleWithMove?(move)
  191.           pbMessage(_INTL("{1} can't learn {2}.",pokemon.name,movename))
  192.         else
  193.           if pbLearnMove(pokemon,move,false,bymachine)
  194.             ret = chosen
  195.             break
  196.           end
  197.         end
  198.       else
  199.         break
  200.       end  
  201.     end
  202.     screen.pbEndScene
  203.   }
  204.   return ret   # Returns whether the move was learned by a Pokemon
  205. end
  206.  
  207. #===============================================================================
  208. # Load item icons
  209. #===============================================================================
  210. def pbItemIconFile(item)
  211.   return nil if !item
  212.   bitmapFileName = nil
  213.   if item==0
  214.     bitmapFileName = sprintf("Graphics/Icons/itemBack")
  215.   else
  216.     bitmapFileName = sprintf("Graphics/Icons/item%s",getConstantName(PBItems,item)) rescue nil
  217.     if !pbResolveBitmap(bitmapFileName)
  218.       bitmapFileName = sprintf("Graphics/Icons/item%03d",item)
  219.       if !pbResolveBitmap(bitmapFileName) && pbIsTechnicalRecord?(item)
  220.         move = pbGetMachine(item)
  221.         type = pbGetMoveData(move,MOVE_TYPE)
  222.         bitmapFileName = sprintf("Graphics/Icons/itemRecord%s",getConstantName(PBTypes,type)) rescue nil
  223.         if !pbResolveBitmap(bitmapFileName)
  224.           bitmapFileName = sprintf("Graphics/Icons/itemRecord%03d",type)
  225.         end
  226.       end
  227.       if !pbResolveBitmap(bitmapFileName) && pbIsMachine?(item)
  228.         move = pbGetMachine(item)
  229.         type = pbGetMoveData(move,MOVE_TYPE)
  230.         bitmapFileName = sprintf("Graphics/Icons/itemMachine%s",getConstantName(PBTypes,type)) rescue nil
  231.         if !pbResolveBitmap(bitmapFileName)
  232.           bitmapFileName = sprintf("Graphics/Icons/itemMachine%03d",type)
  233.         end
  234.       end
  235.       bitmapFileName = "Graphics/Icons/item000" if !pbResolveBitmap(bitmapFileName)
  236.     end
  237.   end
  238.   return bitmapFileName
  239. end
  240.  
  241. class PokeBattle_Pokemon
  242.   attr_accessor :trmoves
  243.  
  244.   def trmoves
  245.     @trmoves=[] if !@trmoves
  246.     return @trmoves
  247.   end
  248. end
  249.  
  250. alias tr_pbGetRelearnableMoves pbGetRelearnableMoves
  251. def pbGetRelearnableMoves(pokemon)
  252.   ret=tr_pbGetRelearnableMoves(pokemon)
  253.   trmoves=[]
  254.   for i in pokemon.trmoves
  255.     trmoves.push(i) if !pokemon.hasMove?(i) && !ret.include?(i)
  256.   end
  257.   ret=ret+trmoves
  258.   return ret|[]
  259. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement