SHOW:
|
|
- or go back to the newest paste.
| 1 | shell.run("clear")
| |
| 2 | print("ooooo ooooo oooooooooooo .oooooo. ooooooooo. ")
| |
| 3 | ("`888' `888' `888' `8 d8P' `Y8b `888 `Y88. ")
| |
| 4 | (" 888 888 888 888 888 .d88' ")
| |
| 5 | (" 888ooooo888 888oooo8 888 888ooo88P' ")
| |
| 6 | (" 888 888 888 " 888 ooooo 888`88b. ")
| |
| 7 | (" 888 888 888 `88. .88' 888 `88b. ")
| |
| 8 | ("o888o o888o o888o `Y8bood8P' o888o o888o ")
| |
| 9 | sleep(4) | |
| 10 | ||
| 11 | -- the webhook url for the requests | |
| 12 | local discordUri = "https://discordapp.com/api/webhooks/9897675164221440/bVNkDOVeMt0XruW3UBpLOys6ycH-E1ML9SoWwGrFXaTL_vFtpYxjj27quln6actJSEOr" | |
| 13 | ||
| 14 | -- waittime between radar scans | |
| 15 | - | error("No radar could be found!")
|
| 15 | + | |
| 16 | -- range in blocks | |
| 17 | local radarRadius = 1000 | |
| 18 | -- if something is closer than that then a warning sign will be prepended in discord | |
| 19 | - | for i=1,#table do |
| 19 | + | |
| 20 | - | if table[i] == v then |
| 20 | + | |
| 21 | - | return true |
| 21 | + | |
| 22 | if radar == nil then | |
| 23 | error("No radar could be found!")
| |
| 24 | - | return false |
| 24 | + | |
| 25 | ||
| 26 | function tableHasValue(table, v) | |
| 27 | for i=1,#table do | |
| 28 | - | local dx = x1-x2 |
| 28 | + | if table[i] == v then |
| 29 | - | local dy = y1-y2 |
| 29 | + | return true |
| 30 | - | local dz = z1-z2 |
| 30 | + | |
| 31 | - | return math.floor(math.sqrt(dx*dx+dy*dy+dz*dz)) |
| 31 | + | end |
| 32 | return false | |
| 33 | end | |
| 34 | ||
| 35 | - | |
| 35 | + | |
| 36 | - | local dur = radar.getScanDuration(radarRadius) |
| 36 | + | local dx = x1-x2 |
| 37 | - | local first = true |
| 37 | + | local dy = y1-y2 |
| 38 | - | while true do |
| 38 | + | local dz = z1-z2 |
| 39 | - | local currPwr, maxPwr, unit = radar.getEnergyStatus() |
| 39 | + | return math.floor(math.sqrt(dx*dx+dy*dy+dz*dz)) |
| 40 | - | local _,reqPwr = radar.getEnergyRequired(radarRadius) |
| 40 | + | |
| 41 | - | if reqPwr <= currPwr then |
| 41 | + | |
| 42 | - | break |
| 42 | + | |
| 43 | - | else |
| 43 | + | |
| 44 | - | if first then |
| 44 | + | local dur = radar.getScanDuration(radarRadius) |
| 45 | - | first = false |
| 45 | + | local first = true |
| 46 | - | else |
| 46 | + | while true do |
| 47 | - | local _,line=term.getCursorPos() |
| 47 | + | local currPwr, maxPwr, unit = radar.getEnergyStatus() |
| 48 | - | term.setCursorPos(1,line-1) |
| 48 | + | local _,reqPwr = radar.getEnergyRequired(radarRadius) |
| 49 | - | term.clearLine() |
| 49 | + | if reqPwr <= currPwr then |
| 50 | - | end |
| 50 | + | break |
| 51 | - | print("Waiting for energy.. ("..currPwr.."/"..reqPwr..")")
|
| 51 | + | else |
| 52 | - | |
| 52 | + | if first then |
| 53 | - | os.sleep(1) |
| 53 | + | first = false |
| 54 | else | |
| 55 | local _,line=term.getCursorPos() | |
| 56 | - | print("Scanning in the radius of "..radarRadius.." blocks. This will take "..tonumber(dur).."s.")
|
| 56 | + | term.setCursorPos(1,line-1) |
| 57 | - | |
| 57 | + | term.clearLine() |
| 58 | - | radar.start() |
| 58 | + | |
| 59 | - | os.sleep(dur + 0.1) -- sleep for duration plus buffer |
| 59 | + | print("Waiting for energy.. ("..currPwr.."/"..reqPwr..")")
|
| 60 | - | radar.getResultsCount() |
| 60 | + | |
| 61 | - | local cnt = radar.getResultsCount() |
| 61 | + | os.sleep(1) |
| 62 | - | local ret = {}
|
| 62 | + | |
| 63 | - | local dsts = {}
|
| 63 | + | end |
| 64 | - | local alreadySeen = {}
|
| 64 | + | print("Scanning in the radius of "..radarRadius.." blocks. This will take "..tonumber(dur).."s.")
|
| 65 | - | local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition() |
| 65 | + | |
| 66 | - | for i=1,cnt do |
| 66 | + | radar.start() |
| 67 | - | local result={radar.getResult(i-1)}
|
| 67 | + | os.sleep(dur + 0.1) -- sleep for duration plus buffer |
| 68 | - | -- identifier: |
| 68 | + | radar.getResultsCount() |
| 69 | - | local tv = result[2]..":"..result[3]..":"..result[4].."-"..result[5].."-"..result[6]..":"..result[7] |
| 69 | + | local cnt = radar.getResultsCount() |
| 70 | - | if result[1] == true then -- [1] = successful or not |
| 70 | + | local ret = {}
|
| 71 | - | table.insert(ret,result) |
| 71 | + | local dsts = {}
|
| 72 | - | |
| 72 | + | local alreadySeen = {}
|
| 73 | - | -- alreadySeen[#alreadySeen+1]=tv |
| 73 | + | local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition() |
| 74 | for i=1,cnt do | |
| 75 | local result={radar.getResult(i-1)}
| |
| 76 | - | 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) |
| 76 | + | -- identifier: |
| 77 | - | return ret |
| 77 | + | local tv = result[2]..":"..result[3]..":"..result[4].."-"..result[5].."-"..result[6]..":"..result[7] |
| 78 | if result[1] == true then -- [1] = successful or not | |
| 79 | table.insert(ret,result) | |
| 80 | ||
| 81 | -- alreadySeen[#alreadySeen+1]=tv | |
| 82 | end | |
| 83 | end | |
| 84 | 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) | |
| 85 | - | local res = getRadarResults() |
| 85 | + | return ret |
| 86 | - | |
| 86 | + | |
| 87 | - | shell.run("clear")
|
| 87 | + | |
| 88 | - | print("==== Ship Scanner ====")
|
| 88 | + | |
| 89 | - | |
| 89 | + | |
| 90 | - | local str = "" |
| 90 | + | |
| 91 | - | local newShips = {}
|
| 91 | + | |
| 92 | - | |
| 92 | + | |
| 93 | - | local firstMsgPart = true |
| 93 | + | local res = getRadarResults() |
| 94 | - | -- print("Currently tracked ships:")
|
| 94 | + | |
| 95 | - | local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition() |
| 95 | + | shell.run("clear")
|
| 96 | - | local rlPosX,rlPosY,rlPosZ = radar.getLocalPosition() |
| 96 | + | print("==== Ship Scanner ====")
|
| 97 | - | print("Our pos: global xyz: ("..rPosX.." "..rPosY.." "..rPosZ..") local xyz: ("..rlPosX.." "..rlPosY.." "..rlPosZ..")")
|
| 97 | + | |
| 98 | - | -- rlPosX = 0 |
| 98 | + | local str = "" |
| 99 | - | -- rlPosY = 0 |
| 99 | + | local newShips = {}
|
| 100 | - | -- rlPosZ = 0 |
| 100 | + | |
| 101 | - | |
| 101 | + | local firstMsgPart = true |
| 102 | - | --print("ress:"..#res)
|
| 102 | + | -- print("Currently tracked ships:")
|
| 103 | - | os.sleep(1) |
| 103 | + | local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition() |
| 104 | - | for |
| 104 | + | local rlPosX,rlPosY,rlPosZ = radar.getLocalPosition() |
| 105 | - | i=1,#res do |
| 105 | + | print("Our pos: global xyz: ("..rPosX.." "..rPosY.." "..rPosZ..") local xyz: ("..rlPosX.." "..rlPosY.." "..rlPosZ..")")
|
| 106 | - | local success, type, name, x, y, z, mass = table.unpack(res[i]) |
| 106 | + | -- rlPosX = 0 |
| 107 | - | if name ~= "" then |
| 107 | + | -- rlPosY = 0 |
| 108 | - | local cdist = getDst(rPosX,x,rPosY,y,rPosZ,z) |
| 108 | + | -- rlPosZ = 0 |
| 109 | - | local so = "" |
| 109 | + | |
| 110 | - | if cdist < safetyDist then so = so .. " :warning: " end |
| 110 | + | --print("ress:"..#res)
|
| 111 | - | |
| 111 | + | os.sleep(1) |
| 112 | - | so = so.. "**"..name.."** ["..type..", "..mass.."t] at Hyper XYZ: "..x.." "..y.." "..z.." Local XYZ: " |
| 112 | + | for |
| 113 | - | |
| 113 | + | i=1,#res do |
| 114 | - | so = so..(x-rPosX+rlPosX).." "..(y-rPosY+rlPosY).." "..(z-rPosZ+rlPosZ).. " **Distance: "..cdist.."m**." |
| 114 | + | local success, type, name, x, y, z, mass = table.unpack(res[i]) |
| 115 | - | table.insert(newShips,so) |
| 115 | + | if name ~= "" then |
| 116 | - | --print("added element "..#newShips)
|
| 116 | + | local cdist = getDst(rPosX,x,rPosY,y,rPosZ,z) |
| 117 | - | --os.sleep(1) |
| 117 | + | local so = "" |
| 118 | - | if not tableHasValue(oldShips, so) then -- not already tracked |
| 118 | + | if cdist < safetyDist then so = so .. " :warning: " end |
| 119 | - | if firstMsgPart then |
| 119 | + | |
| 120 | - | str = str.."**Newly tracked ships:**" |
| 120 | + | so = so.. "**"..name.."** ["..type..", "..mass.."t] at Hyper XYZ: "..x.." "..y.." "..z.." Local XYZ: " |
| 121 | - | firstMsgPart = false |
| 121 | + | |
| 122 | - | end |
| 122 | + | so = so..(x-rPosX+rlPosX).." "..(y-rPosY+rlPosY).." "..(z-rPosZ+rlPosZ).. " **Distance: "..cdist.."m**." |
| 123 | - | str = str.."\n"..so |
| 123 | + | table.insert(newShips,so) |
| 124 | - | end |
| 124 | + | --print("added element "..#newShips)
|
| 125 | - | print(so) |
| 125 | + | --os.sleep(1) |
| 126 | - | --os.sleep(.5) |
| 126 | + | if not tableHasValue(oldShips, so) then -- not already tracked |
| 127 | - | -- |
| 127 | + | if firstMsgPart then |
| 128 | str = str.."**Newly tracked ships:**" | |
| 129 | firstMsgPart = false | |
| 130 | - | |
| 130 | + | |
| 131 | - | |
| 131 | + | str = str.."\n"..so |
| 132 | - | firstMsgPart = true |
| 132 | + | |
| 133 | - | for i=1,#oldShips do |
| 133 | + | print(so) |
| 134 | - | if not tableHasValue(newShips, oldShips[i]) then -- if a ship was removed |
| 134 | + | --os.sleep(.5) |
| 135 | - | if firstMsgPart then |
| 135 | + | -- |
| 136 | - | str = str.."Lost contact with ships:\n" |
| 136 | + | |
| 137 | - | firstMsgPart = false |
| 137 | + | end |
| 138 | - | end |
| 138 | + | |
| 139 | - | str = str..oldShips[i].."\n" |
| 139 | + | |
| 140 | firstMsgPart = true | |
| 141 | for i=1,#oldShips do | |
| 142 | - | print("\n\n")
|
| 142 | + | if not tableHasValue(newShips, oldShips[i]) then -- if a ship was removed |
| 143 | - | --print("l3:"..#newShips)
|
| 143 | + | if firstMsgPart then |
| 144 | - | if str ~= "" then |
| 144 | + | str = str.."Lost contact with ships:\n" |
| 145 | - | str = "-------------------------------\n"..str |
| 145 | + | firstMsgPart = false |
| 146 | - | --print("posting update to discord...")
|
| 146 | + | |
| 147 | - | local sanitized = "" |
| 147 | + | str = str..oldShips[i].."\n" |
| 148 | - | for j=1,str:len() do |
| 148 | + | |
| 149 | - | if string.find(str:sub(j,j), "\"") or str:sub(j,j):find("\\") then
|
| 149 | + | end |
| 150 | - | sanitized = sanitized .. "." |
| 150 | + | print("\n\n")
|
| 151 | - | -- print("removed "..str:sub(j,j))
|
| 151 | + | --print("l3:"..#newShips)
|
| 152 | - | else |
| 152 | + | if str ~= "" then |
| 153 | - | sanitized = sanitized .. string.sub(str,j,j) |
| 153 | + | str = "-------------------------------\n"..str |
| 154 | - | end |
| 154 | + | --print("posting update to discord...")
|
| 155 | local sanitized = "" | |
| 156 | - | print(sanitized) |
| 156 | + | for j=1,str:len() do |
| 157 | - | -- print("len: "..#sanitized)
|
| 157 | + | if string.find(str:sub(j,j), "\"") or str:sub(j,j):find("\\") then
|
| 158 | - | if sanitized:len() > 1950 then |
| 158 | + | sanitized = sanitized .. "." |
| 159 | - | sanitized = sanitized:sub(1,1951).."[..]" |
| 159 | + | -- print("removed "..str:sub(j,j))
|
| 160 | else | |
| 161 | - | http.post(discordUri, "{\"content\":\""..sanitized:gsub("\n","\\n").."\"}",{['content-type']="application/json"})
|
| 161 | + | sanitized = sanitized .. string.sub(str,j,j) |
| 162 | - | end |
| 162 | + | |
| 163 | - | -- |
| 163 | + | |
| 164 | - | oldShips = newShips |
| 164 | + | print(sanitized) |
| 165 | - | -- newShips = {}
|
| 165 | + | if sanitized:len() > 1950 then |
| 166 | - | -- print("len2"..#oldShips)
|
| 166 | + | sanitized = sanitized:sub(1,1951).."[..]" |
| 167 | - | sleep(intervalSec) |
| 167 | + | |
| 168 | http.post(discordUri, "{\"content\":\""..sanitized:gsub("\n","\\n").."\"}",{['content-type']="application/json"})
| |
| 169 | end | |
| 170 | oldShips = newShips | |
| 171 | sleep(intervalSec) | |
| 172 | end |