View difference between Paste ID: iirEhRW6 and 5vQT3fKX
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("ocs/apis/sensor")
2
3
place = ""
4
distance = 10
5
alarmSide = "right"
6
teslaSide = "left"
7
sensorSide = "top"
8
enableRequired = false
9
enabledSide = "back"
10
duration = 120
11
sendEmail = false
12
13
apiKey = ""
14
15-
allowedPlayers = {
15+
allowedPlayers = {}
16-
    "lego11", 
16+
rest = http.get("http://172.16.20.227/~fabrimat/proclus-acl.php")
17-
    "Fabrimat"
17+
s = rest.readAll()
18-
}
18+
shell.run("pastebin get ADaQ4War json")
19
os.loadAPI("json")
20
t = json.decode(s)
21
for key, val in pairs(t) do
22
    table.insert(allowedPlayers, val.Name)
23
end
24
25
-- DO NOT EDIT
26
emailSent = true
27
timer = 0
28
se = sensor.wrap(sensorSide)
29
30
local function has_value (tab, val)
31
    for index, value in pairs(tab) do
32
        if value == val then
33
            return true
34
        end
35
    end
36
37
    return false
38
end
39
40
while true do
41
    if timer > 0 then
42
        timer = timer - 1
43
    else
44
        emailSent = false
45
    end
46
    
47
    term.clear()
48
    if not enableRequired or rs.getInput(enabledSide) then
49
        print("Alarm system enabled")
50
        print("Scanning...")
51
        
52
        targets = se.getTargets()
53
        intruder = false
54
        allowed = false
55
        intruderName = ""
56
        for name, data in pairs(targets) do
57
        details = se.getTargetDetails(name)
58
            if data["Name"] == "Player" and 
59
          details ~= nil and 
60
          details.Position ~= nil and 
61
          details.Position.X <= distance and 
62
          details.Position.X >= -distance and 
63
          details.Position.Y <= distance and 
64
          details.Position.Y >= -distance and 
65
          details.Position.Z <= distance and
66
          details.Position.Z >= -distance then
67
                if has_value(allowedPlayers, name) then
68
                    allowed = true
69
                else
70
                    intruder = true
71
                    intruderName = name
72
                end
73
            end
74
        end
75
        
76
        if intruder and not allowed then
77
        if timer == 0 then
78
                timer = duration
79
            end
80-
                    http.get("http://172.16.20.220/luanet/servlets/notifier.php?api="..apiKey.."&var1="..intruderName.."%20("..string.gsub(place," ", "+")..")")
80+
81
            rs.setOutput(alarmSide, true)
82
        rs.setOutput(teslaSide, true)
83
            if not emailSent and sendEmail then
84
                    emailSent = true
85
                    http.get("http://172.16.20.220/luanet/servlets/notifier.php?api="..apiKey.."&var1="..intruderName.."%20("..place..")")
86
                    print("Intruder detected. Name: " .. intruderName .. ". E-mail sent.")
87
                end
88
        else
89
            rs.setOutput(alarmSide, false)
90
            rs.setOutput(teslaSide, false)
91
        end
92
    else
93
        print("Warning!")
94
        print("Alarm system disabled")
95
        rs.setOutput(alarmSide, false)
96
        rs.setOutput(teslaSide, false)
97
    end
98
    
99
    sleep(1)
100
end