Advertisement
Maxstripe

Radar Scan Broadcast WarpDrive

Jun 16th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local modem = component.modem
  3. modem.open(420)
  4.  
  5. if not component.isAvailable("warpdriveRadar") then
  6.   print("No radar detected")
  7.   return
  8. end
  9.  
  10. local radar = component.warpdriveRadar
  11.  
  12. local argv = { ... }
  13. if #argv ~= 1 then
  14.   print("Usage: ping <scanRadius>")
  15.   return
  16. end
  17. local radius = tonumber(argv[1])
  18.  
  19. if radius < 1 or radius > 9999 then
  20.   print("Radius must be between 1 and 9999")
  21.   return
  22. end
  23.  
  24. energy, energyMax = radar.energy()
  25. energyRequired = radar.getEnergyRequired(radius)
  26. scanDuration = radar.getScanDuration(radius)
  27. if energy < energyRequired then
  28.   print("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
  29.   return
  30. end
  31. radar.radius(radius)
  32. radar.start()
  33. os.sleep(0.5)
  34.  
  35. print("Scanning... (" .. scanDuration .. " s)")
  36. os.sleep(scanDuration)
  37.  
  38. local delay = 0
  39. local count = nil
  40. repeat
  41.   count = radar.getResultsCount()
  42.   os.sleep(0.1)
  43.   delay = delay + 1
  44. until (count ~= nil and count ~= -1) or delay > 10
  45.  
  46. if count ~= nil and count > 0 then
  47.   for i=0, count-1 do
  48.     success, type, name, x, y, z = radar.getResult(i)
  49.     if success then
  50.       modem.broadcast(420, type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
  51.     else
  52.       print("Error " .. type)
  53.     end
  54.   end
  55. else
  56.   print("Nothing was found =(")
  57. end
  58.  
  59. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement