Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local uri = "htt"
- local intervalSec = 15
- function tableHasValue(table, v)
- for i=1,#table do
- if table[i] == v then
- return true
- end
- end
- return false
- end
- if not term.isColor() then
- print("Advanced computer required")
- error()
- end
- local function showError(message)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.write(message)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- print()
- end
- local function showErrorAndExit(message)
- showError(message)
- error()
- end
- local camera
- local cameras = {}
- local sides = peripheral.getNames()
- for key,side in pairs(sides) do
- if peripheral.getType(side) == "warpdriveCamera" then
- print("Camera found on " .. side)
- camera = peripheral.wrap(side)
- table.insert(cameras, peripheral.wrap(side))
- --camera.videoChannel("23" + key)
- end
- end
- if camera == nil or camera.isInterfaced() == nil then
- showErrorAndExit("No camera detected")
- end
- local argv = { ... }
- if #argv ~= 0 then
- showErrorAndExit("Usage: recognition")
- end
- while true do
- for _, camera in pairs(cameras) do
- local delay = 0
- local count
- local newFaces = {}
- local oldFaces = {}
- repeat
- count = camera.getResultsCount()
- os.sleep(0.1)
- delay = delay + 1
- until (count ~= nil and count ~= -1) or delay > 10
- if count ~= nil and count > 0 then
- for i=0, count-1 do
- local success, type, name, x, y, z, vx, vy, vz = camera.getResult(i)
- x = math.floor(x * 10) / 10
- y = math.floor(y * 10) / 10
- z = math.floor(z * 10) / 10
- if success then
- if type == "minecraft:player" then
- player = "".. name .." @ (" .. x .. " " .. y .. " " .. z .. ")"
- table.insert(newFaces,player)
- if not tableHasValue(oldFaces, player) then -- not already tracked
- if firstMsgPart then
- str = str.."**Newly tracked Players:**"
- firstMsgPart = false
- end
- str = str.."\n"..so
- end
- --print(so)
- --os.sleep(.5)
- --
- end
- end
- firstMsgPart = true
- for i=1,#oldFaces do
- if not tableHasValue(newFaces, oldFaces[i]) then -- if a ship was removed
- if firstMsgPart then
- str = str.."Lost contact with ships:\n"
- firstMsgPart = false
- end
- str = str..oldFaces[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
- oldFaces = newFaces
- sleep(intervalSec)
- end
- else
- end
- else
- showError("Error " .. type)
- end
- end
- else
- print("Nothing was found =(")
- end
- end
- oldFaces = newFaces
- sleep(intervalSec)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement