Advertisement
toxicfaceit

Untitled

Jun 14th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. local component = require("component")
  2. local robot = require("robot")
  3. local event = require("event")
  4. local fs = require("filesystem")
  5. local port = 512
  6. local keyWord = "ECSGrief"
  7. local modem
  8. local redstone = component.redstone
  9. local redstoneState = false
  10.  
  11. if component.isAvailable("modem") then
  12. modem = component.modem
  13. else
  14. error("Этой программе требуется беспроводной модем для работы!")
  15. end
  16.  
  17. modem.open(port)
  18.  
  19. -------------------------------------------------------------------------------------
  20.  
  21. local commands = {
  22. forward = robot.forward,
  23. back = robot.back,
  24. turnRight = robot.turnRight,
  25. turnLeft = robot.turnLeft,
  26. up = robot.up,
  27. down = robot.down,
  28. }
  29.  
  30. local function redstoneControl()
  31. if not redstone then return end
  32. if redstoneState then
  33. for i = 0, 5 do
  34. redstone.setOutput(i, 0)
  35. end
  36. print("Сигнал редстоуна включен со всех сторон робота!")
  37. redstoneState = false
  38. else
  39. for i = 0, 5 do
  40. redstone.setOutput(i, 15)
  41. end
  42. print("Сигнал редстоуна отключен.")
  43. redstoneState = true
  44. end
  45. end
  46.  
  47. local function receive()
  48. while true do
  49. local eventData = { event.pull() }
  50. if eventData[1] == "modem_message" and eventData[4] == port and eventData[6] == keyWord then
  51. local message = eventData[7]
  52. if commands[message] then
  53. commands[message]()
  54. else
  55. if message == "selfDestroy" then
  56. local fs = require("filesystem")
  57. for file in fs.list("") do
  58. print("Уничтожаю \"" .. file .. "\"")
  59. fs.remove(file)
  60. end
  61. require("term").clear()
  62. require("computer").shutdown()
  63. elseif message == "use" then
  64. robot.use()
  65. robot.useUp()
  66. robot.useDown()
  67. elseif message == "PIZDA" then
  68. local component = require("component")
  69. local robots = component.robot
  70. local i_c = component.inventory_controller
  71.  
  72. local function finditem(side, name)
  73. local inv, item = i_c.getInventorySize(side)
  74. if inv then
  75. for slot = 1, inv do
  76. item = i_c.getStackInSlot(side, slot)
  77. if item and item.name == name then
  78. return slot
  79. end
  80. end
  81. end
  82. return nil
  83. end
  84.  
  85. local i = finditem(3, "appliedenergistics2:storage_cell_1k")
  86. if i then
  87. robots.select(1)
  88. i_c.suckFromSlot(3, i)
  89. i_c.equip()
  90. end
  91. elseif message == "exit" then
  92. return
  93. elseif message == "redstone" then
  94. redstoneControl()
  95. end
  96. end
  97. end
  98. end
  99. end
  100.  
  101. local function main()
  102. print(" ")
  103. print("Добро пожаловать в программу ECSGrief Receiver v1.0 alpha early access! Идет ожидание команд с беспроводного устройства.")
  104. print(" ")
  105. receive()
  106. print(" ")
  107. print("Программа приема сообщений завершена!")
  108. end
  109.  
  110. -------------------------------------------------------------------------------------
  111.  
  112. main()
  113.  
  114. -------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement