Advertisement
kizeren

Untitled

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