Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- looting / loot arrangement settings
- local MainBP = Container.GetByName("brocade backpack")
- local GoldBP = Container.GetByName("blue backpack")
- local LootBP = Container.GetByName("fur backpack")
- local WormsBP = Container.GetByName("golden backpack")
- local PurseBP = Container.GetByName("beach backpack")
- -- junk cleanup settings
- local itemsToSell = { 12731, 3580, 12736, 12732, 12735, 12741, 12733, 12557, 12807, 13992}
- local capToSell = 2800
- local itemsToArrange = {
- { ["id"] = 12731, ["destination"] = LootBP },
- { ["id"] = 3580, ["destination"] = LootBP },
- { ["id"] = 12736, ["destination"] = LootBP },
- { ["id"] = 12732, ["destination"] = LootBP },
- { ["id"] = 12735, ["destination"] = LootBP },
- { ["id"] = 12741, ["destination"] = LootBP },
- { ["id"] = 12733, ["destination"] = LootBP },
- { ["id"] = 12557, ["destination"] = LootBP },
- { ["id"] = 12807, ["destination"] = LootBP },
- { ["id"] = 13992, ["destination"] = LootBP },
- { ["id"] = 3492, ["destination"] = WormsBP },
- { ["id"] = 3043, ["destination"] = GoldBP },
- { ["id"] = 3035, ["destination"] = GoldBP },
- { ["id"] = 16087, ["destination"] = PurseBP },
- { ["id"] = 5895, ["destination"] = GoldBP }
- }
- local itemsToDrop = { 5951, 3111, 3123, 3108, 3578, 3581, 3031, 12318 }
- -- fishing settings
- local FishingEnabled = true
- local wormsToBuy = 800
- Automap = {}
- Automap.Path = "C:\\Users\\" .. os.getenv("USERNAME") .. "\\AppData\\Roaming\\Tibia\\Automap"
- -- parse the contents of the specified minimap file
- Automap.Parse = function(filename)
- local positions = {}
- local mapX,mapY,mapZ = tonumber(filename:sub(1, 3)), tonumber(filename:sub(4, 6)),tonumber(filename:sub(7, 8))
- local file = io.open(Automap.Path .. "\\" .. filename .. ".map", "rb")
- local data = file:read(65536)
- file:close()
- local index = 1
- for x = 0, 255 do
- for y = 0, 255 do
- table.insert(positions, {x=x+(mapX*256),y=y+(mapY*256),z=mapZ, color=data:byte(index)})
- index = index + 1
- end
- end
- return positions
- end
- -- find the minimap file containing the position specified
- Automap.GetFileFromPosition = function(pos)
- local filename = string.format("%03d%03d%02d", math.min(pos.x/256), math.min(pos.y/256), pos.z)
- return Automap.Parse(filename)
- end
- -- get all the water tiles found in the minimap file
- Automap.GetWaterTiles = function()
- local waterTiles = {}
- local curPos = Self.Position()
- local positions = Automap.GetFileFromPosition(curPos)
- for _, tile in ipairs(positions) do
- if(math.abs(tile.x - curPos.x) <= 7 and math.abs(tile.y - curPos.y) <= 5)then
- if(tile.color == 0x28)then
- local block = false
- for _, check in ipairs(positions) do
- -- water is near a tile that is not water, it's probably a border.
- if(isPositionAdjacent(check, tile) and check.color ~= 0x28)then
- block = true
- end
- end
- if(not block)then
- table.insert(waterTiles, tile)
- end
- end
- end
- end
- return waterTiles
- end
- function Container:HasCascadeBackpack()
- self = type(self)=='table' and self or Container.New(self)
- local spot = self:ItemCount() - 1
- return Item.isContainer(self:GetItemData(spot).id)
- end
- function Container:OpenCascade()
- self = type(self)=='table' and self or Container.New(self)
- if (not self:HasCascadeBackpack()) then
- return 0
- end
- local spot = self:ItemCount() - 1
- local ret = self:UseItem(spot, true)
- wait(500)
- return ret
- end
- function useCoins(id)
- local cont = Container.GetFirst()
- while (cont:isOpen()) do
- for spot = 0, cont:ItemCount() do
- local item = cont:GetItemData(spot)
- if (item.id == id) then
- if (item.count == 100) then
- cont:UseItem(spot, True)
- sleep(500)
- return true
- end
- end
- end
- cont = cont:GetNext()
- end
- return false
- end
- function dropItems()
- FishingEnabled = false
- local self = Self.Position()
- local cont = MainBP
- print('dropping')
- for spot = 0, cont:ItemCount() do
- local item = cont:GetItemData(spot)
- if(table.contains(itemsToDrop, item.id))then
- Self.DropItem(self.x, self.y, self.z, item.id)
- wait(1100, 1200)
- end
- end
- if(Self.ItemCount(3035) >= 100) then
- useCoins(3035)
- end
- FishingEnabled = true
- end
- function buyWorms()
- if(Self.ItemCount(3492) < 500) then
- Self.SayToNpc({'hi', 'trade'}, 70)
- wait(2000)
- Self.ShopBuyItemsUpTo(3492, wormsToBuy)
- wait(1000)
- end
- FishingEnabled = true
- end
- function sellFishingItems()
- FishingEnabled = false
- if(Self.Cap() < capToSell or Self.ItemCount(3492) < 500) then
- Self.SayToNpc({'hi', 'trade'}, 70)
- wait(1500)
- -- loop through our items to sell and sell each in the junk list.
- for index, item in ipairs(itemsToSell) do
- if(Self.ShopGetItemSaleCount(item) > 0)then
- displayInformationMessage("Selling items")
- Self.ShopSellAllItems(item)
- sleep(1000)
- end
- end
- -- buy worms, pretty easy.
- buyWorms()
- wait(1000)
- end
- end
- function arrangeItems()
- print('arranging')
- FishingEnabled = false
- for spot = 0, MainBP:ItemCount() do
- local item = MainBP:GetItemData(spot)
- for index = 1, #itemsToArrange do
- if(item.id == itemsToArrange[index].id)then
- print('match, arrange it!')
- local moveSuccessful = MainBP:MoveItemToContainer(spot, itemsToArrange[index].destination:Index(), 19)
- wait(800,1000)
- if(moveSuccessful ~= true)then
- print('cascade to make room')
- itemsToArrange[index].destination:OpenCascade()
- wait(500,900)
- MainBP:MoveItemToContainer(spot, itemsToArrange[index].destination:Index(), 19)
- wait(500,900)
- end
- end
- end
- end
- FishingEnabled = true
- end
- local waterTiles = Automap.GetWaterTiles()
- if(#waterTiles > 0)then
- printf("%d water tile(s) found...", #waterTiles)
- local lastPos, lastCount = Self.Position(), Self.ItemCount(3578)
- local index = 1
- while(FishingEnabled)do
- -- do we need to sale loot?
- if(Self.Cap() < capToSell)then
- sellFishingItems()
- end
- -- do we need to buy worms?
- if(Self.ItemCount(3492) < 100)then
- buyWorms()
- end
- -- check if we have worms o.O
- if(MainBP:ItemCount() >= 14)then
- print('disable fishing and start dropping shit')
- dropItems()
- arrangeItems()
- end
- if(Self.ItemCount(3492) >= 1)then
- -- if player has moved
- local curPos = Self.Position()
- if(getDistanceBetween(curPos, lastPos) > 0)then
- print("You have moved recently. Finding new fishing spots...")
- lastPos = curPos
- lastCount = Self.ItemCount(3578)
- waterTiles = Automap.GetWaterTiles()
- if(#waterTiles > 0)then
- printf("%d water tile(s) found...", #waterTiles)
- else
- print("No water tiles found. Auto Fishing has been disabled.")
- break
- end
- end
- local tile = waterTiles[index]
- Self.UseItemWithGround(3483, tile.x, tile.y, tile.z)
- wait(200)
- -- fish was caught, go to next tile
- local curCount = Self.ItemCount(3578)
- if(curCount > lastCount)then
- lastCount = curCount
- index = index + 1
- -- if fished all the tiles once
- if(index > #waterTiles)then
- print("Finished fishing all tiles on screen, restarting...")
- index = 1
- end
- end
- wait(500, 1500)
- else
- print("You are out of worms. Auto Fishing has been disabled.")
- break
- end
- end
- else
- print("No water tiles found. Auto Fishing has been disabled.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement