Hannesaronsson

Storage drone

Jan 9th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. cords = " "
  2. inv = peripheral.wrap("left")
  3. function refuel()
  4.  if turtle.getFuelLevel() < 300 then                
  5.  shell.run("goto 2458 233 87")
  6.  sleep(60)
  7.  returnHome(0)
  8.  end
  9. end
  10.  
  11. function returnHome(units, state)
  12.  shell.run("goto 2457 233 87")
  13. if state == 0 then
  14. print(units)
  15. print(state)
  16.  for i=1, units do
  17.   turtle.select(i)
  18.   turtle.dropDown()
  19.  end
  20. else
  21.   turtle.select(1)
  22.   turtle.dropDown()
  23. end
  24. end
  25.  
  26. function collect(x, z, y, units, stack)
  27.  turtle.select(1)
  28.  refuel()
  29.  shell.run("goto".." ".. x.." ".. y.." ".." ".. z)
  30.  if stack == 0 then
  31.   for i=1, units do
  32.   turtle.suckUp()
  33.   end
  34.  else
  35.   inv.suckSneakyUp(0,units)
  36. end
  37.  turtle.select(1)
  38.  inv.dropSneakyUp(1,1)
  39.  returnHome(units, stack)
  40. end
  41.  
  42.  
  43. rednet.open("right")
  44. while true do
  45.  rednet.send(912, "done")
  46.  senderId, cords, distance = rednet.receive(5) -- Wait for a message
  47.  print(cords)
  48.   if senderId == 912 then
  49.   rednet.send(912, "working")
  50.   cords = textutils.unserialize(cords)
  51.   if tonumber(cords[6]) < 0 then
  52.    cords[6] = tonumber(cords[6]) /-1
  53.    unitStack = 1
  54.   else
  55.    unitStack = 0
  56.   end
  57.    collect(cords[1], cords[2], cords[3], cords[6], unitStack)
  58. end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment