Advertisement
StreamerYT

robot.robot.lua

Nov 5th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. require("term").clear();
  2.  
  3. local cmp=require("component");
  4. local computer=require("computer");
  5. local event=require("event");
  6.  
  7. local robot;
  8. local modem;
  9. local motion,username,userx=0,usery=0,userz=0;
  10.  
  11. local port = 512;local key;
  12.  
  13. print("Добро пожаловать в систему управления роботом.")
  14. print("Разработал EliteClubSessions")
  15. print("Доработал StreamerYT")
  16. print("\nEnter для продолжения");io.read();require("term").clear()
  17.  
  18. print("Компоненты которые поддерживает робот:")
  19. print("[-] - Не установлен [+] - Установлен\n")
  20.  
  21. if cmp.isAvailable("robot") then robot=require("robot");io.write("[+]") else robot=false;io.write("[-]") end;print("Робот")
  22. if cmp.isAvailable("modem") then modem=cmp["modem"];io.write("[+]") else modem=false;io.write("[-]") end;print("Плата беспроводной сети")
  23. if cmp.isAvailable("motion_sensor") then motion=cmp["motion_sensor"];io.write("[+]") else motion=false;print("[-]Датчик движения") end
  24.  
  25. if robot==false then error("Эта программа предназначена для робота!") end
  26. if modem==false then error("Плата беспроводной сети обязательна для работы!") end
  27.  
  28. print("\nEnter для продолжения");io.read();require("term").clear()
  29.  
  30. if motion_sensor!=false then print("Ваш ник:");username=io.read() end
  31. print('Введите секретный ключ');key = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" .. io.read() .. "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
  32.  
  33. require("term").clear()
  34.  
  35. print("Ожидание команд!")
  36.  
  37. modem.open(port)
  38.  
  39. function moveForward()
  40.     robot.forward()
  41. end
  42.  
  43. function moveBack()
  44.     robot.back()
  45. end
  46.  
  47. function moveRight()
  48.     robot.turnRight()
  49.     robot.forward()
  50.     robot.turnLeft()
  51. end
  52.  
  53. function moveLeft()
  54.     robot.turnLeft()
  55.     robot.forward()
  56.     robot.turnRight()
  57. end
  58.  
  59. function moveUp()
  60.     robot.up()
  61. end
  62.  
  63. function moveDown()
  64.     robot.down()
  65. end
  66.  
  67. function moveUser()
  68.     robot.down()
  69. end
  70.  
  71. function moveUserX()
  72.  
  73. end
  74.  
  75. function moveUserY()
  76. --+20
  77. end
  78.  
  79. function moveUserZ()
  80.  
  81. end
  82. -------------------------------------------------------------------------------------
  83. -------------------------------------------------------------------------------------------------------------------------------------
  84. -------------------------------------------------------------------------------------
  85.  
  86. local command = {
  87.     forward = moveForward,
  88.     back = moveBack,
  89.     turnRight = moveRight,
  90.     turnLeft = moveLeft,
  91.     up = moveUp,
  92.     down = moveDown,
  93.     move = moveUser
  94. }
  95.  
  96. local function receive()
  97.     while true do
  98.         local e = { event.pull() }
  99.         if e[1] == "modem_message" and e[4] == port and e[6] == key then
  100.             if command[e[7]] then
  101.                 command[e[7]]()
  102.                 modem.broadcast(port,key,"power",computer.energy()/(computer.maxEnergy()/100))
  103. ----modem.broadcast(                  port ,      key ,   1  ,  2  ,  3  ,   4  ,   5  ,   6  ,   7  )
  104. ----               (e[1] ,e[2] ,e[3] ,e[4] ,e[5] ,e[6] ,e[7] ,e[8] ,e[9] ,e[10] ,e[11] ,e[12] ,e[13] )
  105. ----               (mm_me,mmget,mmput,      blocks                                                   )
  106.             end
  107.         elseif e[1]=="motion" and e[6] == username then
  108.             userx=math.ceil(t[3]);
  109.             usery=math.ceil(t[4])+2;
  110.             userz=math.ceil(t[5]);     
  111.         end
  112.     end
  113. end
  114.  
  115. receive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement