Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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 hasItemFramInFront()
  10.  
  11. items = s.getEntityIds("item_frame")
  12. if #items > 0 then
  13. for i, j in 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. if hasItemFramInFront() == false then
  31. sendScore = true
  32. turtle.place()
  33. end
  34. elseif message == "s" then
  35. exit()
  36. end
  37. end
  38. sleep(0.1)
  39. end
  40. end
  41.  
  42. function sendData()
  43. while 1 do
  44. if sendScore then
  45. w.transmit(101,101,"+")
  46. sendScore = false
  47. end
  48. sleep(0.1)
  49. end
  50. end
  51.  
  52.  
  53. parallel.waitForAll(receiveData, sendData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement