Fabrimat

TDS Master

Jul 10th, 2021 (edited)
4,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.00 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. place = "Tyrian+TDS"
  4. alarmSide = "right"
  5. teslaSide = "back"
  6. sensorSide = "top"
  7. enableRequired = false
  8. enabledSide = "bottom"
  9. duration = 120
  10. sendEmail = true
  11. chatSide = "bottom"
  12.  
  13. minX = -6
  14. minY = -40
  15. minZ = -2
  16. maxX = 2
  17. maxY = 8.5
  18. maxZ = 4
  19.  
  20. -- y 8.5
  21. -- x -6.2
  22. -- z -2.01
  23. -- y -25.5
  24. -- x 1.95
  25. -- z 3.8
  26.  
  27.  
  28. -- y 6.5
  29. -- x -7.2
  30. -- z -3.2
  31. -- y -25.5
  32. -- x 3
  33. -- z 5
  34.  
  35. apiKey = ""
  36.  
  37. allowedPlayers = {
  38.     "lego11",
  39.     "Fabrimat",
  40.     "kiiw"
  41. }
  42.  
  43. -- DO NOT EDIT
  44. teslaOutputMain = false
  45. teslaOutputTDS = false
  46. alarmOutputMain = false
  47. alarmOutputTDS = false
  48.  
  49. emailSent = true
  50. timer = 0
  51. se = sensor.wrap(sensorSide)
  52.  
  53. chatbox = peripheral.wrap(chatSide)
  54.  
  55. timerTDS = 0
  56. instruction = 0
  57. endor = false
  58. chatMessage = ""
  59. defcon = ""
  60. alarm = false
  61. chatRadius = 0
  62. update = false
  63.  
  64. shell.run("pastebin get ADaQ4War json")
  65. os.loadAPI("json")
  66.  
  67. function updateVars()
  68.     rest = http.get("http://rgbvm.fabrimat.me/~fabrimat/tds.php")
  69.     if(rest == nil) then
  70.         return
  71.     end
  72.    
  73.     s = rest.readAll()
  74.     t = json.decode(s)
  75.    
  76.     defcon = t.defcon
  77.     endor = t.endor
  78.     chatRadius = t.chat_radius
  79.     alarm = t.alarm
  80.     chatMessage = t.chat_message
  81.     timerTDS = t.next_sleep
  82.     if(instruction < t.id) then
  83.         instruction = t.id
  84.         update = true
  85.     end
  86. end
  87.  
  88. function executeUpdate()
  89.     teslaOutputTDS = endor
  90.     alarmOutputTDS = alarm
  91.    
  92.     chatbox.say(chatMessage, chatRadius, true)
  93. end
  94.  
  95. local function has_value (tab, val)
  96.     for index, value in pairs(tab) do
  97.         if value == val then
  98.             return true
  99.         end
  100.     end
  101.  
  102.     return false
  103. end
  104.  
  105. while true do
  106.     if timer > 0 then
  107.         timer = timer - 1
  108.     else
  109.         emailSent = false
  110.     end
  111.    
  112.     --term.clear()
  113.     if not enableRequired or rs.getInput(enabledSide) then
  114.         print("Alarm system enabled")
  115.         print("Scanning...")
  116.        
  117.         targets = se.getTargets()
  118.         intruder = false
  119.         allowed = false
  120.         intruderName = ""
  121.         for name, data in pairs(targets) do
  122.         details = se.getTargetDetails(name)
  123.             if data["Name"] == "Player" and
  124.           details ~= nil and
  125.           details.Position ~= nil and
  126.           details.Position.X <= maxX and
  127.           details.Position.X >= minX and
  128.           details.Position.Y <= maxY and
  129.           details.Position.Y >= minY and
  130.           details.Position.Z <= maxZ and
  131.           details.Position.Z >= minZ then
  132.                 if has_value(allowedPlayers, name) or details.Gamemode then
  133.                     allowed = true
  134.                 else
  135.                     intruder = true
  136.                     intruderName = name
  137.                 end
  138.             end
  139.         end
  140.        
  141.         if intruder and not allowed then
  142.         if timer == 0 then
  143.                 timer = duration
  144.             end
  145.  
  146.         teslaOutputMain = true
  147.         alarmOutputMain = true
  148.             if not emailSent and sendEmail then
  149.                     emailSent = true
  150.                     http.get("http://172.16.20.220/luanet/servlets/notifier.php?api="..apiKey.."&var1="..intruderName.."%20("..place..")")
  151.                     print("Intruder detected. Name: " .. intruderName .. ". E-mail sent.")
  152.                 end
  153.         else
  154.             teslaOutputMain = false
  155.         end
  156.     else
  157.         print("Warning!")
  158.         print("Alarm system disabled")
  159.         alarmOutputMain = false
  160.         teslaOutputMain = false
  161.     end
  162.    
  163.     timerTDS = timerTDS - 1
  164.     if(timerTDS <= 0) then
  165.         timerTDS = 0
  166.         updateVars()
  167.     end
  168.    
  169.     if(update) then
  170.         executeUpdate()
  171.         update = false
  172.     end
  173.    
  174.     if(teslaOutputMain or teslaOutputTDS) then
  175.         rs.setOutput(teslaSide, true)
  176.     else
  177.         rs.setOutput(teslaSide, false)
  178.     end
  179.    
  180.     if(alarmOutputMain or alarmOutputTDS) then
  181.         rs.setOutput(alarmSide, true)
  182.     else
  183.         rs.setOutput(alarmSide, false)
  184.     end
  185.    
  186.     sleep(1)
  187. end
Advertisement
Add Comment
Please, Sign In to add comment