Auto DF

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 14

-- Koncol Dey 19cm

LogToConsole("Started")

maxPlayerCount = 3 -- if u set this to 1 this script will not run for 10 seconds if
theres more than 1 person in the world. it will continue if conditions are met.

platformID = FindItemID("Fish Landing Platform")


dirtID = FindItemID("Dirt")
dirtSeedID = FindItemID("Dirt Seed")
placeDirtRowsDelay = 0 -- use 150 kinda fixes buggy pathfinding
droplist = {"Dirt", "Dirt Seed", "Cave Background", "Cave Background Seed", "Lava",
"Lava Seed", "Rock", "Rock Seed"}
trashlist = {"Dirt", "Dirt Seed", "Cave Background", "Cave Background Seed",
"Lava", "Lava Seed", "Rock", "Rock Seed"}

function punch(x, y)
pkt = {}
pkt.px = x;
pkt.py = y;
pkt.type = 3;
pkt.value = 18;
pkt.x = GetLocal().posX;
pkt.y = GetLocal().posY;
SendPacketRaw(false, pkt);
Sleep(180);
end

function place(x, y, itemID)


pkt = {}
pkt.px = x;
pkt.py = y;
pkt.type = 3;
pkt.value = itemID;
pkt.x = GetLocal().posX;
pkt.y = GetLocal().posY;
SendPacketRaw(false, pkt);
Sleep(110)
end

function getPlayerCount()
count = 0
for _, player in pairs(GetPlayerList()) do
count = count+1
end
return count
end

function getItemAmount(itemid)
for _, item in pairs(GetInventory()) do
if item.id == itemid then
return item.amount
end
end
return 0
end

function isItemToDrop()
count = 0
for i, drop in ipairs(droplist) do

dropID = FindItemID(drop)
if drop == "Rock" then
dropID = 10
end
if drop == "Rock Seed" then
dropID = 11
end

if getItemAmount(dropID) >= 200 then


count = count + 1
return count
end
end
return count
end

function isItemToTrash(amount)
count = 0
for i, trash in ipairs(trashlist) do

trashID = FindItemID(trash)
if trash == "Rock" then
trashID = 10
end
if trash == "Rock Seed" then
trashID = 11
end

if getItemAmount(trashID) >= amount then


count = count + 1
return count
end
end
return count
end

function drop()
for i, drop in ipairs(droplist) do

dropID = FindItemID(drop)
if drop == "Rock" then
dropID = 10
end
if drop == "Rock Seed" then
dropID = 11
end

if getItemAmount(dropID) >= 200 then


SendPacket(2, "action|drop\n|itemID|"..dropID)
Sleep(1000)
--SendPacket(2, "action|dialog_return\ndialog_name|drop_item\
nitemID|"..FindItemID(drop).."|\ncount|"..getItemAmount(FindItemID(drop)))
Sleep(1000)
LogToConsole("Dropped item")
end
end
end
function trash(amount)
for i, trash in ipairs(trashlist) do

trashID = FindItemID(trash)
if trash == "Rock" then
trashID = 10
end
if trash == "Rock Seed" then
trashID = 11
end

if getItemAmount(trashID) >= amount then


SendPacket(2, "action|trash\n|itemID|"..trashID)
Sleep(1000)
SendPacket(2, "action|dialog_return\ndialog_name|trash_item\
nitemID|"..trashID.."|\ncount|"..getItemAmount(trashID))
Sleep(1000)
LogToConsole("Trashed item")
end
end
end

function PathFindToObj(objID ,targetAmount)


for _, obj in pairs(GetObjectList()) do
if obj.itemid == objID and obj.amount >= targetAmount then
FindPath(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32))
--LogToConsole("Finding Path to "..math.floor(obj.posX/32).." and
"..math.floor(obj.posY/32).." id "..obj.itemid.." amount "..obj.amount)
return true
end
end
return false
end

function PathFindToObjUnobst()
for _, obj in pairs(GetObjectList()) do
if GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 0 or GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 2 then
FindPath(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32))
return true
end
end
return false
end

function getFloatingItemAmount(objID)
count = 0
for _, obj in pairs(GetObjectList()) do
if obj.itemid == objID then -- and GetTiles(math.floor(obj.posX/32),
math.floor(obj.posY/32)).flag == 0
count = count + obj.amount
end
end
return count
end
function getFloatingObjAmountUnobst()
count = 0
for _, obj in pairs(GetObjectList()) do
if GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 0 or GetTiles(math.floor((obj.posX+10)/32),
math.floor((obj.posY+10)/32)).flag == 2 then
count = count + 1
end
end
return count
end

function getPlacedAmount(id)
count = 0
for _, tile in pairs(GetTiles()) do
if tile.fg == id then -- and GetTiles(math.floor(obj.posX/32),
math.floor(obj.posY/32)).flag == 0
count = count + 1
end
end
return count
end

function plant(seedID)
for _, tile in pairs(GetTiles()) do
if tile.y >= 23 then
if tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 1 or
tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 2 then
--if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2
and math.abs(tile.y - math.floor(GetLocal().posY/32)) <= 2 then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
--if(GetTiles(math.floor(GetLocal().posX/32),
math.floor(GetLocal().posY/32)).fg == 0) then
if(GetTiles(math.floor(GetLocal().posX/32)+1,
math.floor(GetLocal().posY/32)).fg == 0) then
place(tile.x+1, tile.y, seedID)
end
place(tile.x, tile.y, seedID)
--end
else
if(math.floor(GetLocal().posX/32) == tile.x-1 and
math.floor(GetLocal().posY/32) == tile.y) then
FindPath(tile.x, tile.y)
Sleep(50)
else
FindPath(tile.x, tile.y)
Sleep(100)
end
end
return true
end
end
end
return false
end

function harvest(seedID)
for _, tile in pairs(GetTiles()) do
if tile.y >= 23 then
if(tile.fg == seedID and tile.readyharvest == 1) then
--if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2
and math.abs(tile.y - math.floor(GetLocal().posY/32)) <= 2 then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
if(GetTiles(math.floor(GetLocal().posX/32)+1,
math.floor(GetLocal().posY/32)).fg == seedID) then
punch(tile.x+1, tile.y)
end
punch(tile.x, tile.y)
--end
else
if(math.floor(GetLocal().posX/32) == tile.x-1 and
math.floor(GetLocal().posY/32) == tile.y) then
FindPath(tile.x, tile.y)
Sleep(50)
else
FindPath(tile.x, tile.y)
Sleep(100)
end
end
return true
end
end
end
return false
end

function hasHarvestableTrees(seedID)
for _, tile in pairs(GetTiles()) do
if (tile.fg == seedID and tile.readyharvest == 1) then
return true
end
end
return false
end

function canEndDirtRows()
for _, tile in pairs(GetTiles()) do
if (tile.x == 97 and tile.y == 22 and tile.fg ~= 0) then
return true
end
end
return false
end
----------------------------------------------------------------
function clearLeft()
for _, tile in pairs(GetTiles()) do
if(tile.x>=0 and tile.x<=1 and tile.y<54 and tile.flag == 1)then -- 2
columns to the left

if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2 and


math.abs((tile.y-1) - math.floor(GetLocal().posY/32)) <= 2 then
--if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y-1 then
punch(tile.x, tile.y) --punch solid block
else
FindPath(tile.x, tile.y-1)
Sleep(100)
end
return true

elseif(tile.x>=0 and tile.x<=1 and tile.y<54 and tile.bg ~= 0)then

if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2 and


math.abs(tile.y - math.floor(GetLocal().posY/32)) <= 2 then
--if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
punch(tile.x, tile.y) --punch bg
else
FindPath(tile.x, tile.y)
Sleep(100)
end
return true
end
end
return false
end
----------------------------------------------------------------
function placePlatformsLeft()
for _, tile in pairs(GetTiles()) do
if tile.x ==1 and (tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag ==
1 or tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 2) then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y and math.floor(GetLocal().posY/32)>2 then
place(tile.x, tile.y-1, platformID) --place platform
else
if GetTiles(1, 2).fg == platformID then
return false
end
FindPath(tile.x, tile.y)
Sleep(100)
end
return true
end
end
return false
end
----------------------------------------------------------------
function clearRight()
for _, tile in pairs(GetTiles()) do
if(tile.x>=98 and tile.x<=99 and tile.y<54 and tile.flag == 1)then -- 2
columns to the left

if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2 and


math.abs((tile.y-1) - math.floor(GetLocal().posY/32)) <= 2 then
--if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y-1 then
punch(tile.x, tile.y) --punch solid block
else
FindPath(tile.x, tile.y-1)
Sleep(50)
end
return true
elseif(tile.x>=98 and tile.x<=99 and tile.y<54 and tile.bg ~= 0)then
if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2 and
math.abs(tile.y - math.floor(GetLocal().posY/32)) <= 2 then
--if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y then
punch(tile.x, tile.y) --punch bg
else
FindPath(tile.x, tile.y)
Sleep(50)
end
return true
end
end
return false
end
----------------------------------------------------------------
function placePlatformsRight()
for _, tile in pairs(GetTiles()) do
if tile.x ==98 and (tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag ==
1 or tile.fg == 0 and GetTiles(tile.x, tile.y+1).flag == 2) then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y and math.floor(GetLocal().posY/32)>2 then
place(tile.x, tile.y-1, platformID) --place platform
else
if GetTiles(98, 2).fg == platformID then
return false
end
FindPath(tile.x, tile.y)
Sleep(100)
end

return true
end
end
return false
end
----------------------------------------------------------------
function dirtFarm()
botname = "133pkmd10"
SendPacket(2, "action|input\n|text|/pull 133pkmd10") Sleep(200)
for _, tile in pairs(GetTiles()) do
if(tile.y<54 and tile.x>=2 and tile.x<=97 and tile.bg == 14 and
GetTiles(tile.x, tile.y+1).bg == 14) then
if math.abs(tile.x - math.floor(GetLocal().posX/32)) <= 2 and
math.abs((tile.y-1) - math.floor(GetLocal().posY/32)) <= 2 then
--if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y-1 then
punch(tile.x, tile.y+1) --punch cave
else
FindPath(tile.x, tile.y-1)
Sleep(50)
end
return true
end
end
return false
end
----------------------------------------------------------------
function breakLava()
for _, tile in pairs(GetTiles()) do
if(tile.fg == 4)then
if math.floor(GetLocal().posX/32) == tile.x+1 and
math.floor(GetLocal().posY/32) == tile.y-1 then
punch(tile.x, tile.y) --punch lava
else
FindPath(tile.x+1, tile.y-1)
Sleep(100)
end
return true
elseif tile.y>44 and tile.x>=1 and tile.x<=97 then
if (tile.flag == 1 and GetTiles(tile.x+1, tile.y).fg == 0) or
(tile.flag == 2 and GetTiles(tile.x+1, tile.y).fg == 0) then
if math.floor(GetLocal().posX/32) == tile.x+2 and
math.floor(GetLocal().posY/32) == tile.y-1 then
place(tile.x+1, tile.y, dirtID)
else
FindPath(tile.x+2, tile.y-1)
Sleep(100)
end
return true
end
end
end
return false
end
----------------------------------------------------------------
function placeDirtRows()
for _, tile in pairs(GetTiles()) do
if tile.x>=1 and tile.x<=97 then
if (tile.flag == 1 and GetTiles(tile.x+1, tile.y).fg == 0) or
(tile.flag == 2 and GetTiles(tile.x+1, tile.y).fg == 0) then
if math.floor(GetLocal().posX/32) == tile.x and
math.floor(GetLocal().posY/32) == tile.y-1 then
place(tile.x+2, tile.y, dirtID)--added this for
antibug kinda
place(tile.x+1, tile.y, dirtID)
Sleep(placeDirtRowsDelay)
else

