Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --http://pastebin.com/p51K7GEK
- rednet.close("right")
- rednet.open("right")
- function getDir()
- print("EXTREMELY IMPORTANT!")
- print("Enter the direction. . .")
- print("Options")
- print("[ 1 = North, 2 = East, 3 = South, 4 = West ]")
- local continue = true
- while continue == true do
- local input = read()
- if input == "1" then
- continue = false
- return 1
- elseif input == "2" then
- continue = false
- return 2
- elseif input == "3" then
- continue = false
- return 3
- elseif input == "4" then
- continue = false
- return 4
- else
- print("Not valid input!")
- end
- end
- end
- function getTravel()
- print("Enter the height at which drones travel to and from quarry.")
- print("Enter Number >")
- local continue = true
- while continue == true do
- local input = read()
- if tonumber(input) == nil then
- print("Not valid input!")
- elseif tonumber(input) < 0 then
- print("Enter a positive number")
- elseif tonumber(input) > 0 then
- continue = false
- return input
- end
- end
- end
- function getNum()
- print("Enter a number >")
- local continue = true
- while continue == true do
- local input = read()
- if tonumber(input) == nil then
- print("Not valid input!")
- elseif tonumber(input) > 0 or tonumber(input) < 0 then
- continue = false
- return input
- end
- end
- end
- function getDumpLoc()
- local x,y,z = 1
- print("Type Dump Location Coordinates")
- print("X")
- x = getNum()
- print("Y")
- y = getNum()
- print("Z")
- z = getNum()
- return x,y,z
- end
- -- Variables --
- isServerRunning = true
- dir = getDir()
- startDir = dir
- directions ={"north","east","south","west"}
- travelHeight = getTravel()
- hole = 2
- dumpLoc = vector.new(getDumpLoc())
- print("Type Dump Direction")
- dumpDir = getDir()
- startLoc = vector.new(gps.locate())
- loc = vector.new(gps.locate())
- -- END Vars --
- -- Hacked excavate functions --
- local function turnLeft()
- dir=dir-1
- dir=(dir-1)%4
- dir=dir+1
- turtle.turnLeft()
- end
- local function turnRight()
- dir=dir-1
- dir=(dir+1)%4
- dir=dir+1
- turtle.turnRight()
- end
- function refuel(ammount)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- local needed = ammount
- if turtle.getFuelLevel() < needed then
- local fueled = false
- while fueled == false do
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
- turtle.refuel(1)
- end
- if turtle.getFuelLevel() >= needed then
- turtle.select(1)
- return true
- end
- end
- end
- end
- end
- turtle.select(1)
- return false
- end
- return true
- end
- local function unload()
- print( "Unloading items..." )
- local bKeepFuel = true
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount > 0 then
- turtle.select(n)
- local bDrop = true
- if bKeepFuel and turtle.refuel(0) then
- bDrop = false
- bKeepFuel = false
- end
- if bDrop then
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- end
- local function returnSupplies()
- for i=1,20 do
- turtle.up()
- end
- local resume = vector.new(gps.locate())
- local resumeDir = dir
- print( "Returning supplies..." )
- goTo( dumpLoc.x,dumpLoc.y+travelHeight,dumpLoc.z, directions[dumpDir])
- goTo( dumpLoc.x,dumpLoc.y-20,dumpLoc.z, directions[dumpDir])
- local fuelNeeded = 2*(dumpLoc.x+dumpLoc.y+dumpLoc.z) + 1
- if not refuel( fuelNeeded ) then
- unload( true )
- print( "Waiting for fuel" )
- while not refuel( fuelNeeded ) do
- sleep(1)
- end
- else
- unload( true )
- end
- print( "Going back to location..." )
- goTo(resume.x,resume.y,resume.z,directions[resumeDir])
- end
- local function collect()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if bFull then
- print( "No empty slots left." )
- return false
- end
- return true
- end
- local function tryForwards()
- if not refuel(100) then
- print( "Not enough Fuel" )
- returnSupplies()
- end
- while not turtle.forward() do
- if turtle.detect() then
- if turtle.dig() then
- if not collect() then
- returnSupplies()
- end
- else
- return false
- end
- elseif turtle.attack() then
- if not collect() then
- returnSupplies()
- end
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryDown()
- if not refuel(100) then
- print( "Not enough Fuel" )
- returnSupplies()
- end
- while not turtle.down() do
- if turtle.detectDown() then
- if turtle.digDown() then
- if not collect() then
- returnSupplies()
- end
- else
- return false
- end
- elseif turtle.attackDown() then
- if not collect() then
- returnSupplies()
- end
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- function goTo( x, y, z, face)
- local x,y,z = tonumber(x),tonumber(y),tonumber(z)
- loc = vector.new(gps.locate())
- local xPos,depth,zPos = loc.x,loc.y,loc.z
- if not refuel(100) then
- print("Waiting for Fuel. . .")
- end
- while depth < y do
- if turtle.up() then
- depth = depth + 1
- elseif turtle.digUp() or turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- loc = vector.new(gps.locate())
- local xPos,depth,zPos = loc.x,loc.y,loc.z
- if xPos > x then
- while directions[dir] ~= "west" do
- turnLeft()
- end
- while xPos > x do
- if turtle.forward() then
- xPos = xPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif xPos < x then
- while directions[dir] ~= "east" do
- turnLeft()
- end
- while xPos < x do
- if turtle.forward() then
- xPos = xPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- if zPos > z then
- while directions[dir] ~= "north" do
- turnLeft()
- end
- while zPos > z do
- if turtle.forward() then
- zPos = zPos - 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- elseif zPos < z then
- while directions[dir] ~= "south" do
- turnLeft()
- end
- while zPos < z do
- if turtle.forward() then
- zPos = zPos + 1
- elseif turtle.dig() or turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- end
- while depth > y do
- if turtle.down() then
- depth = depth - 1
- elseif turtle.digDown() or turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- while directions[dir] ~= face do
- turnLeft()
- end
- end
- function excavate()
- local alternate = 0
- local done = false
- local size = tonumber(hole)
- while not done do
- for n=1,size do
- for m=1,size-1 do
- if not tryForwards() then
- done = true
- break
- end
- end
- if done then
- break
- end
- if n < size then
- if math.fmod(n + alternate,2) == 0 then
- turnLeft()
- if not tryForwards() then
- done = true
- break
- end
- turnLeft()
- else
- turnRight()
- if not tryForwards() then
- done = true
- break
- end
- turnRight()
- end
- end
- end
- if done then
- break
- end
- if size > 1 then
- if math.fmod(size,2) == 0 then
- turnRight()
- else
- if alternate == 0 then
- turnLeft()
- else
- turnRight()
- end
- alternate = 1 - alternate
- end
- end
- if not tryDown() then
- done = true
- break
- end
- end
- print( "Job's Done" )
- end
- function mine(x,y,z)
- refuel(100)
- goTo(x,y+travelHeight,z,"north")
- goTo(x,y,z,"north")
- excavate()
- goTo(startLoc.x,startLoc.y+travelHeight,startLoc.z, directions[startDir])
- goTo(startLoc.x,startLoc.y,startLoc.z, directions[startDir])
- returnSupplies()
- end
- -- End Movement--
- -- Botnet Functions --
- function establishConnection()
- print("Waiting for server response...")
- local continue = true
- while continue == true do
- rednet.broadcast("Query: CNC ID")
- id,message,dist = rednet.receive(2)
- if message == "ID Sent" then
- continue = false
- return id
- end
- end
- end
- function job()
- while isServerRunning == true do
- rednet.send(establishConnection(),"Query: Job")
- id,message,dist = rednet.receive()
- if message == "Yes" then
- --Receive the hole size
- id,message,diet = rednet.receive()
- hole = message
- -- Receive the X Y Z coordinates
- id,message,dist = rednet.receive()
- x = message
- id,message,dist = rednet.receive()
- y = tonumber(message)
- id,message,dist = rednet.receive()
- z = message
- print("Location X: "..x.." Y: "..y.." Z: "..z)
- rednet.send(id, "Quarry Starting")
- mine(x,y,z)
- end
- end
- end
- --End Botnet--
- -- MAIN --
- job()
- -- End Main --
- -- END of File --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement