Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local brk=false
- local modem=peripheral.wrap("right")
- modem.closeAll()
- modem.open(65534)
- local function checkIfThereAreAnyLeft()
- local e,s,c,r,m,d
- modem.transmit(65534,65534,"PING")
- local id=os.startTimer(2)
- repeat
- e,s,c,r,m,d=os.pullEventRaw()
- until (e=="modem_message" and c==65534) or (e=="timer" and s==id)
- if e=="timer" then return false end
- return true
- end
- while true do
- if not checkIfThereAreAnyLeft() then print("Killed all GPS servers in range.") return end
- local modem=peripheral.wrap("right")
- modem.closeAll()
- modem.open(65534)
- local distanceT={}
- local coordsTable, coords=nil,nil
- local function getData()
- modem.transmit(65534,65534,"PING")
- local eventData
- repeat
- eventData={os.pullEventRaw("modem_message")}
- if eventData[5]==coords or coords==nil then return eventData end
- --print("test")
- until eventData[1]=="terminate"
- return error("Terminated")
- end
- local function getCloser(func)
- while true do
- if turtle.detect() then turtle.dig() end
- if turtle.detectUp() then turtle.digUp() end
- if turtle.detectDown() then turtle.digDown() end
- func()
- local nDat=getData()
- if nDat[6]>distanceT[#distanceT] or nDat[6]==1 then break
- else
- table.insert(distanceT,nDat[6])
- end
- end
- end
- local eventData=getData()
- coords=eventData[5]
- table.insert(distanceT,eventData[6])
- turtle.up()
- local nData=getData()
- table.insert(distanceT,nData[6])
- if distanceT[#distanceT-1]>distanceT[#distanceT] then
- --This means its higher
- getCloser(turtle.up)
- turtle.down()
- turtle.dig()
- else
- --Lower
- getCloser(turtle.down)
- turtle.up()
- turtle.dig()
- end
- local eventData=getData()
- table.insert(distanceT,eventData[6])
- turtle.forward()
- local nData=getData()
- table.insert(distanceT,nData[6])
- if distanceT[#distanceT-1]>distanceT[#distanceT] then
- --Keep going forward
- getCloser(turtle.forward)
- turtle.back()
- else
- --Moonwalk
- turtle.turnRight()
- turtle.turnRight()
- getCloser(turtle.forward)
- turtle.back()
- turtle.turnRight()
- turtle.turnRight()
- end
- --Turn right and do (almost) the same thing
- turtle.turnRight()
- local eventData=getData()
- table.insert(distanceT,eventData[6])
- turtle.forward()
- local nData=getData()
- table.insert(distanceT,nData[6])
- if distanceT[#distanceT-1]>distanceT[#distanceT] then
- --Keep going forward
- getCloser(turtle.forward)
- else
- --Moonwalk
- turtle.turnRight()
- turtle.turnRight()
- getCloser(turtle.forward)
- end
- --We should be right in front of the host.
- peripheral.call("front","shutdown")
- if brk then turtle.dig() end
- print("Killed a GPS host!")
- print("Coords: ",coords)
- print("Tries: ",#distanceT)
- print("Original Distance: ",distanceT[1])
- end
Advertisement
Add Comment
Please, Sign In to add comment