Advertisement
AlexOfKing

Untitled

May 1st, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. local function proxy(componentType)
  2. local address = component.list(componentType)()
  3. return address and component.proxy(address) or error("No component " .. componentType)
  4. end
  5. local robot, modem, keyboard = proxy("robot"), proxy("modem"), proxy("keyboard")
  6. local a,b = 6,6
  7. local list = {
  8. --w = 0x11, a = 0x1E, s = 0x1F, d = 0x20, lshift = 0x2A, lctrl = 0x1D
  9. --движение робота
  10. ['17.0'] = function(name_key) robot.move(3) end,
  11. ['31.0']= function(name_key) robot.move(2) end,
  12. ['32.0']= function(name_key) robot.turn(true) end,
  13. ['30.0']= function(name_key) robot.turn(false) end,
  14. ['58.0']= function(name_key) robot.move(1) end,
  15. ['29.0']= function(name_key) robot.move(0) end
  16. }
  17. local function sleep(timeout)
  18. local deadline = computer.uptime() + timeout
  19. repeat
  20. computer.pullSignal(deadline - computer.uptime())
  21. until computer.uptime() >= deadline
  22. end
  23. function start()
  24. modem.open(6791)
  25. modem.open(7000)
  26. modem.setWakeMessage('')
  27. modem.setStrength(50000)
  28. checkPort()
  29. end
  30. function checkPort()
  31. if modem.isOpen(6791) and modem.isOpen(7000) then
  32. modem.broadcast(7000, 'Я ожил!')
  33. end
  34. end
  35. function ferma()
  36. while true do
  37. for i = 1, a do
  38. robot.move(3)
  39. robot.use(0)
  40. end
  41. robot.turn(false)
  42. robot.move(3)
  43. robot.use(0)
  44. robot.turn(false)
  45. for l = 1, b do
  46. robot.move(3)
  47. robot.use(0)
  48. end
  49. robot.turn(false)
  50. robot.move(3)
  51. robot.use(0)
  52. robot.turn(false)
  53. end
  54. end
  55.  
  56. start()
  57. while true do
  58. e, _, _, code, _, msg = computer.pullSignal()
  59.  
  60. if e == 'key_down' then
  61. sleep(.2)
  62. name_key = tostring(code)
  63. --modem.broadcast(7000, name_key)
  64. if list[name_key] then
  65. list[name_key]()
  66. end
  67. elseif e == 'modem_message' then
  68. if msg == "StartFarm" then
  69. ferma()
  70. end
  71. end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement