Darkar25

ECSGrief Reciever 1.0 MBDarkar25

Jun 16th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 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 = 215
  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.     print("ПРОГРАММА ЗАВЕРШЕНА!")
  16. end
  17.  
  18. modem.open(port)
  19. slot=1
  20. robot.select(slot)
  21.  
  22. -------------------------------------------------------------------------------------
  23.  
  24. local commands = {
  25.     forward = robot.forward,
  26.     back = robot.back,
  27.     turnRight = robot.turnRight,
  28.     turnLeft = robot.turnLeft,
  29.     up = robot.up,
  30.     down = robot.down,
  31.     dig = robot.swing,
  32. }
  33.  
  34. local function redstoneControl()
  35.     if not redstone then return end
  36.     if redstoneState then
  37.         for i = 0, 5 do
  38.             redstone.setOutput(i, 0)
  39.         end
  40.         print("Сигнал редстоуна включен со всех сторон робота!")
  41.         redstoneState = false
  42.     else
  43.         for i = 0, 5 do
  44.             redstone.setOutput(i, 15)
  45.         end
  46.         print("Сигнал редстоуна отключен.")
  47.         redstoneState = true
  48.     end
  49. end
  50.  
  51. local function drop()
  52.     robot.drop() -- дропаем предмет вперед
  53.         slot = (slot + 1)%robot.inventorySize()
  54.         robot.select(slot)
  55. end
  56.  
  57. local function prevSlot()
  58.         slot = (slot - 1)%robot.inventorySize()
  59.         robot.select(slot)
  60. end
  61.  
  62. local function nextSlot()
  63.         slot = (slot + 1)%robot.inventorySize()
  64.         robot.select(slot)
  65. end
  66.  
  67. local function firstSlot()
  68.         slot = (1)%robot.inventorySize()
  69.         robot.select(slot)
  70. end
  71.  
  72. local function receive()
  73.     while true do
  74.         local eventData = { event.pull() }
  75.         if eventData[1] == "modem_message" and eventData[4] == port and eventData[6] == keyWord then
  76.             local message = eventData[7]
  77.             if commands[message] then
  78.                 commands[message]()
  79.             else
  80.                 if message == "selfDestroy" then
  81.                     local fs = require("filesystem")
  82.                     for file in fs.list("") do
  83.                         print("Уничтожаю \"" .. file .. "\"")
  84.                         fs.remove(file)
  85.                     end
  86.                     require("term").clear()
  87.                     require("computer").shutdown()
  88.                 elseif message == "use" then
  89.                     robot.use()
  90.                     robot.useUp()
  91.                     robot.useDown()
  92.                 elseif message == "exit" then
  93.                     return
  94.                 elseif message == "redstone" then
  95.                     redstoneControl()
  96.                 elseif message == "suck" then
  97.                     robot.suck()
  98.                     robot.suckDown()
  99.                     robot.suckUp()
  100.                 elseif message == "drop" then
  101.                     drop()
  102.                 elseif message == "prevSlot" then
  103.                     prevSlot()
  104.                 elseif message == "nextSlot" then
  105.                     nextSlot()
  106.                 elseif message == "firstSlot" then
  107.                     firstSlot()
  108.                 elseif message == "digAround" then
  109.                     robot.swing()
  110.                     robot.swingUp()
  111.                     robot.swingDown()
  112.                 end
  113.             end
  114.         end
  115.     end
  116. end
  117.  
  118. local function main()
  119.     print(" ")
  120.     print("Добро пожаловать в программу ECSGrief Receiver v1.0 alpha early access!Modified By Darkar25. Идет ожидание команд с беспроводного устройства.")
  121.     print(" ")
  122.     receive()
  123.     print(" ")
  124.     print("Программа приема сообщений завершена!")
  125. end
  126.  
  127. -------------------------------------------------------------------------------------
  128.  
  129. main()
  130.  
  131. -------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment