Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- drone = component.proxy(component.list("drone")())
- modem = component.proxy(component.list("modem")())
- leash = component.proxy(component.list("leash")())
- drone.setStatusText("Hi!")
- modem.open(27)
- route = {}
- current = ""
- function add(x, y, z, name, from)
- route[name] = {x=x, y=y, z=z, link = {}}
- if from ~= nil then
- if route[name] == nil or route[from] == nil then
- drone.setStatusText("Error!")
- else
- table.insert(route[name].link, from)
- table.insert(route[from].link, name)
- end
- end
- end
- path = {}
- function search(target, point, prev)
- for key, name in pairs(route[point].link) do
- if name == target then
- table.insert(path, point)
- return true
- end
- end
- for key, name in pairs(route[point].link) do
- if name ~= prev then
- if search(target, name, point) then
- table.insert(path, point)
- return true
- end
- end
- end
- return false
- end
- function to(name)
- path = {}
- table.insert(path, name)
- search(name, current)
- end
- function catch()
- for c = 2, 5 do
- if leash.leash(c) then return true end
- end
- return false
- end
- function drop()
- leash.unleash()
- end
- while true do
- name, _, sender, _, _, message, x, y, z, point, from = computer.pullSignal(1)
- if name == "modem_message" then
- if message == 'add' then
- add(tonumber(x), tonumber(y), tonumber(z), point, from)
- if current == "" then current = point end
- elseif message == 'to' then
- to(x)
- elseif message == 'catch' then
- catch()
- elseif message == 'drop' then
- drop()
- end
- end
- if #path > 0 and drone.getOffset() < 1 then
- drone.move(route[path[#path]].x-route[current].x,
- route[path[#path]].y-route[current].y,
- route[path[#path]].z-route[current].z)
- current = path[#path]
- path[#path] = nil
- end
- end
- modem.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement