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