Advertisement
Wojbie

Swarminer Turtle Recovery

Oct 29th, 2013
3,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --Work in Progres - turtle recovery program
  2.  
  3. local function yn(A)
  4.     if not A then return false end
  5.     local key
  6.     write(A.."[y/n]:")
  7.     while true do
  8.         _,key = os.pullEvent("key")
  9.         if key==21 then write(keys.getName(key).."\n") sleep(0.01) return true
  10.         elseif key==49 then write(keys.getName(key).."\n") sleep(0.01) return false
  11.         end
  12.     end
  13. end
  14.  
  15. local function getpos()
  16.         local temp={}
  17.         while true do
  18.                 print("Enter data from F3 Screen")
  19.                 write("Please enter x coordinate:") temp.x=tonumber(read())
  20.                 write("Please enter y coordinate:") temp.y=tonumber(read())
  21.                 write("Please enter z coordinate:") temp.z=tonumber(read())
  22.                 if temp.x and temp.y and temp.z then
  23.                         print("x:"..temp.x.." y:"..temp.y.." z:"..temp.z)
  24.                         if yn("Are thise correct?") then break end
  25.                 end
  26.         end
  27.         return temp
  28. end
  29.  
  30. local channel=15151
  31. modem=false
  32. for _,i in pairs(redstone.getSides()) do
  33.     if peripheral.isPresent(i) then
  34.         if peripheral.getType(i)=="modem" then
  35.             if peripheral.call(i,"isWireless") then
  36.             modem=peripheral.wrap(i)
  37.             --modem.open(channel)
  38.             break
  39.             end
  40.         end
  41.     end
  42. end
  43. local function transmit(...)
  44. if modem then modem.transmit(...) end
  45. end
  46.  
  47. if turtle.getFuelLevel()<=2 then return false end
  48. --print("Give me coords in front of me")
  49. turtle.forward()
  50. local pos={gps.locate(2,true)}
  51. if pos[1] then
  52.     print("x:"..pos[1].." y:"..pos[2].." z:"..pos[3])
  53.     if not yn("Are thise correct?") then return false end
  54.     pos={x=pos[1],y=pos[2],z=pos[3]}
  55. else print("No gps online - Enter Scanner Position manualy") pos=getpos() end
  56. turtle.back()
  57. transmit(channel,4,"Pause") sleep(1) transmit(channel,6,textutils.serialize(pos))
  58. print("Recall in progress")
  59.  
  60. turtle.select(1)
  61. turtle.dropDown()
  62.  
  63. while true do
  64. if turtle.detect() then
  65. while turtle.suck() do turtle.dropDown() end
  66.     turtle.dig()
  67.     turtle.dropDown()
  68. else
  69.     sleep(1)
  70. end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement