Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. local sendScore = false
  2. local score = 0
  3.  
  4. s = peripheral.wrap("left")
  5. w = peripheral.wrap("right")
  6.  
  7. w.open(101)
  8.  
  9. function hasItemFrameInFront()
  10.  
  11. items = s.getEntityIds("item_frame")
  12. if #items > 0 then
  13. for i, j in pairs(items) do
  14. data = s.getEntityData(items[i], "item_frame")
  15. pos = data.all().position
  16. if math.floor(pos.x) == 0 and math.floor(pos.y) == 0 and math.floor(pos.z) == 0 then
  17. return true
  18. end
  19. end
  20. end
  21.  
  22. return false
  23. end
  24.  
  25. function receiveData()
  26. while 1 do
  27. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  28. if senderChannel == 101 then
  29. if message == "p" then
  30. local ok, val = pcall(hasItemFrameInFront)
  31. if ok == true and val == false then
  32. sendScore = true
  33. turtle.place()
  34. end
  35. elseif message == "s" then
  36. exit()
  37. end
  38. end
  39. sleep(0.1)
  40. end
  41. end
  42.  
  43. function sendData()
  44. while 1 do
  45. if sendScore then
  46. w.transmit(101,101,"+")
  47. sendScore = false
  48. end
  49. sleep(0.1)
  50. end
  51. end
  52.  
  53.  
  54. parallel.waitForAll(receiveData, sendData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement