Advertisement
Cavitt

Auto Fisher

May 15th, 2012
2,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. Automap = {}
  2. Automap.Path = "C:\\Users\\" .. os.getenv("USERNAME") .. "\\AppData\\Roaming\\Tibia\\Automap"
  3.  
  4. -- parse the contents of the specified minimap file
  5. Automap.Parse = function(filename)
  6.     local positions = {}
  7.     local mapX,mapY,mapZ = tonumber(filename:sub(1, 3)), tonumber(filename:sub(4, 6)),tonumber(filename:sub(7, 8))
  8.     local file = io.open(Automap.Path .. "\\" .. filename .. ".map", "rb")
  9.     local data = file:read(65536)
  10.     file:close()
  11.     local index = 1
  12.     for x = 0, 255 do
  13.         for y = 0, 255 do
  14.             table.insert(positions, {x=x+(mapX*256),y=y+(mapY*256),z=mapZ, color=data:byte(index)})
  15.             index = index + 1
  16.         end
  17.     end
  18.     return positions
  19. end
  20.  
  21. -- find the minimap file containing the position specified
  22. Automap.GetFileFromPosition = function(pos)
  23.     local filename = string.format("%03d%03d%02d", math.min(pos.x/256), math.min(pos.y/256), pos.z)
  24.     return Automap.Parse(filename)
  25. end
  26.  
  27. -- get all the water tiles found in the minimap file
  28. Automap.GetWaterTiles = function()
  29.     local waterTiles = {}
  30.     local curPos = Self.Position()
  31.     local positions = Automap.GetFileFromPosition(curPos)
  32.     for _, tile in ipairs(positions) do
  33.         if(math.abs(tile.x - curPos.x) <= 7 and math.abs(tile.y - curPos.y) <= 5)then
  34.             if(tile.color == 0x28)then
  35.                 local block = false
  36.                 for _, check in ipairs(positions) do
  37.                     -- water is near a tile that is not water, it's probably a border.
  38.                     if(isPositionAdjacent(check, tile) and check.color ~= 0x28)then
  39.                         block = true
  40.                     end
  41.                 end
  42.                 if(not block)then
  43.                     table.insert(waterTiles, tile)
  44.                 end
  45.             end
  46.         end
  47.     end
  48.     return waterTiles
  49. end
  50.  
  51. print("Auto Fishing by Syntax...")
  52. local waterTiles = Automap.GetWaterTiles()
  53. if(#waterTiles > 0)then
  54.     printf("%d water tile(s) found...", #waterTiles)
  55.     local lastPos, lastCount = Self.Position(), Self.ItemCount(3578)
  56.     local index = 1
  57.     while(true)do
  58.         -- check if we have worms o.O
  59.         if(Self.ItemCount(3492) >= 1)then
  60.             -- if player has moved
  61.             local curPos = Self.Position()
  62.             if(getDistanceBetween(curPos, lastPos) > 0)then
  63.                 print("You have moved recently. Finding new fishing spots...")
  64.                 lastPos = curPos
  65.                 lastCount = Self.ItemCount(3578)
  66.                 waterTiles = Automap.GetWaterTiles()
  67.                 if(#waterTiles > 0)then
  68.                     printf("%d water tile(s) found...", #waterTiles)
  69.                 else
  70.                     print("No water tiles found. Auto Fishing has been disabled.")
  71.                     break
  72.                 end
  73.             end
  74.             local tile = waterTiles[index]
  75.             Self.UseItemWithGround(3483, tile.x, tile.y, tile.z)
  76.             wait(200)
  77.             -- fish was caught, go to next tile
  78.             local curCount = Self.ItemCount(3578)
  79.             if(curCount > lastCount)then
  80.                 lastCount = curCount
  81.                 index = index + 1
  82.                 -- if fished all the tiles once
  83.                 if(index > #waterTiles)then
  84.                     print("Finished fishing all tiles on screen, restarting...")
  85.                     index = 1
  86.                 end
  87.             end
  88.             wait(500, 1500)
  89.         else
  90.             print("You are out of worms. Auto Fishing has been disabled.")
  91.             break
  92.         end
  93.     end
  94. else
  95.     print("No water tiles found. Auto Fishing has been disabled.")
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement