Advertisement
lego11

ALLARME PIÙ ANCORA DEFINITIVISSIMO

Mar 18th, 2022
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = {
  16.     "lego11",
  17.     "Fabrimat"
  18. }
  19.  
  20. -- DO NOT EDIT
  21. emailSent = true
  22. timer = 0
  23. se = sensor.wrap(sensorSide)
  24.  
  25. local function has_value (tab, val)
  26.     for index, value in pairs(tab) do
  27.         if value == val then
  28.             return true
  29.         end
  30.     end
  31.  
  32.     return false
  33. end
  34.  
  35. while true do
  36.     if timer > 0 then
  37.         timer = timer - 1
  38.     else
  39.         emailSent = false
  40.     end
  41.    
  42.     term.clear()
  43.     if not enableRequired or rs.getInput(enabledSide) then
  44.         print("Alarm system enabled")
  45.         print("Scanning...")
  46.        
  47.         targets = se.getTargets()
  48.         intruder = false
  49.         allowed = false
  50.         intruderName = ""
  51.         for name, data in pairs(targets) do
  52.         details = se.getTargetDetails(name)
  53.             if data["Name"] == "Player" and
  54.           details ~= nil and
  55.           details.Position ~= nil and
  56.           details.Position.X <= distance and
  57.           details.Position.X >= -distance and
  58.           details.Position.Y <= distance and
  59.           details.Position.Y >= -distance and
  60.           details.Position.Z <= distance and
  61.           details.Position.Z >= -distance then
  62.                 if has_value(allowedPlayers, name) then
  63.                     allowed = true
  64.                 else
  65.                     intruder = true
  66.                     intruderName = name
  67.                 end
  68.             end
  69.         end
  70.        
  71.         if intruder and not allowed then
  72.         if timer == 0 then
  73.                 timer = duration
  74.             end
  75.  
  76.             rs.setOutput(alarmSide, true)
  77.         rs.setOutput(teslaSide, true)
  78.             if not emailSent and sendEmail then
  79.                     emailSent = true
  80.                     http.get("http://172.16.20.220/luanet/servlets/notifier.php?api="..apiKey.."&var1="..intruderName.."%20("..string.gsub(place," ", "+")..")")
  81.                     print("Intruder detected. Name: " .. intruderName .. ". E-mail sent.")
  82.                 end
  83.         else
  84.             rs.setOutput(alarmSide, false)
  85.             rs.setOutput(teslaSide, false)
  86.         end
  87.     else
  88.         print("Warning!")
  89.         print("Alarm system disabled")
  90.         rs.setOutput(alarmSide, false)
  91.         rs.setOutput(teslaSide, false)
  92.     end
  93.    
  94.     sleep(1)
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement