Advertisement
Guest User

awaitCommand

a guest
Aug 6th, 2015
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. rednet.open("left")
  2. local data = {}
  3. local x, y, z
  4. p = peripheral.wrap("right")
  5.  
  6. function waitDone()
  7.    while not p.isActionDone() do
  8.       sleep(1)
  9.    end
  10. end
  11.  
  12. function isDone(data, id)
  13.     if p.getAction() then
  14.         rednet.send(id, p.isActionDone())
  15.     else
  16.         print("No action")
  17.         rednet.send(id, true)
  18.     end
  19. end
  20.  
  21. function sendAction(data, id)
  22.     rednet.send(id, p.getAction())
  23. end
  24.  
  25. function hasItem(data, id)
  26.     if data[1] ~= "" then
  27.         p.clearWhitelistItemFilter()
  28.         p.addWhitelistItemFilter(data[1], 0, false, false, false, false)
  29.     end
  30.     p.setAction("droneConditionItem")
  31.     rednet.send(id, p.evaluateCondition())
  32.     p.clearWhitelistItemFilter()
  33. end
  34.  
  35. function getPressure(data, id)
  36.    rednet.send(id, p.getDronePressure())
  37. end
  38.  
  39. function getPosition(data, id)
  40.     local tempdata = {}
  41.     tempdata[1], tempdata[2], tempdata[3] = p.getDronePosition()
  42.     rednet.send(id, textutils.serialize(tempdata))
  43. end
  44.  
  45. function goto(data)
  46.     p.clearArea()
  47.     p.addArea(data[1], data[2], data[3])
  48.     p.setAction("goto")
  49. end
  50.  
  51. function teleport(data)
  52.     p.clearArea()
  53.     p.addArea(data[1], data[2], data[3])
  54.     p.setAction("teleport")
  55. end
  56.  
  57. function setSpot(data)
  58.    p.addArea(data[1], data[2], data[3])
  59. end
  60.  
  61. function setArea(data)
  62.    p.addArea(data[1], data[2], data[3], data[4], data[5], data[6], data[7])
  63. end
  64.  
  65. function showArea()
  66.     if data[1] then
  67.         p.showArea()
  68.     else
  69.         p.hideArea()
  70.     end
  71. end
  72.  
  73. function clearArea()
  74.     p.clearArea()
  75. end
  76.  
  77. function abortAction()
  78.     p.abortAction()
  79. end
  80.  
  81. function dig()
  82.     p.clearWhitelistItemFilter()
  83.     p.setAction("dig")
  84. end
  85.  
  86. function entityImport()
  87.     p.clearWhitelistText()
  88.     p.setAction("entityImport")
  89. end
  90.  
  91. function entityExport()
  92.     p.clearWhitelistText()
  93.     p.setAction("entityExport")
  94. end
  95.  
  96. function place()
  97.     p.clearWhitelistItemFilter()
  98.     p.setAction("place")
  99. end
  100.  
  101. function attack()
  102.     p.forgetTarget()
  103.     p.setAction("entityAttack")
  104. end
  105.  
  106. function pickup()
  107.     p.clearWhitelistItemFilter()
  108.     p.setAction("pickupItem")
  109. end
  110.  
  111. function inventoryImport(data)
  112.     if data[1] ~= "" then
  113.         p.clearWhitelistItemFilter()
  114.         p.addWhitelistItemFilter(data[1], 0, false, false, false, false)
  115.     else
  116.         p.clearWhitelistItemFilter()
  117.     end
  118.     p.setSides(true, true, true, true, true, true)
  119.     p.setAction("inventoryImport")
  120.     --p.clearWhitelistItemFilter()
  121.     --p.setSides(false, false, false, false, false, false)
  122. end
  123.  
  124. function inventoryExport(data)
  125.     if data[1] ~= "" then
  126.         p.clearWhitelistItemFilter()
  127.         p.addWhitelistItemFilter(data[1], 0, false, false, false, false)
  128.     else
  129.         p.clearWhitelistItemFilter()
  130.     end
  131.     p.setSides(true, true, true, true, true, true)
  132.     p.setAction("inventoryExport")
  133.     --p.clearWhitelistItemFilter()
  134.     --p.setSides(false, false, false, false, false, false)
  135. end
  136.  
  137. function msg()
  138.     data = {}
  139.     id, message, distance, protocol = rednet.receive()
  140.     print(message)
  141.     data = textutils.unserialize(message)
  142.     if data[0] == "goto" then
  143.         goto(data)
  144.     elseif data[0] == "teleport" then
  145.         teleport(data)
  146.     elseif data[0] == "setSpot" then
  147.         setSpot(data)
  148.     elseif data[0] == "setArea" then
  149.         setArea(data)
  150.     elseif data[0] == "dig" then
  151.         dig()
  152.     elseif data[0] == "pickup" then
  153.         pickup()
  154.     elseif data[0] == "clearArea" then
  155.         clearArea()
  156.     elseif data[0] == "showArea" then
  157.         showArea(data)
  158.     elseif data[0] == "inventoryImport" then
  159.         inventoryImport(data)
  160.     elseif data[0] == "inventoryExport" then
  161.         inventoryExport(data)
  162.     elseif data[0] == "isDone" then
  163.         isDone(data, id)
  164.     elseif data[0] == "getAction" then
  165.         sendAction(data, id)
  166.     elseif data[0] == "getPressure" then
  167.         getPressure(data, id)
  168.     elseif data[0] == "getPosition" then
  169.         getPosition(data, id)
  170.     elseif data[0] == "hasItem" then
  171.         hasItem(data, id)
  172.     elseif data[0] == "attack" then
  173.         attack()
  174.     elseif data[0] == "place" then
  175.         place()
  176.     elseif data[0] == "entityImport" then
  177.         entityImport()
  178.     elseif data[0] == "entityExport" then
  179.         entityExport()
  180.     elseif data[0] == "exitPiece" then
  181.         abortAction()
  182.     end
  183.  
  184. end
  185.  
  186. while true do
  187.   msg()
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement