Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.54 KB | None | 0 0
  1. ---------------------------------------------------
  2. -- Script Name: AutoFish
  3. -- Author: MadMartyr
  4. -- Version: 1.4
  5. -- Client Tested with: 7.0.10.1
  6. -- Written with OpenEUO
  7. -- Shard OSI / FS: (OSI)
  8. -- Last Modified:  11/4/2010
  9. -- Description: Automatically fishes down the left side of the boat
  10. --              while monitoring for enemies.  If one shows up, it
  11. --              whips out the bow you select and kills it.  Once
  12. --              the enemy is dead, it will loot various items from
  13. --              its corpse.
  14. --------------------------------------------------
  15. -- Changelog:
  16. --           11/04/2010 - v1.4
  17. --                     1. Added nets to loot and stow
  18. --                     2. All garbage is now tossed to random tiles
  19. --                     3. Boat movement on empty tile randomized
  20. --                     4. Added auto-dismount
  21. --
  22. --           11/03/2010 - v1.3
  23. --                     1. Fixed trash tossing by increased area
  24. --                     2. Fixed journal scanning
  25. --                     3. Changed wording on Hold selection
  26. --                     4. Gave random start tile for trash tossing
  27. --                     5. Set trash tossing to skip the tile the character is occupying
  28. --
  29. --           11/02/2010 - v1.2
  30. --                     1. Fixed Energy Bolt
  31. --                     2. Added Bandies
  32. --                     3. Various bug fixes
  33. --                     4. Heavy commenting
  34. --
  35. --           11/01/2010 - v1.1
  36. --                     1.  Added trash, storage, and item usage.
  37. --                     2.  Combined trash, storage, and item usage.
  38. --                      
  39.  
  40. function main()
  41.      -- Our main function is where all the magic gets started.
  42.      
  43.      -- Boots
  44.      intTrash = { 5899, 5900, 5901, 5902, 5903, 5904, 5905, 5906 }
  45.      
  46.      -- Fish types, White Pearls, and Gold to throw in the cargo hold.
  47.      intStore = { 2508, 2509, 2510, 2511, 3530, 3821, 5355, 12694, 17154, 17155, 17158, 17159, 17603, 17604, 17605, 17606, 22330 }
  48.  
  49.      -- Items to use up (Mess of Fish)
  50.      intUse = { 2463, 3542 }
  51.  
  52.      -- Loot to pull from the corpses of hostiles.
  53.      intLoot = { 2463, 3530, 3821, 3903, 5355 }
  54.      
  55.     -- Find the fishing pole to use (automatic).
  56.      intPole = FindPole()
  57.  
  58.      -- Let the user select a bow to use.  If none, use Magery.
  59.      intBow = FindBow()
  60.      if intBow == 0 then
  61.           UseMagery = true
  62.      end
  63.      
  64.      -- Let the user select the Boat's hold.
  65.      intHold = FindHold()
  66.      if intHold == 0 then
  67.           UO.ExMsg( UO.CharID, 3, 50, "Items will remain in pack." )
  68.      end
  69.  
  70.      -- Start with a clean pack, and no visible corpses.
  71.      TossStoreAndUse()
  72.      DoLoot()
  73.  
  74.      -- Make sure we have a fishing pole ID.
  75.      if intPole == 0 then
  76.          UO.ExMsg( UO.CharID, 3, 50, "Fishing Pole Not Found!" )
  77.          return
  78.      end
  79.  
  80.      -- Kick things off.
  81.      StartFishing()
  82.  
  83. end
  84.  
  85. function FindHold()
  86.      -- Our method to let the user select their boat's hold.
  87.      UO.LTargetID = 0
  88.  
  89.      UO.ExMsg( UO.CharID, 3, 50, "Select the stowing container (ESC for toon pack)." )
  90.  
  91.      UO.TargCurs = true
  92.      while( UO.TargCurs == true ) do
  93.           wait( 1 )
  94.      end
  95.      
  96.      return UO.LTargetID
  97. end
  98.  
  99. function FindBow()
  100.      -- Our method to let the user select the bow they want to use,
  101.      -- if not using magery.
  102.      UO.LTargetID = 0
  103.      UO.ExMsg( UO.CharID, 3, 50, "Select the bow you wish to use (ESC for Magery)." )
  104.  
  105.      UO.TargCurs = true
  106.      while( UO.TargCurs == true ) do
  107.           wait( 1 )
  108.      end
  109.      
  110.      return UO.LTargetID
  111. end
  112.  
  113. function StartFishing()
  114.      -- Setup all of our positioning variables.
  115.      local intX = UO.CharPosX - 3
  116.      local intY = UO.CharPosY + 3
  117.      local intStartX = UO.CharPosX
  118.      local intStartY = UO.CharPosY
  119.      
  120.      -- Start our main loop
  121.      while true == true do
  122.           -- If the character has moved, reset our positioning variables.
  123.           -- Causes: Spot is fished out, player moved the boat, player
  124.           -- moved the character.
  125.           if UO.CharPosX ~= intStartX or UO.CharPosY ~= intStartY then
  126.                intX = UO.CharPosX - 3
  127.                intY = UO.CharPosY + 3
  128.                intStartX = UO.CharPosX
  129.                intStartY = UO.CharPosY
  130.           end
  131.          
  132.           -- Use the pole
  133.           UO.LObjectID = intPole
  134.           UO.Macro( 17, 0 )
  135.           wait( 1000 )
  136.          
  137.           if UO.SysMsg == "You can't fish while riding or flying!" then
  138.                -- Dismount.
  139.                wait( 500 )
  140.                UO.LObjectID = UO.CharID
  141.                UO.Macro( 17, 0 )
  142.           end
  143.          
  144.           WaitForTargWithTimeout( 500 )
  145.          
  146.           -- Set our tagetting up to fish the specified coords.
  147.           UO.LTargetKind = 3
  148.           UO.LTargetX = intX
  149.           UO.LTargetY = intY
  150.           UO.LTargetZ = UO.CharPosZ
  151.          
  152.           -- And do it.
  153.           UO.Macro( 22, 0 )
  154.          
  155.           wait( 1000 )
  156.          
  157.           -- Wait for our fishing to be finished.  We could have done the next
  158.           -- few steps during this time, but I was seeing some strange
  159.           -- artifacts of the process.
  160.           wait( 9000 )
  161.  
  162.           -- Move on to the next fishing X coord.
  163.           intX = intX + 1
  164.  
  165.           -- We only fish 7 spots on the x plain.  -3x through +3x
  166.           -- Check to make sure we are within this area.
  167.           if intX > UO.CharPosX + 3 then
  168.                -- Moving on the next Y coord.
  169.                intY = intY + 1
  170.                -- Reset our X coord.
  171.                intX = UO.CharPosX - 3
  172.                -- Put everything away.
  173.                TossStoreAndUse()
  174.                wait( 1000 )
  175.           end
  176.          
  177.           -- We start at Y+3, and fish through Y+5.  That means we
  178.           -- we fish two tiles along the Y plain, 14 tiles total.
  179.           -- Check to make sure we are within this area.
  180.           if intY == UO.CharPosY + 5 then
  181.                -- Getting here means that intX should already be reset, so
  182.                -- we'll reset Y.
  183.                intY = UO.CharPosY + 3
  184.                -- Put everything away.
  185.                TossStoreAndUse()
  186.                wait( 1000 )
  187.           end
  188.          
  189.           -- Check our journal to see if the tile is fished out.
  190.           if isFishedOut() == true then
  191.                -- And, apparently, it is.  Move a few tiles.
  192.                if math.random( 1, 2 ) == 1 then
  193.                     UO.Macro( 1, 0, "left" )
  194.                else
  195.                     UO.Macro( 1, 0, "right" )
  196.                end
  197.                wait( 2500 )
  198.                if math.random( 1, 2 ) == 1 then
  199.                     UO.Macro( 1, 0, "forward" )
  200.                else
  201.                     UO.Macro( 1, 0, "backward" )
  202.                end
  203.                wait( 2500 )
  204.                UO.Macro( 1, 0, "stop" )
  205.           end
  206.          
  207.           -- We're under attack.  Own that bitch up!
  208.           if UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 then
  209.                -- Like I said, asshole...own that bitch up!
  210.                DoBattle()
  211.           end
  212.          
  213.      end          
  214. end
  215.  
  216. function WaitForTargWithTimeout(intTimeout)
  217.           while( UO.TargCurs == false ) do
  218.                wait( 1 )
  219.                intTimeout = intTimeout + 1
  220.                if intTimeout >= 500 then
  221.                     break
  222.                end
  223.           end
  224. end
  225.  
  226. function isFishedOut()
  227.      -- We're only gonna scan the last five lines so we don't mistakenly return
  228.      -- true.
  229.  
  230.      local intCycle
  231.      local intMax = UO.ScanJournal(0)
  232.      for intCycle = 0, 5 do
  233.           local strLine = UO.GetJournal( intCycle )
  234.           if strLine == UO.CharName .. ": The fish don't seem to be biting here." then
  235.                -- Tile is empty, move on.
  236.                return true
  237.           end  
  238.      end
  239.      
  240.      return false
  241. end
  242.  
  243. function TossStoreAndUse()
  244.     --Loop through all items found in the backpack.
  245.     local intCycle
  246.     local intMax = UO.ScanItems( false )
  247.    
  248.     for intCycle = 1,intMax do
  249.          
  250.          -- Get all of the info about this item that we need.
  251.          local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
  252.          
  253.          -- Loop through our trash array.
  254.          local intCycle2
  255.          local intMax2 = table.getn( intTrash )
  256.          for intCycle2 = 1, intMax2 do
  257.               if Type == intTrash[intCycle2] and ContID == UO.BackpackID then
  258.                    -- Bitch ain't worth shit.  Toss it.
  259.                    UO.Drag( ID )
  260.                    wait( 1000 )
  261.                    UO.DropG( UO.CharPosX + math.random( -2, 2 ), UO.CharPosY + math.random( -2, 2 ) )
  262.                    wait( 1000 )
  263.               end
  264.          end
  265.          
  266.          -- Loop through our keepers array.
  267.          if intHold ~= 0 then
  268.               intMax2 = table.getn( intStore )
  269.               for intCycle2 = 1, intMax2 do
  270.                   if Type == intStore[intCycle2] and ContID == UO.BackpackID then
  271.                         -- Good shit, stow it.
  272.                         UO.Drag( ID, 999 )
  273.                         wait( 1000 )
  274.                         UO.DropC( intHold )
  275.                         wait( 1000 )
  276.                    end
  277.               end
  278.          end            
  279.  
  280.          -- Loop through our array of stuff to use (MiB, special fish, etc.)
  281.          intMax2 = table.getn( intUse )
  282.          for intCycle2 = 1, intMax2 do
  283.              if Type == intUse[intCycle2] and ContID == UO.BackpackID then
  284.                   UO.LObjectID = ID
  285.                   UO.Macro( 17, 0 )
  286.                   wait( 1000 )
  287.               end
  288.          end            
  289.     end
  290. end
  291.  
  292. function DoBattle()
  293.      -- Time to kick some ass.
  294.      if UseMagery == true then
  295.           -- This attempts to ensure that we're not needlessly casting.  When it's
  296.           -- dead, stop.
  297.           while UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 do
  298.                -- Cast Energy Bolt
  299.                UO.Macro( 15, 41 )
  300.                
  301.                wait( 3000 )
  302.                -- Wait for the Target cursor.
  303.                while( UO.TargCurs == false ) do
  304.                      wait( 1 )
  305.                end
  306.                
  307.                -- Target the current enemy.  We don't cache this in case you have
  308.                -- multiple enemies around.
  309.                UO.LTargetID = UO.EnemyID
  310.                UO.LTargetKind = 1 -- Thanks for the tip, PetKiller.
  311.                UO.Macro( 22, 0 )
  312.                wait( 2000 )
  313.                
  314.                -- See if we're in trouble.  Could be changed to 1/2 HP, but 3/4 HP
  315.                -- worked best for me.
  316.                if UO.Hits < UO.MaxHits - (UO.MaxHits / 4) then
  317.                     -- Cast Greater Heal
  318.                     UO.Macro(15, 28)
  319.                
  320.                     wait( 3000 )
  321.                    
  322.                     -- Wait for the Target cursor.
  323.                     while( UO.TargCurs == false ) do
  324.                           wait( 1 )
  325.                     end
  326.                    
  327.                     -- Target self
  328.                     UO.LTargetID = UO.CharID
  329.                     UO.Macro( 22, 0 )
  330.                
  331.                     wait( 1000 )                                              
  332.                    
  333.                end
  334.           end
  335.      else
  336.      
  337.           -- Equip the bow and whip it's candy ass.
  338.           UO.LObjectID = intBow
  339.           UO.Macro( 37, 0 )
  340.  
  341.           while UO.EnemyID ~= 0 and UO.EnemyHits ~= 0 do
  342.                -- We need to heal.  Using bandies.
  343.                if UO.Hits < UO.MaxHits - (UO.MaxHits / 4) then
  344.                     UO.LObjectID = FindBandies()
  345.                     UO.Macro(37, 0)
  346.                
  347.                     wait( 3000 )
  348.                     -- Wait for the Target cursor.
  349.                     while( UO.TargCurs == false ) do
  350.                           wait( 1 )
  351.                     end
  352.                    
  353.                     -- Target the character
  354.                     UO.LTargetID = UO.CharID
  355.                     UO.LTargetKind = 1
  356.                     UO.Macro( 22, 0 )
  357.                
  358.                     wait( 3000 )                                              
  359.                
  360.                     -- Re-equip the bow, just in case.
  361.                     UO.LObjectID = intBow
  362.                     UO.Macro( 37, 0 )
  363.                    
  364.                end
  365.           end
  366.      end
  367.      wait( 1000 )
  368.      
  369.      -- Bitch is dead.  Get your booty.
  370.      DoLoot()
  371. end
  372.  
  373. function DoLoot()
  374.     -- Find the corpse(s)
  375.     local intCycle
  376.     local intMax = UO.ScanItems( false )
  377.    
  378.     -- Loop through all items
  379.     for intCycle = 1,intMax do
  380.          
  381.          -- Get all of the info about this item that we need.
  382.          local corpseID,corpseType,corpseKind,corpseContID = UO.GetItem( intCycle )
  383.          
  384.          -- If it's the corpse.
  385.          if corpseType == 8198 then
  386.               -- I'm pretty sure Type 8198 is just a Sea Serpent corpse, but
  387.               -- we're not really worried about looting Water Elems.
  388.              
  389.               -- Move the corpse pack gump.  Not really needed, but I like it asshole.
  390.               UO.NextCPosX = 100        
  391.               UO.NextCPosY = 100        
  392.  
  393.               -- Open the gump.
  394.               UO.LObjectID = corpseID
  395.               UO.Macro( 17, 0, "" )
  396.               wait( 1000 )
  397.              
  398.               -- Loop through all items to get only what's in the corpse.
  399.               local intCycle2
  400.               local intMax2 = UO.ScanItems( true )
  401.               for intCycle2 = 1, intMax2 do
  402.                   local itemID,itemType,itemKind,itemContID = UO.GetItem( intCycle2 )
  403.          
  404.                   -- It's in the corpse.
  405.                   if itemContID == UO.ContID then
  406.                         -- Loop through and make sure it's the loot we want.
  407.                         local intCycle3
  408.                         local intMax3 = table.getn( intLoot )
  409.                         for intCycle3 = 1, intMax3 do
  410.                              if itemType == intLoot[intCycle3] then
  411.                                   -- Loot match, grab it!  Quick!
  412.                                   UO.Drag( itemID, 999 )
  413.                                   wait( 1000 )
  414.                                   UO.DropC( UO.BackpackID )
  415.                                   wait( 1000 )
  416.                              end
  417.                         end
  418.                    end                                
  419.               end
  420.              
  421.               -- Hide the corpse we just raided and move on.
  422.               UO.HideItem( corpseID )
  423.          end            
  424.     end
  425.  
  426. end
  427.  
  428. function FindPole()
  429.     --Loop through all items
  430.     local intCycle
  431.     local intMax = UO.ScanItems( false )
  432.    
  433.     for intCycle = 1,intMax do
  434.          
  435.          -- Get all of the info about this item that we need.
  436.          local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
  437.          
  438.          -- If it's a pole, use it.
  439.          if Type == 3519 then
  440.               return ID
  441.          end            
  442.     end
  443. end
  444.  
  445. function FindBandies()
  446.     --Loop through all items
  447.     local intCycle
  448.     local intMax = UO.ScanItems( false )
  449.    
  450.     for intCycle = 1,intMax do
  451.          
  452.          -- Get all of the info about this item that we need.
  453.          local ID,Type,Kind,ContID,X,Y = UO.GetItem( intCycle )
  454.          
  455.          -- If it's bandies, we're usin' it!
  456.          if Type == 3617 then
  457.               return ID
  458.          end            
  459.     end
  460. end
  461.  
  462. -- Without this next line, the script will NOT work.
  463. -- This line initiates the entire runtime process.
  464. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement