Advertisement
BigSHinyToys

[Computer Craft] Turtle GPS builder

Jan 1st, 2013
4,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. if not turtle then
  2.     print("Error Not turtle")
  3.     return
  4. end
  5.  
  6. local mov = {}
  7.  
  8. mov.forward = function ()
  9.     while not turtle.forward() do
  10.         sleep(1)
  11.     end
  12.     return true
  13. end
  14. mov.back = function ()
  15.     while not turtle.back() do
  16.         sleep(1)
  17.     end
  18.     return true
  19. end
  20. mov.up = function ()
  21.     while not turtle.up() do
  22.         sleep(1)
  23.     end
  24.     return true
  25. end
  26. mov.down = function ()
  27.     while not turtle.down() do
  28.         sleep(1)
  29.     end
  30.     return true
  31. end
  32. mov.place = function ()
  33.     while not turtle.place() do
  34.         sleep(1)
  35.     end
  36. end
  37.  
  38. local base = nil
  39.  
  40. if turtle.getFuelLevel() < 600 then
  41.     print("600 fuel is required")
  42.     return
  43. else
  44.     if fs.exists("custom") then
  45.         print("custom program detected")
  46.         print("please Enter base Station number")
  47.         local failFlag = false
  48.         repeat
  49.             if failFlag then
  50.                 print("Error Not number")
  51.                 print("try again")
  52.             end
  53.             write(" > ")
  54.             base = tonumber(read())
  55.             failFlag = true
  56.         until type(base) == "number"
  57.     end
  58.     print("Please Place 4 computers in slot one")
  59.     print("4 modems in slot two")
  60.     print("if mineing turtle then")
  61.     print("1 disk drive in slot three")
  62.     print("if not mineing then")
  63.     print("4 disk drive in slot three")
  64.     print("blank floopy disk in slot four")
  65.     print("press Enter key to continue")
  66.     while true do
  67.         local event , key = os.pullEvent("key")
  68.         if key == 28 then break end
  69.     end
  70.     print("Launching")
  71. end
  72. local set = {}
  73. set[1] = {x = 0,y = 3,z = 254}
  74. set[2] = {x = 3,y = 0,z = 251}
  75. set[3] = {x = 0,y = -3,z = 254}
  76. set[4] = {x = -3,y = 0,z = 251}
  77.  
  78. while turtle.up() do -- sends it up till it hits max hight
  79. end
  80.  
  81. for a = 1,4 do
  82.     for i = 1,2 do
  83.         mov.forward()
  84.     end
  85.     turtle.select(1)
  86.     mov.place()
  87.     mov.back()
  88.     turtle.select(2)
  89.     mov.place()
  90.     mov.down()
  91.     mov.forward()
  92.     turtle.select(3)
  93.     mov.place()
  94.     turtle.select(4)
  95.     turtle.drop()
  96.     -- make disk custom
  97.     fs.delete("disk/startup")
  98.     file = fs.open("disk/startup","w")
  99.     file.write([[
  100. fs.copy("disk/install","startup")
  101. fs.delete("disk/startup")
  102. if fs.exists("disk/custom") then
  103.     fs.copy("disk/custom","custom")
  104.     fs.delete("disk/custom")
  105. end
  106. print("sleep in 10")
  107. sleep(10)
  108. os.reboot()
  109. ]])
  110.     file.close()
  111.     if fs.exists("custom") then
  112.         fs.copy("custom","disk/custom")
  113.     end
  114.         file = fs.open("disk/install","w")
  115.         file.write([[
  116. if fs.exists("custom") then
  117.     shell.run("custom","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..","..(base or "nil")..[[)
  118. else
  119.     shell.run("gps","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..[[)
  120. end
  121. ]])
  122.         file.close()
  123.     -- end make disk custom
  124.     turtle.turnLeft()
  125.     mov.forward()
  126.     mov.up()
  127.     turtle.turnRight()
  128.     mov.forward()
  129.     turtle.turnRight()
  130.     peripheral.call("front","turnOn")
  131.     mov.down()
  132.     turtle.suck()
  133.     turtle.select(3)
  134.     turtle.dig()
  135.     mov.up()
  136.     -- reboot would be here
  137.     turtle.turnRight()
  138.     for i = 1,3 do
  139.         mov.forward()
  140.     end
  141.     turtle.turnLeft()
  142.     mov.forward()
  143.     if a == 1 or a == 3 then
  144.         for i = 1,3 do
  145.         mov.down()
  146.         end
  147.     elseif a == 2 or a == 4 then
  148.         for i = 1,3 do
  149.         mov.up()
  150.         end
  151.     end
  152. end
  153.  
  154. while turtle.down() do -- brings turtle down
  155. end
  156. turtle = tMove
  157. print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement