Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- place = ""
- distance = 10
- alarmSide = "right"
- teslaSide = "left"
- sensorSide = "top"
- enableRequired = false
- enabledSide = "back"
- duration = 120
- sendEmail = false
- apiKey = ""
- allowedPlayers = {
- "lego11",
- "Fabrimat"
- }
- -- DO NOT EDIT
- emailSent = true
- timer = 0
- se = sensor.wrap(sensorSide)
- local function has_value (tab, val)
- for index, value in pairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- while true do
- if timer > 0 then
- timer = timer - 1
- else
- emailSent = false
- end
- term.clear()
- if not enableRequired or rs.getInput(enabledSide) then
- print("Alarm system enabled")
- print("Scanning...")
- targets = se.getTargets()
- intruder = false
- allowed = false
- intruderName = ""
- for name, data in pairs(targets) do
- details = se.getTargetDetails(name)
- if data["Name"] == "Player" and
- details ~= nil and
- details.Position ~= nil and
- details.Position.X <= distance and
- details.Position.X >= -distance and
- details.Position.Y <= distance and
- details.Position.Y >= -distance and
- details.Position.Z <= distance and
- details.Position.Z >= -distance then
- if has_value(allowedPlayers, name) then
- allowed = true
- else
- intruder = true
- intruderName = name
- end
- end
- end
- if intruder and not allowed then
- if timer == 0 then
- timer = duration
- end
- rs.setOutput(alarmSide, true)
- rs.setOutput(teslaSide, true)
- if not emailSent and sendEmail then
- emailSent = true
- http.get("http://172.16.20.220/luanet/servlets/notifier.php?api="..apiKey.."&var1="..intruderName.."%20("..string.gsub(place," ", "+")..")")
- print("Intruder detected. Name: " .. intruderName .. ". E-mail sent.")
- end
- else
- rs.setOutput(alarmSide, false)
- rs.setOutput(teslaSide, false)
- end
- else
- print("Warning!")
- print("Alarm system disabled")
- rs.setOutput(alarmSide, false)
- rs.setOutput(teslaSide, false)
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement