Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.71 KB | None | 0 0
  1. -- looting / loot arrangement settings
  2. local MainBP = Container.GetByName("brocade backpack")
  3. local GoldBP = Container.GetByName("blue backpack")
  4. local LootBP = Container.GetByName("fur backpack")
  5. local WormsBP = Container.GetByName("golden backpack")
  6. local PurseBP = Container.GetByName("beach backpack")
  7.  
  8. -- junk cleanup settings
  9. local itemsToSell = { 12731, 3580, 12736, 12732, 12735, 12741, 12733, 12557, 12807, 13992}
  10. local capToSell = 2800
  11. local itemsToArrange = {
  12.                          { ["id"] = 12731, ["destination"] = LootBP },
  13.                          { ["id"] = 3580,  ["destination"] = LootBP },
  14.                          { ["id"] = 12736, ["destination"] = LootBP },
  15.                          { ["id"] = 12732, ["destination"] = LootBP },
  16.                          { ["id"] = 12735, ["destination"] = LootBP },
  17.                          { ["id"] = 12741, ["destination"] = LootBP },
  18.                          { ["id"] = 12733, ["destination"] = LootBP },
  19.                          { ["id"] = 12557, ["destination"] = LootBP },
  20.                          { ["id"] = 12807, ["destination"] = LootBP },
  21.                          { ["id"] = 13992, ["destination"] = LootBP },
  22.                          { ["id"] = 3492,  ["destination"] = WormsBP },
  23.                          { ["id"] = 3043,  ["destination"] = GoldBP },
  24.                          { ["id"] = 3035,  ["destination"] = GoldBP },
  25.                          { ["id"] = 16087, ["destination"] = PurseBP },
  26.                          { ["id"] = 5895,  ["destination"] = GoldBP }
  27.                        }
  28.  
  29. local itemsToDrop = { 5951, 3111, 3123, 3108, 3578, 3581, 3031, 12318 }
  30.  
  31. -- fishing settings
  32. local FishingEnabled = true
  33. local wormsToBuy = 800
  34.  
  35. Automap = {}
  36. Automap.Path = "C:\\Users\\" .. os.getenv("USERNAME") .. "\\AppData\\Roaming\\Tibia\\Automap"
  37.  
  38. -- parse the contents of the specified minimap file
  39. Automap.Parse = function(filename)
  40.     local positions = {}
  41.     local mapX,mapY,mapZ = tonumber(filename:sub(1, 3)), tonumber(filename:sub(4, 6)),tonumber(filename:sub(7, 8))
  42.     local file = io.open(Automap.Path .. "\\" .. filename .. ".map", "rb")
  43.     local data = file:read(65536)
  44.     file:close()
  45.     local index = 1
  46.     for x = 0, 255 do
  47.         for y = 0, 255 do
  48.             table.insert(positions, {x=x+(mapX*256),y=y+(mapY*256),z=mapZ, color=data:byte(index)})
  49.             index = index + 1
  50.         end
  51.     end
  52.     return positions
  53. end
  54.  
  55. -- find the minimap file containing the position specified
  56. Automap.GetFileFromPosition = function(pos)
  57.     local filename = string.format("%03d%03d%02d", math.min(pos.x/256), math.min(pos.y/256), pos.z)
  58.     return Automap.Parse(filename)
  59. end
  60.  
  61. -- get all the water tiles found in the minimap file
  62. Automap.GetWaterTiles = function()
  63.     local waterTiles = {}
  64.     local curPos = Self.Position()
  65.     local positions = Automap.GetFileFromPosition(curPos)
  66.     for _, tile in ipairs(positions) do
  67.         if(math.abs(tile.x - curPos.x) <= 7 and math.abs(tile.y - curPos.y) <= 5)then
  68.             if(tile.color == 0x28)then
  69.                 local block = false
  70.                 for _, check in ipairs(positions) do
  71.                     -- water is near a tile that is not water, it's probably a border.
  72.                     if(isPositionAdjacent(check, tile) and check.color ~= 0x28)then
  73.                         block = true
  74.                     end
  75.                 end
  76.                 if(not block)then
  77.                     table.insert(waterTiles, tile)
  78.                 end
  79.             end
  80.         end
  81.     end
  82.     return waterTiles
  83. end
  84.  
  85. function Container:HasCascadeBackpack()
  86.     self = type(self)=='table' and self or Container.New(self)
  87.     local spot = self:ItemCount() - 1
  88.     return Item.isContainer(self:GetItemData(spot).id)
  89. end
  90.  
  91. function Container:OpenCascade()
  92.     self = type(self)=='table' and self or Container.New(self)
  93.     if (not self:HasCascadeBackpack()) then
  94.         return 0
  95.     end
  96.     local spot = self:ItemCount() - 1
  97.     local ret = self:UseItem(spot, true)    
  98.     wait(500)
  99.     return ret
  100. end
  101.  
  102. function useCoins(id)  
  103.     local cont = Container.GetFirst()  
  104.     while (cont:isOpen()) do
  105.         for spot = 0, cont:ItemCount() do
  106.             local item = cont:GetItemData(spot)  
  107.             if (item.id == id) then
  108.                 if (item.count == 100) then
  109.                     cont:UseItem(spot, True)
  110.                     sleep(500)
  111.                     return true
  112.                 end
  113.             end
  114.         end
  115.         cont = cont:GetNext()  
  116.     end
  117.     return false
  118. end
  119.  
  120. function dropItems()
  121.     FishingEnabled = false
  122.     local self = Self.Position()
  123.     local cont = MainBP
  124.     print('dropping')
  125.     for spot = 0, cont:ItemCount() do
  126.         local item = cont:GetItemData(spot)
  127.         if(table.contains(itemsToDrop, item.id))then                  
  128.             Self.DropItem(self.x, self.y, self.z, item.id)
  129.             wait(1100, 1200)
  130.         end        
  131.     end
  132.    
  133.     if(Self.ItemCount(3035) >= 100) then
  134.         useCoins(3035)
  135.     end
  136.  
  137.     FishingEnabled = true
  138. end
  139.  
  140. function buyWorms()
  141.     if(Self.ItemCount(3492) < 500) then
  142.         Self.SayToNpc({'hi', 'trade'}, 70)
  143.         wait(2000)
  144.  
  145.         Self.ShopBuyItemsUpTo(3492, wormsToBuy)
  146.  
  147.         wait(1000)
  148.     end
  149.     FishingEnabled = true
  150. end
  151.  
  152. function sellFishingItems()
  153.     FishingEnabled = false
  154.     if(Self.Cap() < capToSell or Self.ItemCount(3492) < 500) then
  155.         Self.SayToNpc({'hi', 'trade'}, 70)
  156.         wait(1500)
  157.         -- loop through our items to sell and sell each in the junk list.
  158.         for index, item in ipairs(itemsToSell) do
  159.             if(Self.ShopGetItemSaleCount(item) > 0)then
  160.                 displayInformationMessage("Selling items")
  161.                 Self.ShopSellAllItems(item)
  162.                 sleep(1000)
  163.             end
  164.         end
  165.         -- buy worms, pretty easy.
  166.         buyWorms()
  167.  
  168.         wait(1000)
  169.     end
  170. end
  171.  
  172. function arrangeItems()
  173.     print('arranging')
  174.     FishingEnabled = false
  175.     for spot = 0, MainBP:ItemCount() do
  176.         local item = MainBP:GetItemData(spot)
  177.        
  178.         for index = 1, #itemsToArrange do
  179.             if(item.id == itemsToArrange[index].id)then
  180.                 print('match, arrange it!')
  181.                 local moveSuccessful = MainBP:MoveItemToContainer(spot, itemsToArrange[index].destination:Index(), 19)
  182.                 wait(800,1000)
  183.                 if(moveSuccessful ~= true)then
  184.                     print('cascade to make room')
  185.                     itemsToArrange[index].destination:OpenCascade()
  186.                     wait(500,900)                    
  187.                     MainBP:MoveItemToContainer(spot, itemsToArrange[index].destination:Index(), 19)
  188.                     wait(500,900)
  189.                 end
  190.             end
  191.         end
  192.     end
  193.     FishingEnabled = true
  194. end
  195.  
  196. local waterTiles = Automap.GetWaterTiles()
  197.  
  198. if(#waterTiles > 0)then
  199.     printf("%d water tile(s) found...", #waterTiles)
  200.     local lastPos, lastCount = Self.Position(), Self.ItemCount(3578)
  201.     local index = 1
  202.  
  203.     while(FishingEnabled)do
  204.         -- do we need to sale loot?
  205.         if(Self.Cap() < capToSell)then
  206.             sellFishingItems()
  207.         end
  208.         -- do we need to buy worms?
  209.         if(Self.ItemCount(3492) < 100)then
  210.             buyWorms()
  211.         end
  212.         -- check if we have worms o.O
  213.         if(MainBP:ItemCount() >= 14)then
  214.             print('disable fishing and start dropping shit')
  215.             dropItems()
  216.             arrangeItems()     
  217.         end
  218.  
  219.         if(Self.ItemCount(3492) >= 1)then
  220.             -- if player has moved
  221.             local curPos = Self.Position()
  222.             if(getDistanceBetween(curPos, lastPos) > 0)then
  223.                 print("You have moved recently. Finding new fishing spots...")
  224.                 lastPos = curPos
  225.                 lastCount = Self.ItemCount(3578)
  226.                 waterTiles = Automap.GetWaterTiles()
  227.                 if(#waterTiles > 0)then
  228.                     printf("%d water tile(s) found...", #waterTiles)
  229.                 else
  230.                     print("No water tiles found. Auto Fishing has been disabled.")
  231.                     break
  232.                 end
  233.             end
  234.             local tile = waterTiles[index]
  235.             Self.UseItemWithGround(3483, tile.x, tile.y, tile.z)
  236.             wait(200)
  237.             -- fish was caught, go to next tile
  238.             local curCount = Self.ItemCount(3578)
  239.             if(curCount > lastCount)then
  240.                 lastCount = curCount
  241.                 index = index + 1
  242.                 -- if fished all the tiles once
  243.                 if(index > #waterTiles)then
  244.                     print("Finished fishing all tiles on screen, restarting...")
  245.                     index = 1
  246.                 end
  247.             end
  248.             wait(500, 1500)
  249.         else
  250.             print("You are out of worms. Auto Fishing has been disabled.")
  251.             break
  252.         end
  253.     end
  254. else
  255.     print("No water tiles found. Auto Fishing has been disabled.")
  256. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement