Advertisement
Maxstripe

ping

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