SHARE
TWEET

Pig's Airline (Дрон)

Sharplook Jun 13th, 2015 371 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local drone = component.proxy(component.list("drone")())
  2. local leash = component.proxy(component.list("leash")())
  3. local modem = component.proxy(component.list("modem")())
  4.  
  5. local port = 36
  6.  
  7. modem.open(port)
  8. modem.setWakeMessage("ohshit")
  9.  
  10. local dx = 0
  11. local dy = 0
  12. local dz = 0
  13.  
  14. local way = false
  15. local waytoY = false
  16.  
  17. commands = {
  18.         ["w"] = function() nz = dz + 1 drone.move(dx, dy, nz) end,
  19.         ["a"] = function() nx = dx + 1 drone.move(nx, dy, dz) end,
  20.         ["s"] = function() nz = dz - 1 drone.move(dx, dy, nz) end,
  21.         ["d"] = function() nx = dx - 1 drone.move(nx, dy, dz) end,
  22.         ["e"] = function() ny = dy + 1 drone.move(dx, ny, dz) end,
  23.         ["r"] = function() ny = dy - 1 drone.move(dx, ny, dz) end,
  24.         ["p"] =
  25.         function(toY, x, z, toX, toZ)
  26.                 way = true
  27.                 if dy ~= 0 then toY = toY + dy end
  28.                 drone.move(toX - x, toY, toZ - z)
  29.         end,
  30.         ["v"] = function() computer.shutdown(false) end,
  31.         ["c"] = function() leashPig() end,
  32.         ["z"] = function() leash.unleash() end,
  33.         ["onpos"] = function() computer.beep(1000, 2) commands["reload"]() end,
  34.         ["toY"] = function(toY) if dy ~= 0 then toY = toY + dy end drone.move(dx, toY, dz) waytoY = true end,
  35.         ["reload"] = function() computer.shutdown(true) end
  36. }
  37.  
  38. function leashPig()
  39.         for i = 0, 5 do
  40.                 if leash.leash(i) then return end
  41.         end
  42. end
  43.  
  44. while true do
  45.         event, _, _, _, _, msg, toY, x, z, toX, toZ = computer.pullSignal(1)
  46.         if event == "modem_message" then
  47.                 if msg == "p" then
  48.                         commands["p"](toY, x, z, toX, toZ)
  49.                 elseif msg == "toY" then
  50.                         commands["toY"](toY)
  51.                 elseif commands[msg] then
  52.                         commands[msg]()
  53.                 end
  54.         end
  55.         if waytoY then if drone.getOffset() <= 1 then modem.broadcast(port, "onY") waytoY = false end end
  56.         if way then if drone.getOffset() <= 1 then modem.broadcast(port, "onpos") way = false end end
  57. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top