Advertisement
serafim7

Remoute Control Robot [OpenComputers]

Jun 10th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. --[[ OpenComputers Удалённое управление роботом by serafim
  2.      http://pastebin.com/g8NCXBeY
  3. с защитой от угона при помощи авторизации
  4. программа для робота !
  5.  
  6. требования:
  7. робот первого уровня,
  8. карта wi-fi, контроллер редстоуна
  9.  
  10. использование:
  11. запустить, на экране появится pin код,
  12. ввести на планшете.
  13. ]]--
  14.  
  15. local comp = require("component")
  16. local event = require("event")
  17. local sides = require("sides")
  18. local user,redstate = false,false
  19. local pin = tostring(math.random(100,999))
  20. local port = 123
  21.  
  22. if not comp.isAvailable("robot") then
  23.   print("только роботы могут использовать эту программу")
  24.   os.exit()
  25. end
  26. local r = require("robot")
  27.  
  28. if comp.isAvailable("modem") then
  29.   modem = comp.modem
  30. else
  31.   print("Нет модема !")
  32.   os.exit()
  33. end
  34. modem.open(port)
  35.  
  36. if comp.isAvailable("redstone") then
  37.   rs = comp.redstone
  38.   red = true
  39. end
  40.  
  41. local actions = {
  42. [17] = r.forward,
  43. [31] = r.back,
  44. [32] = r.turnRight,
  45. [30] = r.turnLeft,
  46. [57] = r.up,
  47. [42] = r.down,
  48. [18] = r.swing,
  49. [33] = r.use,
  50. [19] = r.place,
  51. [45] = r.turnAround
  52. }
  53.  
  54. function authoriz(pin)
  55.   local _,_,kard,_,_,key = event.pull("modem_message")
  56.   if pin == key then
  57.     modem.broadcast(port,"true")
  58.     return kard
  59.   else
  60.    modem.broadcast(port,"false")
  61.   end
  62. end
  63. r.setLightColor(0xFF0000)
  64. print("pin: "..pin)
  65. while not user do
  66.   user = authoriz(pin)
  67. end
  68. r.setLightColor(0x0000FF)
  69. print("Авторизован")
  70.  
  71. while true do
  72.   local _,_,kard,_,_,key = event.pull("modem_message")
  73.   if kard == user and actions[key] then actions[key]() end
  74.   if key == 34 then
  75.     for i = 1, r.inventorySize() do if r.count(i) > 0 then r.select(i) r.drop() end end r.select(1)
  76.   elseif key == 20 then
  77.     r.select(1) for i = 1, r.inventorySize() do r.suck() end
  78.   elseif key == 46 then
  79.     local col = math.random(0x0, 0xFFFFFF) r.setLightColor(col)
  80.   elseif key == 47 then
  81.     if red then
  82.       redstate = not redstate
  83.       if redstate then rs.setOutput(sides.front, 15) else rs.setOutput(sides.front, 0) end
  84.     end
  85.   end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement