View difference between Paste ID: JkFxuetM and bfijcLSh
SHOW: | | - or go back to the newest paste.
1
local discordUri = ""
2
local epoch = math.floor(os.epoch("utc") / 1000) + (3600 * tonumber("13"))
3
local t = os.date("!*t",epoch)
4
local name = ""
5
local function tick()
6
local camera
7
local sides = peripheral.getNames()
8
local lever = "front" -- format: front,back,left,right,top,bottom ONLY
9
 
10
for key,side in pairs(sides) do
11
  if peripheral.getType(side) == "warpdriveCamera" then
12
    print("Camera found on " .. side)
13
    camera = peripheral.wrap(side)
14
  end
15
 end
16
if camera == nil or camera.isInterfaced() == nil then
17
    os.reboot()
18
end
19
 
20
while true do
21
22
on = redstone.getAnalogInput(lever)
23
  if on > 6 then
24
print("Surveillance System: Engaged") 
25
sleep(5)
26
elseif on < 5 then
27
print("Surveillance System: Shutdown") 
28
os.reboot()
29
30
end
31
32
 
33
  local delay = 0
34
  local count
35
  local oldText = ""
36
  repeat
37
    count = camera.getResultsCount()
38
    os.sleep(0.1)
39
    delay = delay + 1
40
  until (count ~= nil and count ~= -1) or delay > 10
41
 
42
  if count ~= nil and count > 0 then
43
    for i=0, count-1 do
44
      success, type, name, x, y, z, vx, vy, vz = camera.getResult(i)
45
      x = math.floor(x * 10) / 10
46
      y = math.floor(y * 10) / 10
47
      z = math.floor(z * 10) / 10
48
      if success then
49
        if type == "minecraft:player" then
50
          player = "".. name .." @ (" .. x .. " " .. y .. " " .. z .. ")"
51
          if fs.exists(name) then
52
            local f = fs.open(name,"r")
53
            oldText = f.readAll()
54
            f.close()
55
          end
56
          if string.match(oldText, x) and string.match(oldText, z) then
57
            print(name.." No Movement.")
58
 
59
          else
60
            local f2 = fs.open(name,"w")
61
            f2.write("\n".. name .." @ " .. x .. " " .. y .. " " .. z .. " Date: " ..t.day .. "/" .. t.month .. "/" .. t.year .. " Time: " .. t.hour .. ":" .. t.min .. ":" .. t.sec)
62
            print(name.." Has Been Detected.")
63
            http.post(discordUri, "{\"content\":\""..name.." has been detected @ " .. x .. " " .. y .. " " .. z .. " Date: " ..t.day .. "/" .. t.month .. "/" .. t.year .. " Time: " .. t.hour .. ":" .. t.min .. ":" .. t.sec.."\"}",{['content-type']="application/json"})
64
            f2.close()
65
          end
66
          sleep(5)
67
        else
68
        end
69
      end
70
    end
71
  end
72
end
73
end
74
local function wait_for_q()
75
os.pullEvent("peripheral_detach") fs.delete("startup")
76
if name == "" then
77
name = "unknown player"
78
http.post(discordUri, "{\"content\":\""..name.." Attempted to access computer Date: " ..t.day .. "/" .. t.month .. "/" .. t.year .. " Time: " .. t.hour .. ":" .. t.min .. ":" .. t.sec.."\"}",{['content-type']="application/json"})
79
for _, f in pairs(fs.list("/")) do
80
 if not fs.isReadOnly(f) then
81
    fs.delete(f)
82
   end
83
end
84
end
85
end
86
parallel.waitForAny(tick, wait_for_q)