MrSnake20_15

Drone v2

Dec 15th, 2016
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. modem = component.proxy(component.list("modem")())
  2. drone = component.proxy(component.list("drone")())
  3.  
  4. --Vars
  5. local port = 12345
  6. local speed = 1.0
  7. local Ncol = 0xFF0000
  8. local col = 0x0000FF
  9. local user = false
  10. local msg = 'LINKED'
  11.  
  12. modem.open(port)
  13.  
  14. local ans = {['PING']='PONG'}
  15. local pin = tostring(math.random(10000,99999))
  16. drone.setStatusText(pin)
  17. --Authorization
  18. function authoriz(pin)
  19.     local e = {computer.pullSignal()}
  20.     if e[1] == 'modem_message' and pin == e[6] then
  21.         modem.broadcast(port,"ok")
  22.         return e[3]
  23.     else
  24.         modem.broadcast(port, "No")
  25.     end
  26. end
  27. drone.setLightColor(Ncol)
  28. while not user do
  29. user = authoriz(pin)
  30. end
  31. drone.setLightColor(col)
  32. drone.setStatusText(msg)
  33. drone.setAcceleration(speed)
  34. modem.broadcast(port, ans['info'] )
  35.  
  36. while true do
  37.   e = {computer.pullSignal()}
  38.   if e[1]=="modem_message" and e[3] == user then
  39.     if ans[e[6]] then
  40.         modem.broadcast(port,ans[e[6]])
  41.     else
  42.         pcall(load(e[6]))
  43.     end
  44.   end
  45. end
Add Comment
Please, Sign In to add comment