Advertisement
Bmorr

satellite.lua

Dec 20th, 2020 (edited)
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.66 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. local uY, count, tX, tY, tZ, face = 1, 1, tArgs[1], tArgs[2] - 1, tArgs[3], tArgs[4]
  4.  
  5. function faceSouth()
  6.   tZ = tZ + 1
  7.   if face == 'N' then
  8.         turtle.turnLeft()
  9.         turtle.turnLeft()
  10.   elseif face == 'W' then
  11.         turtle.turnLeft()
  12.   elseif face == 'E' then
  13.         turtle.turnRight()
  14.   else
  15.         faceUsage()
  16.         return false
  17.   end
  18.   goToSky()
  19. end
  20.  
  21. function goToSky()
  22.   while turtle.up() do
  23.          uY = uY + 1
  24.   end
  25.   tY = tY + uY
  26.   placeComputer()
  27. end
  28.  
  29. function goToGround()
  30.   while turtle.down() do
  31.   end
  32. end
  33.  
  34. function placeComputer()
  35.   turtle.select(1)
  36.   turtle.place()
  37.   turtle.back()
  38.   turtle.select(2)
  39.   turtle.place()
  40.   turtle.down()
  41.   turtle.forward()
  42.   turtle.select(4)
  43.   turtle.place()
  44.   turtle.select(3)
  45.   turtle.drop()
  46.   setComputer()
  47. end
  48.  
  49. function goToSouthPos()
  50.   turtle.turnLeft()
  51.   turtle.turnLeft()
  52.   for i = 1, 4 do
  53.         turtle.forward()
  54.         tZ = tZ + 1
  55.   end
  56.   tZ = tZ + 2 -- + 2 to compensate for turtle pos before turning left and the pos the computer is placed
  57.   placeComputer()
  58. end
  59.  
  60. function goToEastPos()
  61.   turtle.down()
  62.   turtle.down()
  63.   turtle.down()
  64.   tY = tY - 3
  65.   for i = 1, 4 do
  66.         turtle.forward()
  67.   end
  68.   tZ = tZ - 3
  69.   turtle.turnRight()
  70.   turtle.forward()
  71.   turtle.forward()
  72.   tX = tX + 3
  73.   placeComputer()
  74. end
  75.  
  76. function goToWestPos()
  77.   turtle.down()
  78.   for i = 1, 6 do
  79.         turtle.forward()
  80.         tX = tX - 1
  81.   end
  82.   turtle.up()
  83.   placeComputer()
  84. end
  85.  
  86. function setComputer()
  87.   turtle.down()
  88.   turtle.forward()
  89.   turtle.forward()
  90.   turtle.turnLeft()
  91.   turtle.turnLeft()
  92.   turtle.up()
  93.   setUpDisk(tX,tY,tZ)
  94.   turtle.up()
  95.   peripheral.call("front", "turnOn")
  96.   turtle.down()
  97.   turtle.suck()
  98.   turtle.dig()
  99.   turtle.up()
  100.   sleep(2)
  101.   peripheral.call("front", "reboot")
  102.   if count == 1 then
  103.         count = count + 1
  104.         goToSouthPos()
  105.  
  106.   elseif count == 2 then
  107.         count = count + 1
  108.         goToEastPos()
  109.  
  110.   elseif count == 3 then
  111.         count = count + 1
  112.         goToWestPos()
  113.   elseif count == 4 then
  114.         goToGround()
  115.   end
  116. end
  117.  
  118. function setUpDisk(x,y,z)
  119.   print("Computer number "..count)
  120.   print("<x>"..x.." <y>"..y.." <z>"..z)
  121.   local st = fs.open("disk/startup", "w")
  122.   local gps_run = "shell.run('gps','host',"..x..","..y..","..z..")"
  123.   st.writeLine("local startup = fs.open('startup', 'w')")
  124.   st.writeLine("startup.writeLine(\""..gps_run.."\")")
  125.   st.writeLine("startup.close()")
  126.   st.close()
  127. end
  128.  
  129. function usage()
  130.   print("usage:")
  131.   print("setup_gps <x> <y> <z> <f>")
  132. end
  133.  
  134. function placingSetUp()
  135.   print("---------------------------------------")
  136.   print("Please place items in the following order:")
  137.   print("Slot 1: 4x computers")
  138.   print("Slot 2: 4x wirelesse modems")
  139.   print("Slot 3: 1x floopy disk")
  140.   print("Slot 4: 1x disk drive")
  141.   print("---------------------------------------")
  142. end
  143.  
  144. function checkItems()
  145.   if turtle.getItemCount(1) == 4
  146.   and turtle.getItemCount(2) == 4
  147.   and turtle.getItemCount(3) == 1
  148.   and turtle.getItemCount(4) == 1
  149.   then
  150.         return true
  151.   else
  152.         placingSetUp()
  153.         return false
  154.   end
  155. end
  156.  
  157. function checkTurtleType()
  158.  
  159.   turtle.select(4)
  160.   turtle.place()
  161.   if turtle.dig() then
  162.         return true
  163.   else
  164.         print("You must use a mining turtle in order to run this program")
  165.         return false
  166.   end
  167. end
  168.  
  169. function faceUsage()
  170.   print("-----------------")
  171.   print("face parameter:")
  172.   print("S if facing south")
  173.   print("N if facing north")
  174.   print("E if facing east")
  175.   print("W if facing west")
  176.   print("-----------------")
  177.  
  178.   return false
  179. end
  180.  
  181. function checkArguments()
  182.   if #tArgs ~= 4 then
  183.         usage()
  184.         return false
  185.   elseif type(tonumber(tX)) ~= "number" then
  186.         print("<x> has to be a number")
  187.         return false
  188.   elseif type(tonumber(tY)) ~= "number" then
  189.         print("<y> has to be a number")
  190.         return false
  191.   elseif type(tonumber(tZ)) ~= "number" then
  192.         print("<z> has to be a number")
  193.         return false
  194.   else
  195.         return true
  196.   end
  197. end
  198.  
  199. function checkFuel()
  200.   if turtle.getFuelLevel() < 1000 then
  201.         print("Not enough fuel")
  202.         print("Fuel level has to be greater than 1000")
  203.         return false
  204.   else
  205.         return true
  206.   end
  207. end
  208.  
  209. function initialChecking()
  210.   if tX == "help" then
  211.         usage()
  212.         placingSetUp()
  213.         return false
  214.   elseif checkTurtleType() == false  
  215.   or checkArguments() == false
  216.   or checkFuel() == false
  217.   or checkItems() == false
  218.   then
  219.         return false
  220.   else
  221.         return true
  222.   end
  223. end
  224.  
  225. if initialChecking() == false then
  226.   return false
  227. else
  228.   faceSouth()
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement