Advertisement
serafim7

Universal drone remote control (drone) [OpenComputers]

Jun 17th, 2017
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. --Universal drone remote control(drone) version: 1.0 by Litvinov
  2. --http://computercraft.ru/topic/1950-universal-drone-remote-control-distantcionnoe-upravlenie-dronom/
  3. --https://pastebin.com/G6JJfxfh
  4. local d = component.proxy(component.list('drone')())
  5. local m = component.proxy(component.list('modem')())
  6. local leash = component.proxy(component.list('leash')())
  7.  
  8. local receivePort = 1010
  9. local sendPort = 1011
  10.  
  11. m.open(receivePort)
  12. m.setWakeMessage('droneSwitch')
  13. d.move(0, -d.getOffset(), 0)
  14.  
  15. local function send(...)
  16.   m.broadcast(sendPort, ...)
  17. end
  18.  
  19. local function catch()
  20.   for i = 0, 5 do
  21.     if leash.leash(i) then
  22.       return
  23.     end
  24.   end
  25. end
  26.  
  27. local function suck_dropAll(side, action)
  28.   for i = 1, d.inventorySize() do
  29.     d.select(i)
  30.     if action == 'suck' then
  31.       d.suck(side)
  32.     elseif action == 'drop' then
  33.       d.drop(side)
  34.     end
  35.   end
  36.   send('cSelectSlot', d.select(num), d.count())
  37. end
  38.  
  39. local commands = {
  40.   ['move'] = function(x, y, z) d.move(x, y, z) end,
  41.   ['swing'] = function(side) d.swing(side) end,
  42.   ['place'] = function(side) d.place(side) end,
  43.   ['suck'] = function(side) d.suck(side) end,
  44.   ['drop'] = function(side) d.drop(side) end,
  45.   ['suckAll'] = function(side) suck_dropAll(side, 'suck') end,
  46.   ['dropAll'] = function(side) suck_dropAll(side, 'drop') end,
  47.   ['leash'] = function() catch() end,
  48.   ['unleash'] = function() leash.unleash() end,
  49.   ['select'] = function(num) if num <= d.inventorySize() then send('cSelectSlot', d.select(num), d.count()) end end,
  50.   ['getPing'] = function() send('ping') end,
  51.   ['changeColor'] = function(color) d.setLightColor(color) end,
  52.   ['setAcceleration'] = function(value) d.setAcceleration(value) send('cAcceleration', d.getAcceleration()) end,
  53.   ['getAcceleration'] = function() send('cAcceleration', d.getAcceleration()) end,
  54.   ['droneSwitch'] = function() computer.shutdown() end
  55. }
  56.  
  57. while true do
  58.   local event = {computer.pullSignal()}
  59.   if event[1] == 'modem_message' then
  60.     commands[event[6]](event[7], event[8], event[9])
  61.   end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement