Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MODIFY IF YOU NEED TO:
- -- If your door get opened when redstone signal is
- -- applied, then set doorOpenState to true, in the
- -- other case, set it false.
- local doorOpenedState = true
- -- Set sensorPosition with the side where the
- -- sensor is.
- -- Available: top, bottom, left, right, front and back
- local sensorPosition = "right"
- -- Set doorPosition with the side where you want
- -- the redstone signal to be outputted.
- -- Available: top, bottom, left, right, front and back
- local doorPosition = "left"
- -- These variables regulate how much close you
- -- have to be to the sensor to get the door opened.
- -- In this case, if you are more than 3 block away
- -- from the sensor, the door will stay closed.
- xDistance1 = -3
- xDistance2 = 3
- yDistance1 = -3
- yDistance2 = 3
- zDistance1 = -3
- zDistance2 = 3
- -- If a player is in this list, the door
- -- will get opened for him.
- -- These names are examples, you should delete
- -- them and add only the names you want.
- local playersAllowed = {
- "isama92",
- "Al",
- "John",
- "Jack",
- "Peter",
- }
- -- DON'T MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING!
- -- INIZIALIZATIONS
- local p = peripheral.wrap(sensorPosition)
- local door = false -- if false the door is closed
- local found
- local playerName
- redstone.setOutput(doorPosition, (not doorOpenedState))
- -- CHECK DOOR
- function CheckDoor()
- if door == false then
- redstone.setOutput(doorPosition, (not doorOpenedState))
- else
- redstone.setOutput(doorPosition, doorOpenedState)
- end
- end
- -- CHECK PLAYER POSITION
- function CheckPlayerPosition()
- pos = p.getPlayerByName(playerName).all().position
- if pos.x >= xDistance1 and pos.x <= xDistance2
- and pos.y >= yDistance1 and pos.y <= yDistance2
- and pos.z >= zDistance1 and pos.z <= zDistance2 then
- for i, playerAllowed in ipairs(playersAllowed) do
- if playerAllowed == playerName then
- found = true
- end
- end
- end
- end
- -- CHECK PLAYER
- function CheckPlayers()
- found = false
- if #p.getPlayers() > 0 then
- for i,player in ipairs(p.getPlayers()) do
- playerName = player.name
- pcall(CheckPlayerPosition)
- end
- end
- if found == true then
- door = true
- else
- door = false
- end
- CheckDoor()
- end
- -- MAIN
- while true do
- sleep(0.1)
- CheckPlayers()
- end
Advertisement
Add Comment
Please, Sign In to add comment