serafim7

детектор движения [OpenComputers]

Nov 8th, 2020
2,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local event = require('event')
  2. local com = require('component')
  3. local sensor = com.motion_sensor
  4. local rs = com.redstone
  5. local sides = require('sides')
  6.  
  7. local whitelist = {"serafim","zombiman"}  --список кого впускать
  8. local sideredstone = "right"  --"left","right","front","back","bottom","top".
  9.  
  10. local function redset(side, value)
  11.   rs.setOutput(sides[side], value)
  12. end
  13. redset(sideredstone, 0)
  14.  
  15. local function isUser(name)
  16.   for i=1, #whitelist do
  17.     if name == whitelist[i] then
  18.       return true
  19.     end
  20.   end
  21.   return false
  22. end
  23.  
  24. while true do
  25.   local _, address, x, y, z, name = event.pull('motion')
  26.   --print("x "..math.ceil(x).."  y "..math.ceil(y).."  z "..math.ceil(z))
  27.   print("замечен: "..name)
  28.   if isUser(name) then
  29.     print("дверь открыта")
  30.     redset(sideredstone, 15)
  31.     os.sleep(3)  --время открытой двери
  32.     redset(sideredstone, 0)
  33.   else
  34.     print("посторонним вход запрещен")
  35.     os.sleep(3)
  36.     print(" ")
  37.   end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment