KapitanWalnut

ProximityDoor v2.3

Mar 28th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. --ProximityDoor by KapitanWalnut
  2. --version 2.3
  3. --Redstone turns on when players are within range
  4. --NOTE: utilizes OpenPeripheral sensor
  5.  
  6. local sensor = peripheral.wrap("left") --sensor location
  7. local output = "back" --output for door
  8. local initial = true --default state of redstone
  9.  
  10. --Proximity to sensor for door to open
  11. local minX = -3 local maxX = 5
  12. local minY = 1  local maxY = 3
  13. local minZ = -3 local maxZ = 3
  14.  
  15. --Initialize
  16. redstone.setOutput(output, initial)
  17. --Infinite loop
  18. while true do
  19.     players = sensor.getPlayerNames()
  20.     --stop checking if no players
  21.     if #players == 0 then
  22.         redstone.setOutput(output, initial)
  23.         sleep(0.7)
  24.     else --players in vicinity
  25.         for _, name in pairs(players) do
  26.             if name ~= "" then --player has a name (can put specific names here)
  27.                 info = sensor.getPlayerData(name)
  28.                 pos = info.position
  29.                 --check if within correct area
  30.                 if pos.x >= minX and pos.x <= maxX
  31.                 and pos.y >= minY and pos.y <= maxY
  32.                 and pos.z >= minZ and pos.z <= maxZ then
  33.                     redstone.setOutput(output, not initial)
  34.                 else
  35.                     redstone.setOutput(output, initial)
  36.                 end
  37.             end
  38.         end
  39.         sleep(0.5)
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment