SHARE
TWEET

Totoro Drone Bios

MoonlightOwl Dec 28th, 2014 878 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. drone = component.proxy(component.list("drone")())
  2. modem = component.proxy(component.list("modem")())
  3. leash = component.proxy(component.list("leash")())
  4.  
  5. drone.setStatusText("Hi!")
  6. modem.open(27)
  7.  
  8. route = {}
  9. current = ""
  10.  
  11. function add(x, y, z, name, from)
  12.   route[name] = {x=x, y=y, z=z, link = {}}
  13.   if from ~= nil then
  14.     if route[name] == nil or route[from] == nil then
  15.       drone.setStatusText("Error!")
  16.     else
  17.       table.insert(route[name].link, from)
  18.       table.insert(route[from].link, name)
  19.     end
  20.   end
  21. end
  22.  
  23. path = {}
  24. function search(target, point, prev)
  25.   for key, name in pairs(route[point].link) do
  26.     if name == target then
  27.       table.insert(path, point)
  28.       return true
  29.     end
  30.   end
  31.   for key, name in pairs(route[point].link) do
  32.     if name ~= prev then
  33.       if search(target, name, point) then
  34.         table.insert(path, point)
  35.         return true
  36.       end
  37.     end
  38.   end
  39.   return false
  40. end
  41.  
  42. function to(name)
  43.   path = {}
  44.   table.insert(path, name)
  45.   search(name, current)
  46. end
  47.  
  48. function catch()
  49.   for c = 2, 5 do
  50.     if leash.leash(c) then return true end
  51.   end
  52.   return false
  53. end
  54.  
  55. function drop()
  56.   leash.unleash()
  57. end
  58.  
  59. while true do
  60.   name, _, sender, _, _, message, x, y, z, point, from = computer.pullSignal(1)
  61.   if name == "modem_message" then
  62.     if message == 'add' then
  63.       add(tonumber(x), tonumber(y), tonumber(z), point, from)
  64.       if current == "" then current = point end
  65.     elseif message == 'to' then
  66.       to(x)
  67.     elseif message == 'catch' then
  68.       catch()
  69.     elseif message == 'drop' then
  70.       drop()
  71.     end
  72.   end
  73.   if #path > 0 and drone.getOffset() < 1 then
  74.     drone.move(route[path[#path]].x-route[current].x,
  75.                route[path[#path]].y-route[current].y,
  76.                route[path[#path]].z-route[current].z)
  77.     current = path[#path]
  78.     path[#path] = nil
  79.   end
  80. end
  81.  
  82. modem.close()
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