Advertisement
Romanok2805

Untitled

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