FindPath(tile.x, tile.y-1)
Sleep(100)
end
return true
end
end
end
return false
end
----------------------------------------------------------------
--**************************************************************
--RUN HERE
function main()
LogToConsole("Clearing Left Side")
runClearLeft = true
while runClearLeft == true do
if getPlayerCount() <= maxPlayerCount then
if clearLeft() == false then
runClearLeft = false
end
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Cleared Left Side")
--**************************************************************
LogToConsole("Placing Platforms Left Side")
if getItemAmount(platformID) >= 26 then
runPlacePlatformsLeft = true
else
runPlacePlatformsLeft = false
end
while runPlacePlatformsLeft == true do
if getPlayerCount() <= maxPlayerCount then
if placePlatformsLeft() == false then
runPlacePlatformsLeft = false
end
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Placed Platforms Left Side")
--**************************************************************
LogToConsole("Clearing Right Side")
runClearRight = true
while runClearRight == true do
if getPlayerCount() <= maxPlayerCount then
if clearRight() == false then
runClearRight = false
end
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Cleared Right Side")
--**************************************************************
LogToConsole("Placing Platforms Right Side")
if getItemAmount(platformID) >= 26 then
runPlacePlatformsRight = true
else
runPlacePlatformsRight = false
end
while runPlacePlatformsRight == true do
if getPlayerCount() <= maxPlayerCount then
if placePlatformsRight() == false then
runPlacePlatformsRight = false
end
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Placed Platforms Right Side")
--**************************************************************
LogToConsole("Dirt Farm Start")
botname = "killertY"
SendPacket(2, "action|input\n|text|/pull "..botname)
runDirtFarm = true
while runDirtFarm == true do
if getPlayerCount() <= maxPlayerCount then
if dirtFarm() == false then
runDirtFarm = false
end
if isItemToDrop()>0 then
Sleep(500)
FindPath(97, math.floor(GetLocal().posY/32))
Sleep(2000)
drop()
Sleep(2000)
end
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(1000)
end
end
end
LogToConsole("Dirt Farm Done")
--**************************************************************
LogToConsole("Replacing Lava with Dirt")
runBreakLava = true
while runBreakLava == true do
if getPlayerCount() <= maxPlayerCount then
if breakLava() == false then
runBreakLava = false
end
if getItemAmount(FindItemID("Lava")) == 200 or
getItemAmount(FindItemID("Lava See")) == 200 then
FindPath(98, math.floor(GetLocal().posY/32))
Sleep(2000)
----------------------
SendPacket(2, "action|drop\n|itemID|"..FindItemID("Lava"))
Sleep(1000)
--SendPacket(2, "action|dialog_return\ndialog_name|
drop_item\nitemID|"..FindItemID(drop).."|\
ncount|"..getItemAmount(FindItemID(drop)))
Sleep(1000)
LogToConsole("Dropped Lava")
----------------------
SendPacket(2, "action|drop\n|itemID|"..FindItemID("Lava
Seed"))
Sleep(1000)
--SendPacket(2, "action|dialog_return\ndialog_name|
drop_item\nitemID|"..FindItemID(drop).."|\
ncount|"..getItemAmount(FindItemID(drop)))
Sleep(1000)
LogToConsole("Dropped Lava Seed")
----------------------
--Sleep(2000)
end

while getItemAmount(dirtID) == 0 and


getFloatingItemAmount(dirtID) > 0 and getPlayerCount() <= maxPlayerCount do
PathFindToObj(dirtID, 1)
Sleep(2000)
end

else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Replacing Lava Ended")
--**************************************************************
if getPlacedAmount(platformID) >= 52 then
runBlocks = true
LogToConsole("Gather Blocks")
else
runBlocks = false
LogToConsole("Dont Have Plats Cant Run: Gather Blocks")
end

while runBlocks == true and canEndDirtRows() == false do


if getPlayerCount() <= maxPlayerCount then

-------------------------
LogToConsole("Total Dirt: "..getFloatingItemAmount(dirtID) +
getItemAmount(dirtID))
Sleep(200)
if getFloatingItemAmount(dirtID) + getItemAmount(dirtID) <= 1056
and canEndDirtRows() == false then

PathFindToObj(dirtSeedID, 1)
Sleep(2000)

if getItemAmount(dirtSeedID) == 0 and
getFloatingItemAmount(dirtSeedID) > 0 then
LogToConsole("PathFinding to Dirt Seed")
while (getItemAmount(dirtSeedID) < 200 and
getFloatingItemAmount(dirtSeedID) > 0 ) and getPlayerCount() <= maxPlayerCount do
PathFindToObj(dirtSeedID, 1)
Sleep(1000)
end
end

if getItemAmount(dirtSeedID) > 0 and


getPlacedAmount(dirtSeedID) < 175 then
LogToConsole("Planting")
while getItemAmount(dirtSeedID) > 0 and
getPlacedAmount(dirtSeedID) < 175 and getPlayerCount() <= maxPlayerCount do
plant(dirtSeedID)
end
end

if hasHarvestableTrees(dirtSeedID) == true then


LogToConsole("Harvesting")
while hasHarvestableTrees(dirtSeedID) == true and
getPlayerCount() <= maxPlayerCount do
harvest(dirtSeedID)
end
end

else
runBlocks = false
end

-------------------------
else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Gather Blocks Ended")
--**************************************************************
if getPlacedAmount(platformID) >= 52 then
runPlaceDirtRows = true
LogToConsole("Make Dirt Rows")
else
runPlaceDirtRows = false
LogToConsole("Dont Have Plats Cant Run: Make Dirt Rows")
end

while runPlaceDirtRows == true and canEndDirtRows() == false do


if getPlayerCount() <= maxPlayerCount then
if placeDirtRows() == false and canEndDirtRows() == true then
runPlaceDirtRows = false
end

if getItemAmount(dirtID) == 0 and getFloatingItemAmount(dirtID) >


0 then
while getItemAmount(dirtID) < 200 and
getFloatingItemAmount(dirtID) > 0 and getPlayerCount() <= maxPlayerCount do
PathFindToObj(dirtID, 1)
Sleep(200)
end
end

else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
LogToConsole("Make Dirt Rows Ended")
--**************************************************************
if getPlacedAmount(platformID) >= 52 then
runTrash = true
LogToConsole("Trash Blocks")
else
runTrash = false
LogToConsole("Dont Have Plats Cant Run: Trash Blocks")
end

while runTrash == true do


if getPlayerCount() <= maxPlayerCount then

LogToConsole("Total Objects Floating:


"..getFloatingObjAmountUnobst())
Sleep(200)
if getFloatingObjAmountUnobst() > 0 then

PathFindToObjUnobst()

if isItemToTrash(200)>0 then
trash(200)
end

else
runTrash = false
end

else
SendPacket(2, "action|respawn")
Sleep(5000)
while getPlayerCount() > maxPlayerCount do
Sleep(10000)
end
end
end
--trash(1) --uncomment this if u dont want to trash all the trashable items
in the inventory
LogToConsole("Trash Blocks Ended")
SendPacket(2, "action|respawn")
Sleep(2000)
LogToConsole("Script Ended")

--[[

-- get index
for i, world in ipairs(worlds) do
if world == currentWorld then
currentindex = i
end
Sleep(200)
end
LogToConsole("CurrentWorldIndex: "..currentindex)
LogToConsole("CurrentWorldValue: "..worlds[currentindex])
-- get last element in worlds array
for i,v in pairs(worlds) do
lastWorldIndex = #worlds - 0
Sleep(200)
end
LogToConsole("Last Index In Array: "..lastWorldIndex)
LogToConsole("Last Index In Array: "..worlds[lastWorldIndex])

if worlds[currentindex] == worlds[lastWorldIndex] then


nextWorld = worlds[1]
else
nextWorld = worlds[currentindex+1]
end
LogToConsole("Next World: "..nextWorld)

LogToConsole("Attempting to Join Next World")


Sleep(1000)
SendPacket(3, "action|join_request\nname|"..nextWorld.."\ninvitedWorld|0")
Sleep(5000)
SendPacket(3, "action|join_request\nname|"..nextWorld.."\ninvitedWorld|0") --
just to make sure lmao
Sleep(1000)
currentWorld = nextWorld]]--
end
-- run fix code exeption
while true do
pcall(main)
Sleep(100)
end

You might also like