Dragon53535

Sensor Door

Aug 19th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Original door by Snirkimmington, modified door by Dragon53535
  2. local minX = -3 local maxX = 0 -- You're going to need to edit these to where you want them to stand to open the door.
  3. local minY = 0  local maxY = 4
  4. local minZ = 0 local maxZ = 2
  5. local Side = "bottom" -- What side is the sensor on?
  6. local output = 'right' -- Where to output the signal
  7. local initial = true -- what to output the first signal as
  8. local initial2 = false -- what to output the second signal as
  9. local output2 = "top" -- where to output the second signal
  10. local Filename = "Config"
  11. local sensor
  12. if peripheral.isPresent(Side) then
  13.   sensor = peripheral.wrap(Side)
  14. end
  15. local nameData = {}
  16. local file = fs.open(Filename,"r")
  17. local line = file.readLine()
  18. repeat
  19.   table.insert(nameData,line)
  20.   line = file.readLine()
  21. until line == nil
  22. file.close()
  23. local lolol = false
  24. local timer = os.startTimer(0.05) -- where the sensor is
  25. local alpha = false
  26. -- Initial output
  27. sleep(0.5)
  28. redstone.setOutput(output, initial)
  29. redstone.setOutput(output2,initial2)
  30. local function Sensor()
  31.   players = sensor.getPlayerNames()
  32.   if #players ~= 0 then -- There are players
  33.     for _, name in pairs(players) do
  34.       for _,user in pairs(nameData) do
  35.         if user == name then
  36.           info = sensor.getPlayerData(name)
  37.           pos = info.position
  38.           if pos.x >= minX and pos.x <= maxX
  39.           and pos.y >= minY and pos.y <= maxY
  40.           and pos.z >= minZ and pos.z <= maxZ then
  41.             redstone.setOutput(output2,not initial2)
  42.             sleep(0.05)
  43.             redstone.setOutput(output,not initial)
  44.             timer = os.startTimer(0.1)
  45.             alpha = true
  46.             break
  47.           end
  48.           if alpha then
  49.           alpha = false
  50.           break
  51.           end
  52.         end
  53.       end
  54.     end
  55.   end
  56. end
  57. local function Timer()
  58.   while true do
  59.     local event, param1 = os.pullEvent()
  60.     if event == "timer" and param1 == timer then
  61.       redstone.setOutput(output2, initial2)
  62.       sleep(0.05)
  63.       redstone.setOutput(output,initial)
  64.     elseif event == "char" and param1 == "c" then
  65.       lolol = true
  66.       break
  67.     end
  68.   end
  69. end
  70. local function Resetconfig()
  71.   nameData = {}
  72.   file = fs.open(Filename,"r")
  73.   line = file.readLine()
  74.   repeat
  75.     table.insert(nameData,line)
  76.     line = file.readLine()
  77.   until line == nil
  78. end
  79. while true do
  80.   if lolol then
  81.     shell.run("edit",Filename)
  82.     lolol = false
  83.     Resetconfig()
  84.   else
  85.     parallel.waitForAny(Timer,Sensor)
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment