Advertisement
MrSnake20_15

Drone

Oct 15th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.41 KB | None | 0 0
  1. local drone = component.proxy(component.list("drone")())
  2. local modem = component.proxy(component.list("modem")())
  3.  
  4. --Vars
  5. local port = 12345
  6. local speed = 1.0
  7. local col = 0x0000FF
  8. local user = false
  9.  
  10.  
  11.  
  12. modem.open(port)
  13.  
  14.  
  15.  
  16.  
  17. local pin = tostring(math.random(10000,99999))
  18. drone.setStatusText(pin)
  19. --Authorization
  20. function authoriz(pin)
  21.     local e = {computer.pullSignal()}
  22.     if e[1] == 'modem_message' and pin == e[6] then
  23.         modem.broadcast(port,"ok")
  24.         return e[3]
  25.     else
  26.         modem.broadcast(port, "No")
  27.     end
  28. end
  29.  
  30. while not user do
  31. user = authoriz(pin)
  32. end
  33.  
  34.  
  35.  
  36. drone.setLightColor(col)
  37. drone.setAcceleration(speed)
  38. modem.broadcast(port, "|Цвет:" .. col .. "|Скорость: " .. speed .. "|Конец сообщения." )
  39.  
  40.  
  41. while true do
  42.     local e = {computer.pullSignal()}
  43.     if e[1] == 'modem_message' and e[3] == user then
  44.         msg = e[6]
  45.         if msg == 'forward' then
  46.             drone.move(1,0,0)
  47.         elseif msg == "back" then
  48.             drone.move(-1,0,0)
  49.         elseif msg == "left" then
  50.             drone.move(0,0,-1)
  51.         elseif msg == 'right' then
  52.             drone.move(0,0,1)
  53.         elseif msg == "down" then
  54.             drone.move(0,-1,0)
  55.         elseif msg == "up" then
  56.             drone.move(0,1,0)
  57.         elseif msg == "speedUP" then
  58.             speed = speed + 0.5
  59.             modem.broadcast(port, "Скорость изменена: " .. speed)
  60.             drone.setAcceleration(speed)
  61.         elseif msg == "speedDOWN" then
  62.             speed = speed - 0.5
  63.             modem.broadcast(port, "Скорость изменена: " .. speed)
  64.             drone.setAcceleration(speed)
  65.         elseif msg == "color" then
  66.             col = math.random(0x0, 0xFFFFFF)
  67.             drone.setLightColor(col)
  68.         elseif msg == "drop" then
  69.             for i = 1, drone.inventorySize() do
  70.                 drone.select(i)
  71.                 drone.drop(0)
  72.             end
  73.         elseif msg == "suck" then
  74.             for i = 1,drone.inventorySize() do
  75.                 for i = 0, 5 do
  76.                     drone.suck(i)
  77.                 end
  78.             end
  79.         elseif msg == "info" then
  80.             modem.broadcast(port, "|Цвет:" .. col .. "|Скорость: " .. speed .. "|Конец сообщения." )
  81.         elseif msg == 'PING' then
  82.             modem.broadcast(port,'PONG')
  83.         end
  84.     end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement