Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local uri = "https://discordapp.com/api/webhooks/193796725309441/4Xa8HU1cQiG72gyYC7az7Yfd_UqoE_ydngFswXbNDVjKRCQFPDa5Sidu12TvKa0e6OWO"
- 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)
- -- print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
- if not tableHasValue(oldFaces, player) then
- http.post(uri,"{\"content\":\":camera: ".. camera.videoChannel() .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. "\"}",{['content-type']="application/json"})
- else
- end
- else
- showError("Error " .. type)
- end
- else
- end
- end
- else
- print("Nothing was found =(")
- end
- end
- oldFaces = newFaces
- sleep(intervalSec)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement