Advertisement
Guest User

startup

a guest
Mar 4th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.94 KB | None | 0 0
  1. ---------------------------------------
  2. -- basic functions for turtle control -
  3. ---------------------------------------
  4. local function gf()  while not turtle.forward()   do end end
  5. local function gb()  while not turtle.back()      do end end
  6. local function gu()  while not turtle.up()        do end end
  7. local function gd()  while not turtle.down()      do end end
  8. local function gl()  while not turtle.turnLeft()  do end end
  9. local function gr()  while not turtle.turnRight() do end end
  10. local function df()  turtle.dig()       end
  11. local function du()  turtle.digUp()     end
  12. local function dd()  turtle.digDown()   end
  13. local function pf()  turtle.place()     end
  14. local function pu()  turtle.placeUp()   end
  15. local function pd()  turtle.placeDown() end
  16. local function sf()  turtle.suck()      end
  17. local function su()  turtle.suckUp()    end
  18. local function sd()  turtle.suckDown()  end
  19. local function Df()  turtle.drop()      end
  20. local function Du()  turtle.dropUp()    end
  21. local function Dd()  turtle.dropDown()  end
  22. local function ss(s) turtle.select(s)   end
  23.  
  24. --function to suck and drop all from chest--
  25. function suckAll()
  26. ss(1) sf() ss(2) sf() ss(3) sf() ss(4) sf() ss(5) sf() ss(6)
  27. sf() ss(7) sf() ss(8) sf() ss(9) sf()
  28. end
  29.  
  30. function dropAll()
  31. ss(1) Df() ss(2) Df() ss(3) Df() ss(4) Df() ss(5) Df() ss(6)
  32. Df() ss(7) Df() ss(8) Df() ss(9) Df()
  33. end
  34.  
  35. --
  36.  
  37.  
  38.  
  39. rednet.open("left")
  40. rednet.broadcast(os.computerID().. " Butler is online!")
  41. function clear() term.clear() term.setCursorPos(1, 1) end
  42. local minFuelAmount = 100
  43.  
  44.  
  45. --return home upon restart--
  46. shell.run("goto", -58,65,-446)
  47.  
  48.  
  49.  
  50. while true do
  51. rednet.open("left")
  52. clear()
  53. if turtle.getFuelLevel() < minFuelAmount then
  54. print("I am out of fuel!")
  55. ss(16)
  56. turtle.refuel(1)
  57. end
  58.  
  59. print( "ID: [", os.computerID(), "]Butler is waiting for insturctions.")
  60. rednet.send(62, "Listening")
  61. local id, msg = rednet.receive(5)
  62.  
  63. if msg == "deposit gold" then
  64. print("Told to deposit gold by ID:["..id.."]")
  65. shell.run("goto", -64,66,-444)
  66. suckAll()
  67. shell.run("goto", -67,67,-447)
  68. dropAll()
  69. shell.run("goto", -58,65,-446)
  70.  
  71. else
  72. if msg == "get gold" then
  73. local id, msg = rednet.receive()
  74. amount = tonumber(msg)
  75. --print("Told to retrieve "..amount.." gold by ID:["..id.."]")
  76. shell.run("goto", -67,67,-447)
  77. turtle.suck(amount)
  78. shell.run("goto", -62,66,-444)
  79. dropAll()
  80. shell.run("goto", -58,65,-446)
  81. turtle.turnRight()
  82. else
  83. if msg == "deposit iron" then
  84. print("Told to deposit iron by ID:["..id.."]")
  85. shell.run("goto", -64,66,-444)
  86. suckAll()
  87. shell.run("goto", -67,66,-447)
  88. dropAll()
  89. shell.run("goto", -58,65,-446)
  90. else
  91. if msg == "get iron" then
  92. local id, msg = rednet.receive()
  93. amount = tonumber(msg)
  94. print("Told to retrieve "..amount.." iron by ID:["..id.."]")
  95. shell.run("goto", -67,66,-447)
  96. turtle.suck(amount)
  97. shell.run("goto", -62,66,-444)
  98. dropAll()
  99. shell.run("goto", -58,65,-446)
  100. turtle.turnRight()
  101. else
  102. if msg == "reboot" then
  103. os.reboot()
  104. else
  105. end
  106. end
  107. end
  108. end
  109. end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement