View difference between Paste ID: L6LWdgJ5 and qpgUphE0
SHOW: | | - or go back to the newest paste.
1-
local component = require("component")
1+
local component = require("component")
2-
local modem = component.modem
2+
local modem = component.modem
3-
modem.open(420)
3+
modem.open(420)
4-
4+
5-
if not component.isAvailable("warpdriveRadar") then
5+
if not component.isAvailable("warpdriveRadar") then
6-
  print("No radar detected")
6+
  print("No radar detected")
7-
  return
7+
  return
8-
end
8+
end
9-
9+
10-
local radar = component.warpdriveRadar
10+
local radar = component.warpdriveRadar
11-
11+
12-
local argv = { ... }
12+
local argv = { ... }
13-
if #argv ~= 1 then
13+
if #argv ~= 1 then
14-
  print("Usage: ping <scanRadius>")
14+
  print("Usage: ping <scanRadius>")
15-
  return
15+
  return
16-
end
16+
end
17-
local radius = tonumber(argv[1])
17+
local radius = tonumber(argv[1])
18-
18+
19-
if radius < 1 or radius > 9999 then
19+
if radius < 1 or radius > 9999 then
20-
  print("Radius must be between 1 and 9999")
20+
  print("Radius must be between 1 and 9999")
21-
  return
21+
  return
22-
end
22+
end
23-
23+
24-
energy, energyMax = radar.energy()
24+
energy, energyMax = radar.energy()
25-
energyRequired = radar.getEnergyRequired(radius)
25+
energyRequired = radar.getEnergyRequired(radius)
26-
scanDuration = radar.getScanDuration(radius)
26+
scanDuration = radar.getScanDuration(radius)
27-
if energy < energyRequired then
27+
if energy < energyRequired then
28-
  print("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
28+
  print("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
29-
  return
29+
  return
30-
end
30+
end
31-
radar.radius(radius)
31+
radar.radius(radius)
32-
radar.start()
32+
radar.start()
33-
os.sleep(0.5)
33+
os.sleep(0.5)
34-
34+
35-
print("Scanning... (" .. scanDuration .. " s)")
35+
print("Scanning... (" .. scanDuration .. " s)")
36-
os.sleep(scanDuration)
36+
os.sleep(scanDuration)
37-
37+
38-
local delay = 0
38+
local delay = 0
39-
local count = nil
39+
local count = nil
40-
repeat
40+
repeat
41-
  count = radar.getResultsCount()
41+
  count = radar.getResultsCount()
42-
  os.sleep(0.1)
42+
  os.sleep(0.1)
43-
  delay = delay + 1
43+
  delay = delay + 1
44-
until (count ~= nil and count ~= -1) or delay > 10
44+
until (count ~= nil and count ~= -1) or delay > 10
45-
45+
46-
if count ~= nil and count > 0 then
46+
if count ~= nil and count > 0 then
47-
  for i=0, count-1 do
47+
  for i=0, count-1 do
48-
    success, type, name, x, y, z = radar.getResult(i)
48+
    success, type, name, x, y, z = radar.getResult(i)
49-
    if success then
49+
    if success then
50-
      modem.broadcast(420, type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
50+
      modem.broadcast(420, type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
51-
    else
51+
    else
52-
      print("Error " .. type)
52+
      print("Error " .. type)
53-
    end
53+
    end
54-
  end
54+
  end
55-
else
55+
else
56-
  print("Nothing was found =(")
56+
  print("Nothing was found =(")
57-
end
57+
end
58-
58+
59
print("")