Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- the webhook url for the requests
- local discordUri = "https://discordapp.com/api/webhooks/9897675164221440/bVNkDOVeMt0XruW3UBpLOys6ycH-E1ML9SoWwGrFXaTL_vFtpYxjj27quln6actJSEOr"
- -- Node ID
- nodeid = 1
- -- waittime between radar scans
- local intervalSec = 15
- -- range in blocks
- local radarRadius = 1000
- -- if something is closer than that then a warning sign will be prepended in discord
- local safetyDist = 400
- term.clear()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,2)
- print(" _/ _/ _/_/_/_/ _/_/_/ _/_/_/ ")
- print(" _/ _/ _/ _/ _/ _/ ")
- print(" _/_/_/_/ _/_/_/ _/ _/_/ _/_/_/ ")
- print(" _/ _/ _/ _/ _/ _/ _/ ")
- print(" _/ _/ _/ _/_/_/ _/ _/ ")
- print(" ")
- term.setTextColor( colors.red )
- print(" By InfiniteBlock.")
- term.setTextColor( colors.green )
- print(" Node ID: " .. nodeid .. " Online")
- term.setTextColor( colors.white )
- sleep(4)
- local radar = peripheral.find("warpdriveRadar")
- if radar == nil then
- error("No radar could be found!")
- end
- function tableHasValue(table, v)
- for i=1,#table do
- if table[i] == v then
- return true
- end
- end
- return false
- end
- function getDst(x1,x2,y1,y2,z1,z2)
- local dx = x1-x2
- local dy = y1-y2
- local dz = z1-z2
- return math.floor(math.sqrt(dx*dx+dy*dy+dz*dz))
- end
- function getRadarResults()
- local dur = radar.getScanDuration(radarRadius)
- local first = true
- while true do
- local currPwr, maxPwr, unit = radar.getEnergyStatus()
- local _,reqPwr = radar.getEnergyRequired(radarRadius)
- if reqPwr <= currPwr then
- break
- else
- if first then
- first = false
- else
- local _,line=term.getCursorPos()
- term.setCursorPos(1,line-1)
- term.clearLine()
- end
- term.setCursorPos(1,11)
- term.clearLine()
- print("Waiting for energy.. ("..currPwr.."/"..reqPwr..")")
- os.sleep(1)
- end
- end
- term.setCursorPos(1,11)
- term.clearLine()
- print("Scanning radius of "..radarRadius.." blocks. This will take "..tonumber(dur).."s.")
- radar.start()
- os.sleep(dur + 0.1) -- sleep for duration plus buffer
- radar.getResultsCount()
- local cnt = radar.getResultsCount()
- local ret = {}
- local dsts = {}
- local alreadySeen = {}
- local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition()
- for i=1,cnt do
- local result={radar.getResult(i-1)}
- -- identifier:
- local tv = result[2]..":"..result[3]..":"..result[4].."-"..result[5].."-"..result[6]..":"..result[7]
- if result[1] == true then -- [1] = successful or not
- table.insert(ret,result)
- -- alreadySeen[#alreadySeen+1]=tv
- end
- end
- table.sort(ret, function(a,b) return getDst(rPosX,a[4],rPosY,a[5],rPosZ,a[6]) < getDst(rPosX,b[4],rPosY,b[5],rPosZ,b[6]) end)
- return ret
- end -- func
- local oldShips = {}
- local goodChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"--,;:_-#'+~*?!§$%&/()={[]}^|<>"
- radar.radius(radarRadius)
- radar.enable()
- while true do
- local res = getRadarResults()
- -- shell.run("clear")
- -- print("==== Ship Scanner ====")
- local str = ""
- local newShips = {}
- local firstMsgPart = true
- -- print("Currently tracked ships:")
- local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition()
- local rlPosX,rlPosY,rlPosZ = radar.getLocalPosition()
- -- print("Our pos: global xyz: ("..rPosX.." "..rPosY.." "..rPosZ..") local xyz: ("..rlPosX.." "..rlPosY.." "..rlPosZ..")")
- -- rlPosX = 0
- -- rlPosY = 0
- -- rlPosZ = 0
- --print("ress:"..#res)
- os.sleep(1)
- for
- i=1,#res do
- local success, type, name, x, y, z, mass = table.unpack(res[i])
- if name ~= "" then
- local cdist = getDst(rPosX,x,rPosY,y,rPosZ,z)
- local so = ""
- if cdist < safetyDist then so = so .. " :warning: " end
- so = so.. "**"..name.."** ["..type..", "..mass.."t] at Hyper XYZ: "..x.." "..y.." "..z.." Local XYZ: "
- so = so..(x-rPosX+rlPosX).." "..(y-rPosY+rlPosY).." "..(z-rPosZ+rlPosZ).. " **Distance: "..cdist.."m**."
- table.insert(newShips,so)
- --print("added element "..#newShips)
- --os.sleep(1)
- if not tableHasValue(oldShips, so) then -- not already tracked
- if firstMsgPart then
- str = str.."**Newly tracked ships:**"
- firstMsgPart = false
- end
- str = str.."\n"..so
- end
- --print(so)
- --os.sleep(.5)
- --
- end
- end
- firstMsgPart = true
- for i=1,#oldShips do
- if not tableHasValue(newShips, oldShips[i]) then -- if a ship was removed
- if firstMsgPart then
- str = str.."Lost contact with ships:\n"
- firstMsgPart = false
- end
- str = str..oldShips[i].."\n"
- end
- end
- --print("\n\n")
- --print("l3:"..#newShips)
- if str ~= "" then
- str = "-------------------------------\n"..str
- --print("posting update to discord...")
- local sanitized = ""
- for j=1,str:len() do
- if string.find(str:sub(j,j), "\"") or str:sub(j,j):find("\\") then
- sanitized = sanitized .. "."
- -- print("removed "..str:sub(j,j))
- else
- sanitized = sanitized .. string.sub(str,j,j)
- end
- end
- --print(sanitized)
- term.setCursorPos(1,11)
- term.clearLine()
- print("Sent Results to HFGR Server.")
- if sanitized:len() > 1950 then
- sanitized = sanitized:sub(1,1951).."[..]"
- end
- http.post(discordUri, "{\"content\":\""..sanitized:gsub("\n","\\n").."\"}",{['content-type']="application/json"})
- end
- oldShips = newShips
- sleep(intervalSec)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement