Added mandatory radius parameter to radar scripts
Players don't really read the help, hopefully they'll read the error message.
This commit is contained in:
parent
51418e87de
commit
937952f121
4 changed files with 107 additions and 55 deletions
|
@ -4,8 +4,8 @@ if not term.isColor() then
|
|||
end
|
||||
|
||||
function error(message)
|
||||
term.setBackgroundColor(colors.red)
|
||||
term.setTextColor(colors.white)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.red)
|
||||
term.write(message)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
|
@ -13,7 +13,7 @@ function error(message)
|
|||
end
|
||||
|
||||
local radar
|
||||
sides = peripheral.getNames()
|
||||
local sides = peripheral.getNames()
|
||||
for key,side in pairs(sides) do
|
||||
if peripheral.getType(side) == "warpdriveRadar" then
|
||||
print("Radar found on " .. side)
|
||||
|
@ -22,32 +22,32 @@ for key,side in pairs(sides) do
|
|||
end
|
||||
if radar == nil then
|
||||
error("No radar detected")
|
||||
return
|
||||
exit()
|
||||
end
|
||||
|
||||
local argv = { ... }
|
||||
if #argv ~= 1 then
|
||||
error("Usage: ping <scanRadius>")
|
||||
return
|
||||
exit()
|
||||
end
|
||||
|
||||
local radius = tonumber(argv[1])
|
||||
|
||||
if radius < 1 or radius > 9999 then
|
||||
error("Radius must be between 1 and 9999")
|
||||
return
|
||||
exit()
|
||||
end
|
||||
|
||||
energy, energyMax = radar.energy()
|
||||
energyRequired = radar.getEnergyRequired(radius)
|
||||
scanDuration = radar.getScanDuration(radius)
|
||||
if energy < radius * radius then
|
||||
local energy, energyMax = radar.energy()
|
||||
local energyRequired = radar.getEnergyRequired(radius)
|
||||
local scanDuration = radar.getScanDuration(radius)
|
||||
if energy < energyRequired then
|
||||
error("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
|
||||
return
|
||||
exit()
|
||||
end
|
||||
radar.radius(radius)
|
||||
radar.start()
|
||||
sleep(0.5)
|
||||
os.sleep(0.5)
|
||||
|
||||
print("Scanning... (" .. scanDuration .. " s)")
|
||||
os.sleep(scanDuration)
|
||||
|
@ -56,7 +56,7 @@ local delay = 0
|
|||
local count
|
||||
repeat
|
||||
count = radar.getResultsCount()
|
||||
sleep(0.1)
|
||||
os.sleep(0.1)
|
||||
delay = delay + 1
|
||||
until (count ~= nil and count ~= -1) or delay > 10
|
||||
|
||||
|
@ -64,9 +64,9 @@ if count ~= nil and count > 0 then
|
|||
for i=0, count-1 do
|
||||
success, type, name, x, y, z = radar.getResult(i)
|
||||
if success then
|
||||
print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
|
||||
print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
|
||||
else
|
||||
print("Error " .. type)
|
||||
error("Error " .. type)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
radius = 500
|
||||
scale = 50
|
||||
local scale = 50
|
||||
|
||||
if not term.isColor() then
|
||||
print("Advanced computer required")
|
||||
exit()
|
||||
end
|
||||
|
||||
function error(message)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.red)
|
||||
term.write(message)
|
||||
term.setBackgroundColor(colors.black)
|
||||
term.setTextColor(colors.white)
|
||||
print()
|
||||
end
|
||||
|
||||
local radar
|
||||
sides = peripheral.getNames()
|
||||
for key,side in pairs(sides) do
|
||||
|
@ -15,13 +23,19 @@ for key,side in pairs(sides) do
|
|||
end
|
||||
end
|
||||
if radar == nil then
|
||||
term.setBackgroundColor(colors.red)
|
||||
term.setTextColor(colors.white)
|
||||
term.write("No radar detected")
|
||||
return
|
||||
error("No radar detected")
|
||||
exit()
|
||||
end
|
||||
|
||||
w, h = term.getSize()
|
||||
local argv = { ... }
|
||||
if #argv ~= 1 then
|
||||
error("Usage: scan <scanRadius>")
|
||||
exit()
|
||||
end
|
||||
|
||||
local radius = tonumber(argv[1])
|
||||
|
||||
local w, h = term.getSize()
|
||||
|
||||
term.clear()
|
||||
|
||||
|
@ -76,14 +90,14 @@ function scanAndDraw()
|
|||
paintutils.drawLine(hw - 5, hh, hw + 5, hh, colors.red)
|
||||
textOut(hw - 4, hh,"LOW POWER", colors.white, colors.red)
|
||||
paintutils.drawLine(hw - 5, hh + 1, hw + 5, hh + 1, colors.red)
|
||||
sleep(1)
|
||||
os.sleep(1)
|
||||
|
||||
return 0
|
||||
end
|
||||
radar.radius(radius)
|
||||
radar.start()
|
||||
local scanDuration = radar.getScanDuration(radius)
|
||||
sleep(scanDuration)
|
||||
os.sleep(scanDuration)
|
||||
|
||||
redraw()
|
||||
|
||||
|
@ -105,7 +119,7 @@ function redraw()
|
|||
|
||||
paintutils.drawLine(1, 1, w, 1, colors.black)
|
||||
|
||||
textOut((w / 2) - 8, 1, "= Q-Radar v0.2 =", colors.white, colors.black)
|
||||
textOut((w / 2) - 8, 1, "= Q-Radar v0.3 =", colors.white, colors.black)
|
||||
|
||||
textOut(w - 3, 1, "[X]", colors.white, colors.red)
|
||||
|
||||
|
@ -114,9 +128,9 @@ function redraw()
|
|||
textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, colors.white, colors.black)
|
||||
end
|
||||
|
||||
radarX, radarY, radarZ = radar.position()
|
||||
mrun = true
|
||||
while (mrun) do
|
||||
local radarX, radarY, radarZ = radar.position()
|
||||
local continue = true
|
||||
while continue do
|
||||
scanAndDraw()
|
||||
end
|
||||
|
||||
|
|
|
@ -1,30 +1,46 @@
|
|||
local component = require("component")
|
||||
local term = require("term")
|
||||
|
||||
if not term.isAvailable() then
|
||||
computer.beep()
|
||||
os.exit()
|
||||
end
|
||||
|
||||
function error(message)
|
||||
component.gpu.setBackground(0x000000)
|
||||
component.gpu.setForeground(0xFF0000)
|
||||
local xt, yt = term.getCursor()
|
||||
component.gpu.set(xt, yt, message)
|
||||
component.gpu.setBackground(0x000000)
|
||||
component.gpu.setForeground(0xFFFFFF)
|
||||
print("")
|
||||
end
|
||||
|
||||
if not component.isAvailable("warpdriveRadar") then
|
||||
print("No radar detected")
|
||||
return
|
||||
error("No radar detected")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
local radar = component.warpdriveRadar
|
||||
|
||||
local argv = { ... }
|
||||
if #argv ~= 1 then
|
||||
print("Usage: ping <scanRadius>")
|
||||
return
|
||||
error("Usage: ping <scanRadius>")
|
||||
os.exit()
|
||||
end
|
||||
local radius = tonumber(argv[1])
|
||||
|
||||
if radius < 1 or radius > 9999 then
|
||||
print("Radius must be between 1 and 9999")
|
||||
return
|
||||
error("Radius must be between 1 and 9999")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
energy, energyMax = radar.energy()
|
||||
energyRequired = radar.getEnergyRequired(radius)
|
||||
scanDuration = radar.getScanDuration(radius)
|
||||
local energy, energyMax = radar.energy()
|
||||
local energyRequired = radar.getEnergyRequired(radius)
|
||||
local scanDuration = radar.getScanDuration(radius)
|
||||
if energy < energyRequired then
|
||||
print("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
|
||||
return
|
||||
error("Low energy level... (" .. energy .. "/" .. energyRequired .. ")")
|
||||
os.exit()
|
||||
end
|
||||
radar.radius(radius)
|
||||
radar.start()
|
||||
|
@ -34,7 +50,7 @@ print("Scanning... (" .. scanDuration .. " s)")
|
|||
os.sleep(scanDuration)
|
||||
|
||||
local delay = 0
|
||||
local count = nil
|
||||
local count
|
||||
repeat
|
||||
count = radar.getResultsCount()
|
||||
os.sleep(0.1)
|
||||
|
@ -47,11 +63,9 @@ if count ~= nil and count > 0 then
|
|||
if success then
|
||||
print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
|
||||
else
|
||||
print("Error " .. type)
|
||||
error("Error " .. type)
|
||||
end
|
||||
end
|
||||
else
|
||||
print("Nothing was found =(")
|
||||
end
|
||||
|
||||
print("")
|
||||
|
|
|
@ -1,21 +1,44 @@
|
|||
local component = require("component")
|
||||
local computer = require("computer")
|
||||
local term = require("term")
|
||||
radius = 500
|
||||
scale = 50
|
||||
local radius = 500
|
||||
local scale = 50
|
||||
|
||||
if not term.isAvailable() then
|
||||
computer.beep()
|
||||
return
|
||||
os.exit()
|
||||
end
|
||||
if not component.gpu.getDepth() < 4 then
|
||||
print("Tier 2 GPU required")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
function error(message)
|
||||
component.gpu.setBackground(0x000000)
|
||||
component.gpu.setForeground(0xFF0000)
|
||||
local xt, yt = term.getCursor()
|
||||
component.gpu.set(xt, yt, message)
|
||||
component.gpu.setBackground(0x000000)
|
||||
component.gpu.setForeground(0xFFFFFF)
|
||||
print("")
|
||||
end
|
||||
|
||||
if not component.isAvailable("warpdriveRadar") then
|
||||
computer.beep()
|
||||
print("No radar detected")
|
||||
return
|
||||
error("No radar detected")
|
||||
os.exit()
|
||||
end
|
||||
radar = component.warpdriveRadar
|
||||
local radar = component.warpdriveRadar
|
||||
|
||||
w, h = component.gpu.getResolution()
|
||||
local argv = { ... }
|
||||
if #argv ~= 1 then
|
||||
error("Usage: scan <scanRadius>")
|
||||
os.exit()
|
||||
end
|
||||
|
||||
local radius = tonumber(argv[1])
|
||||
|
||||
local w, h = component.gpu.getResolution()
|
||||
|
||||
term.clear()
|
||||
|
||||
|
@ -69,8 +92,8 @@ function scanAndDraw()
|
|||
local energy, energyMax = radar.energy()
|
||||
local energyRequired = radar.getEnergyRequired(radius)
|
||||
if (energy < energyRequired) then
|
||||
hh = math.floor(h / 2)
|
||||
hw = math.floor(w / 2)
|
||||
local hh = math.floor(h / 2)
|
||||
local hw = math.floor(w / 2)
|
||||
|
||||
drawBox(hw - 5, hh - 1, 11, 3, 0xFF0000)
|
||||
textOut(hw - 4, hh, "LOW POWER", 0xFFFFFF, 0xFF0000)
|
||||
|
@ -106,7 +129,7 @@ function redraw()
|
|||
drawBox(1, h, w, 1, 0x000000)
|
||||
drawBox(w, 1, w, h, 0x000000)
|
||||
|
||||
textOut((w / 2) - 8, 1, "= Q-Radar v0.2 =", 0xFFFFFF, 0x000000)
|
||||
textOut((w / 2) - 8, 1, "= Q-Radar v0.3 =", 0xFFFFFF, 0x000000)
|
||||
|
||||
textOut(w - 3, 1, "[X]", 0xFFFFFF, 0xFF0000)
|
||||
|
||||
|
@ -114,9 +137,10 @@ function redraw()
|
|||
textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, 0xFFFFFF, 0x000000)
|
||||
end
|
||||
|
||||
radarX, radarY, radarZ = radar.position()
|
||||
local radarX, radarY, radarZ = radar.position()
|
||||
|
||||
while component.isAvailable("warpdriveRadar") do
|
||||
local continue = true
|
||||
while component.isAvailable("warpdriveRadar") and continue do
|
||||
scanAndDraw()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue