Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(fs.exists("widget") == false) then
- shell.run("pastebin get 6JsWa9Bj widget")
- term.clear()
- end
- os.loadAPI("widget")
- if not term.isColor() then
- print("Advanced computer required")
- error()
- end
- local radar
- local sides = peripheral.getNames()
- for key,side in pairs(sides) do
- if peripheral.getType(side) == "warpdriveRadar" then
- print("Radar found on " .. side)
- radar = peripheral.wrap(side)
- end
- end
- if radar == nil or radar.isInterfaced() == nil then
- showErrorAndExit("No radar detected")
- end
- local range
- if(fs.exists("range.settings") == false) then
- file = fs.open("range.settings", "w")
- file.write("100")
- file.close()
- end
- if(fs.exists("range.settings")) then
- file = fs.open("range.settings", "r")
- range = tonumber(file.readAll())
- file.close()
- end
- shipName = {}
- shipX = {}
- shipY = {}
- shipZ = {}
- shipMass = {}
- shipRange = {}
- for i=0, 360 do
- shipName[i]=""
- shipX[i]=0
- shipY[i]=0
- shipZ[i]=0
- shipMass[i]=0
- shipRange[i]=0
- end
- function interface(page)
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK2")
- row1 = widget.newRow()
- row1:add(title)
- ship1 = widget.newButton(shipName[0+(page*18)])
- ship2 = widget.newButton(shipName[1+(page*18)])
- ship3 = widget.newButton(shipName[2+(page*18)])
- row2 = widget.newRow()
- row2:add(ship1)
- function ship1.onClick(button)
- shipData(0+page)
- end
- row2:add(ship2)
- function ship2.onClick(button)
- shipData(1+page)
- end
- row2:add(ship3)
- function ship3.onClick(button)
- shipData(2+page)
- end
- ship4 = widget.newButton(shipName[3+(page*18)])
- ship5 = widget.newButton(shipName[4+(page*18)])
- ship6 = widget.newButton(shipName[5+(page*18)])
- row3 = widget.newRow()
- row3:add(ship4)
- function ship4.onClick(button)
- shipData(3+page)
- end
- row3:add(ship5)
- function ship5.onClick(button)
- shipData(4+page)
- end
- row3:add(ship6)
- function ship6.onClick(button)
- shipData(5+page)
- end
- ship7 = widget.newButton(shipName[6+(page*18)])
- ship8 = widget.newButton(shipName[7+(page*18)])
- ship9 = widget.newButton(shipName[8+(page*18)])
- row4 = widget.newRow()
- row4:add(ship7)
- function ship7.onClick(button)
- shipData(6+page)
- end
- row4:add(ship8)
- function ship8.onClick(button)
- shipData(7+page)
- end
- row4:add(ship9)
- function ship9.onClick(button)
- shipData(8+page)
- end
- ship10 = widget.newButton(shipName[9+(page*18)])
- ship11 = widget.newButton(shipName[10+(page*18)])
- ship12 = widget.newButton(shipName[11+(page*18)])
- row5 = widget.newRow()
- row5:add(ship10)
- function ship10.onClick(button)
- shipData(9+page)
- end
- row5:add(ship11)
- function ship11.onClick(button)
- shipData(10+page)
- end
- row5:add(ship12)
- function ship12.onClick(button)
- shipData(11+page)
- end
- ship13 = widget.newButton(shipName[12+(page*18)])
- ship14 = widget.newButton(shipName[13+(page*18)])
- ship15 = widget.newButton(shipName[14+(page*18)])
- row6 = widget.newRow()
- row6:add(ship13)
- function ship13.onClick(button)
- shipData(12+page)
- end
- row6:add(ship14)
- function ship14.onClick(button)
- shipData(13+page)
- end
- row6:add(ship15)
- function ship15.onClick(button)
- shipData(14+page)
- end
- ship16 = widget.newButton(shipName[15+(page*18)])
- ship17 = widget.newButton(shipName[16+(page*18)])
- ship18 = widget.newButton(shipName[17+(page*18)])
- row7 = widget.newRow()
- row7:add(ship16)
- function ship16.onClick(button)
- shipData(15+page)
- end
- row7:add(ship17)
- function ship17.onClick(button)
- shipData(16+page)
- end
- row7:add(ship18)
- function ship18.onClick(button)
- shipData(17+page)
- end
- lastPage = widget.newButton("<--")
- row8 = widget.newRow()
- row8:add(lastPage)
- function lastPage.onClick(button)
- if(page ~= 0) then
- interface(page-1)
- end
- end
- pageNum = widget.newButton("Page "..page+1)
- row8:add(pageNum)
- nextPage = widget.newButton("-->")
- row8:add(nextPage)
- function nextPage.onClick(button)
- if(page ~= 19) then
- interface(page+1)
- end
- end
- row20 = widget.newRow()
- sRange = widget.newButton("Range Settings")
- function sRange.onClick(button)
- rangeSettings()
- end
- startScan = widget.newButton("Scan")
- function startScan.onClick(button)
- scan()
- end
- row20:add(sRange)
- row20:add(startScan)
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- end
- function scan()
- radar.radius(range)
- local success, result = radar.getEnergyRequired()
- if not success then
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK2")
- row1 = widget.newRow()
- row1:add(title)
- row2 = widget.newRow()
- energy = widget.newLabel("Not enough Energy!")
- row3 = widget.newRow()
- row3:add(energy)
- row4 = widget.newRow()
- row5 = widget.newRow()
- row6 = widget.newRow()
- row7 = widget.newRow()
- row8 = widget.newRow()
- okay = widget.newButton("Okay!")
- function okay.onClick(button)
- interface(0)
- end
- row20 = widget.newRow()
- row20:add(okay)
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- end
- local energyRequired = result
- local energyStored, _, energyUnits = radar.getEnergyStatus()
- if energyStored < energyRequired then
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK1")
- row1 = widget.newRow()
- row1:add(title)
- row2 = widget.newRow()
- energy = widget.newLabel("Not enough Energy!")
- row3 = widget.newRow()
- row3:add(energy)
- row4 = widget.newRow()
- row5 = widget.newRow()
- row6 = widget.newRow()
- row7 = widget.newRow()
- row8 = widget.newRow()
- okay = widget.newButton("Okay!")
- function okay.onClick(button)
- interface(0)
- end
- row20 = widget.newRow()
- row20:add(okay)
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- end
- local scanDuration = radar.getScanDuration()
- radar.start()
- os.sleep(0.5)
- print(" Scanning... (" .. scanDuration .. " s)")
- os.sleep(scanDuration)
- local delay = 0
- local count
- repeat
- count = radar.getResultsCount()
- os.sleep(0.1)
- delay = delay + 1
- until (count ~= nil and count ~= -1) or delay > 10
- if count ~= nil and count > 0 then
- term.clear()
- term.setCursorPos(1, 1)
- filtered = 0
- for i=0, count-1 do
- local success, type, name, x, y, z, mass = radar.getResult(i)
- local ssuccess, dimension, sx, sy, sz, system = radar.getGlobalPosition()
- if success then
- if name ~= "" then
- shipName[i-filtered] = name
- shipX[i-filtered] = x
- shipY[i-filtered] = y
- shipZ[i-filtered] = z
- shipMass[i-filtered] = mass
- shipRange[i-filtered] = math.floor(math.sqrt((x-sx)^2+(z-sz)^2))
- else
- filtered = filtered+1
- end
- else
- showError("Error " .. type)
- end
- end
- interface(0)
- end
- end
- function rangeSettings()
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK2")
- row1 = widget.newRow()
- row1:add(title)
- row2 = widget.newRow()
- cRange = widget.newLabel("Current Range: "..range)
- row3 = widget.newRow()
- row3:add(cRange)
- slider = widget.newSlider(1, 40)
- sValue = slider.value
- row4 = widget.newRow()
- row4:add(slider)
- row5 = widget.newRow()
- row6 = widget.newRow()
- row7 = widget.newRow()
- accept = widget.newButton("Accept")
- function accept.onClick(button)
- range = slider.value*50
- if(fs.exists("range.settings")) then
- file = fs.open("range.settings", "w")
- file.write(slider.value*50)
- file.close()
- end
- interface(0)
- end
- decline = widget.newButton("Decline")
- function decline.onClick(button)
- interface(0)
- end
- row8 = widget.newRow()
- row8:add(accept)
- row8:add(decline)
- row20 = widget.newRow()
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- end
- function shipData(num)
- if(shipName[num] ~= "") then
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK2")
- row1 = widget.newRow()
- row1:add(title)
- row2 = widget.newRow()
- sName = widget.newLabel("Name: "..shipName[num])
- row3 = widget.newRow()
- row2:add(sName)
- sX = widget.newLabel("Position X: "..shipX[num])
- row4 = widget.newRow()
- row3:add(sX)
- sY = widget.newLabel("Position Y: "..shipY[num])
- row5 = widget.newRow()
- row4:add(sY)
- sZ = widget.newLabel("Position Z: "..shipZ[num])
- row6 = widget.newRow()
- row5:add(sZ)
- sMass = widget.newLabel("Mass: "..shipMass[num].." tons")
- row7 = widget.newRow()
- row6:add(sMass)
- sRange = widget.newLabel("Distance: "..shipRange[num].."m")
- row8 = widget.newRow()
- row7:add(sRange)
- okay = widget.newButton("Okay!")
- function okay.onClick(button)
- interface(0)
- end
- row20 = widget.newRow()
- row20:add(okay)
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- else
- term.clear()
- title = widget.newLabel("Aegis Scanning System MK2")
- row1 = widget.newRow()
- row1:add(title)
- row2 = widget.newRow()
- noShips = widget.newLabel("No Ship found!")
- row3 = widget.newRow()
- row3:add(noShips)
- row4 = widget.newRow()
- row5 = widget.newRow()
- row6 = widget.newRow()
- row7 = widget.newRow()
- row8 = widget.newRow()
- okay = widget.newButton("Okay!")
- function okay.onClick(button)
- interface(0)
- end
- row20 = widget.newRow()
- row20:add(okay)
- main = widget.newColumn()
- main:add(row1)
- main:add(row2)
- main:add(row3)
- main:add(row4)
- main:add(row5)
- main:add(row6)
- main:add(row7)
- main:add(row8)
- main:add(row20)
- main:run()
- end
- end
- interface(0)
Add Comment
Please, Sign In to add comment