Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local useport = 1351 -- make sure this number is the same as the drone client
- local drone = component.proxy(component.list("drone")())
- local navigation = component.proxy(component.list("navigation")())
- local modem = component.proxy(component.list("modem")())
- modem.open(useport)
- modem.setWakeMessage("_BROADCAST_TARGETS_PS_BOOT")
- local function split(str, chrs)
- local ret = {} string.gsub(str, "[^"..chrs.."]+", function(s) table.insert(ret, s) end) return ret
- end
- local function main()
- computer.beep(500, 1)
- while true do
- local name, receiver, sender, _, _, command = computer.pullSignal()
- if name == "modem_message" then
- local cmd = split(command, " ")
- if cmd[1] == "_BROADCAST_TARGETS_PS_K" then
- modem.send(sender, useport, "target "..drone.name())
- elseif cmd[1] == "list" then
- if cmd[2] == "waypoints" then
- local ways = navigation.findWaypoints(100)
- local ret = ""
- for i, v in ipairs(ways) do
- ret = ret .. tostring(i)..". "..v.label.."\n"
- end
- modem.send(sender, useport, ret)
- end
- elseif cmd[1] == "goto" then
- local wname = cmd[2]
- local ways = navigation.findWaypoints(100)
- for i, v in ipairs(ways) do
- if not (type(v)=="number") then
- if v.label == wname then
- modem.send(sender, useport, "Operation succeed.")
- drone.move(v.position[1], v.position[2], v.position[3])
- break
- end
- end
- end
- elseif cmd[1] == "move" then
- if cmd[2] == "waypoints" then
- local wname = cmd[3]
- local ways = navigation.findWaypoints(100)
- for i, v in ipairs(ways) do
- if not (type(v)=="number") then
- if v.label == wname then
- modem.send(sender, useport, "Operation succeed.")
- drone.move(v.position[1], v.position[2], v.position[3])
- break
- end
- end
- end
- elseif cmd[2] == "relpos" then
- local x = tonumber(cmd[3])
- local y = tonumber(cmd[4])
- local z = tonumber(cmd[5])
- modem.send(sender, useport, "Operation succeed.")
- drone.move(x, y, z)
- end
- end
- for i=1, 30 do
- computer.pullSignal(0.01)
- end
- end
- end
- end
- while true do
- pcall(main)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement