Advertisement
Guest User

startup

a guest
Jan 14th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. local uri = "https://discordapp.com/api/webhooks/193796725309441/4Xa8HU1cQiG72gyYC7az7Yfd_UqoE_ydngFswXbNDVjKRCQFPDa5Sidu12TvKa0e6OWO"
  2. local intervalSec = 15
  3. function tableHasValue(table, v)
  4.   for i=1,#table do
  5.     if table[i] == v then
  6.       return true
  7.     end
  8.   end
  9.   return false
  10. end
  11.  
  12. if not term.isColor() then
  13.   print("Advanced computer required")
  14.   error()
  15. end
  16.  
  17. local function showError(message)
  18.   term.setBackgroundColor(colors.black)
  19.   term.setTextColor(colors.red)
  20.   term.write(message)
  21.   term.setBackgroundColor(colors.black)
  22.   term.setTextColor(colors.white)
  23.   print()
  24. end
  25.  
  26. local function showErrorAndExit(message)
  27.   showError(message)
  28.   error()
  29. end
  30.  
  31. local camera
  32. local cameras = {}
  33. local sides = peripheral.getNames()
  34. for key,side in pairs(sides) do
  35.   if peripheral.getType(side) == "warpdriveCamera" then
  36.     print("Camera found on " .. side)
  37.     camera = peripheral.wrap(side)
  38.     table.insert(cameras, peripheral.wrap(side))
  39.     --camera.videoChannel("23" + key)
  40.   end
  41. end
  42. if camera == nil or camera.isInterfaced() == nil then
  43.   showErrorAndExit("No camera detected")
  44. end
  45.  
  46. local argv = { ... }
  47. if #argv ~= 0 then
  48.   showErrorAndExit("Usage: recognition")
  49. end
  50. while true do
  51. for _, camera in pairs(cameras) do
  52. local delay = 0
  53. local count  
  54. local newFaces = {}
  55. local oldFaces = {}
  56. repeat
  57.   count = camera.getResultsCount()
  58.   os.sleep(0.1)
  59.   delay = delay + 1
  60. until (count ~= nil and count ~= -1) or delay > 10
  61.  
  62. if count ~= nil and count > 0 then
  63.   for i=0, count-1 do
  64.     local success, type, name, x, y, z, vx, vy, vz = camera.getResult(i)
  65.     x = math.floor(x * 10) / 10
  66.     y = math.floor(y * 10) / 10
  67.     z = math.floor(z * 10) / 10
  68.     if success then
  69.     if type == "minecraft:player" then
  70.     player = "".. name .." @ (" .. x .. " " .. y .. " " .. z .. ")"
  71.     table.insert(newFaces,player)
  72.    --   print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
  73.    if not tableHasValue(oldFaces, player) then
  74.      http.post(uri,"{\"content\":\":camera: ".. camera.videoChannel() .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. "\"}",{['content-type']="application/json"})
  75.    
  76.        else
  77.        end
  78.        else
  79.       showError("Error " .. type)
  80.     end
  81.     else
  82.     end
  83. end
  84. else
  85.   print("Nothing was found =(")
  86. end
  87. end
  88. oldFaces = newFaces
  89.  sleep(intervalSec)
  90.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement