Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- place = "Tyrian+TDS"
- alarmSide = "right"
- teslaSide = "back"
- sensorSide = "top"
- enableRequired = false
- enabledSide = "bottom"
- duration = 120
- sendEmail = true
- chatSide = "bottom"
- minX = -6
- minY = -40
- minZ = -2
- maxX = 2
- maxY = 8.5
- maxZ = 4
- -- y 8.5
- -- x -6.2
- -- z -2.01
- -- y -25.5
- -- x 1.95
- -- z 3.8
- -- y 6.5
- -- x -7.2
- -- z -3.2
- -- y -25.5
- -- x 3
- -- z 5
- apiKey = ""
- allowedPlayers = {
- "lego11",
- "Fabrimat",
- "kiiw"
- }
- -- DO NOT EDIT
- teslaOutputMain = false
- teslaOutputTDS = false
- alarmOutputMain = false
- alarmOutputTDS = false
- emailSent = true
- timer = 0
- se = sensor.wrap(sensorSide)
- chatbox = peripheral.wrap(chatSide)
- timerTDS = 0
- instruction = 0
- endor = false
- chatMessage = ""
- defcon = ""
- alarm = false
- chatRadius = 0
- update = false
- shell.run("pastebin get ADaQ4War json")
- os.loadAPI("json")
- function updateVars()
- rest = http.get("http://rgbvm.fabrimat.me/~fabrimat/tds.php")
- if(rest == nil) then
- return
- end
- s = rest.readAll()
- t = json.decode(s)
- defcon = t.defcon
- endor = t.endor
- chatRadius = t.chat_radius
- alarm = t.alarm
- chatMessage = t.chat_message
- timerTDS = t.next_sleep
- if(instruction < t.id) then
- instruction = t.id
- update = true
- end
- end
- function executeUpdate()
- teslaOutputTDS = endor
- alarmOutputTDS = alarm
- chatbox.say(chatMessage, chatRadius, true)
- end
- 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 <= maxX and
- details.Position.X >= minX and
- details.Position.Y <= maxY and
- details.Position.Y >= minY and
- details.Position.Z <= maxZ and
- details.Position.Z >= minZ then
- if has_value(allowedPlayers, name) or details.Gamemode then
- allowed = true
- else
- intruder = true
- intruderName = name
- end
- end
- end
- if intruder and not allowed then
- if timer == 0 then
- timer = duration
- end
- teslaOutputMain = true
- alarmOutputMain = 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("..place..")")
- print("Intruder detected. Name: " .. intruderName .. ". E-mail sent.")
- end
- else
- teslaOutputMain = false
- end
- else
- print("Warning!")
- print("Alarm system disabled")
- alarmOutputMain = false
- teslaOutputMain = false
- end
- timerTDS = timerTDS - 1
- if(timerTDS <= 0) then
- timerTDS = 0
- updateVars()
- end
- if(update) then
- executeUpdate()
- update = false
- end
- if(teslaOutputMain or teslaOutputTDS) then
- rs.setOutput(teslaSide, true)
- else
- rs.setOutput(teslaSide, false)
- end
- if(alarmOutputMain or alarmOutputTDS) then
- rs.setOutput(alarmSide, true)
- else
- rs.setOutput(alarmSide, false)
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment