Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --VaultDoor by KapitanWalnut
- --version 1.4
- --Outputs redstone signal when player is sneaking within the detection area
- --NOTE: requires OpenPeripherals sensor
- --Detection Area
- local minX = 2 local maxX = 7
- local minY = -5 local maxY = 3
- local minZ = -2 local maxZ = 2
- --open time (seconds)
- openTime = 3
- --keep track of if vault is closed
- vaultClosed = true
- --sensor in relation to computer
- local sensor = peripheral.wrap("back")
- --open module in relation to computer
- local moduleOpen = "right"
- --close module in relation to computer
- local moduleClose = "left"
- --disintegrate module in relation to computer
- local moduleDisin = "front"
- --Open and Close functions
- function close()
- vaultClosed = true
- rs.setOutput(moduleOpen, false)
- rs.setOutput(moduleClose, true)
- rs.setOutput(moduleDisin, true)
- sleep(3)
- rs.setOutput(moduleDisin, false)
- sleep(3)
- rs.setOutput(moduleClose, false)
- end
- function open()
- vaultClosed = false
- rs.setOutput(moduleOpen, true)
- rs.setOutput(moduleClose, false)
- rs.setOutput(moduleDisin, true)
- sleep(3)
- rs.setOutput(moduleDisin, false)
- sleep(3)
- rs.setOutput(moduleOpen, false)
- end
- --Initially door should be closed
- close()
- --Infinite loop
- while true do
- --Get players from sensor
- players = sensor.getPlayerNames()
- --no players around
- if #players == 0 then
- --no one's around, make sure vault is closed
- if not vaultClosed then
- close()
- end
- --don't do stuff
- sleep(0.7)
- else --players in vicinity
- for _,name in pairs(players) do
- --anyone can open vault
- if name ~= '' then
- data = sensor.getPlayerData(name)
- pos = data.position
- --check if player is in vicinity
- if pos.x >= minX and pos.x <= maxX
- and pos.y >= minY and pos.y <= maxY
- and pos.z >= minZ and pos.z <= maxZ
- and data.isSneaking == true then
- if vaultClosed then
- open()
- sleep(openTime)
- end
- elseif not vaultClosed then
- close()
- end
- end
- end
- sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment