Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sneak [Proximity] Door by snirkimmington. Doors that you can sneak in front of to open them!
- -- Requires OpenPeripheral and Sensor block. If you want regular proximity doors, see http://pastebin.com/N5TgZh0x.
- -- To use, edit the next 5 lines. (If you want, you can add to the sleep times.)
- -- The min/max X and Y is a <= or >= check and the numbers are relative to the player.
- -- Output is where to output a signal to, and initial is what the signal should be when untoggled.
- local minX = -2 local maxX = 2
- local minY = -2 local maxY = 2
- local minZ = -2 local maxZ = 2
- local sensor = peripheral.wrap('left') -- Where the sensor is
- local output = 'right' -- Where to output
- local redstone_level = 15
- local initial_signal = true -- Default signal
- -- Begin code --
- -- If you would like, you can edit the check on line 39 to, say, data.isBlocking or something. You could even check for holding a specific item in the inventory.
- local toggle = false
- local current_signal = initial_signal
- -- Set initial redstone level
- if initial_signal then
- redstone.setAnalogOutput(output, redstone_level)
- end
- -- Infinite loop
- while true do
- -- Get the players from the sensor.
- local player_namess = sensor.getPlayers()
- -- If there are no players around
- if #players == 0 then
- -- If there are no players, it shouldn't be toggled or do any checks.
- toggle = false
- sleep(2)
- else -- There are players
- -- We need to make sure anyone can open the doors.
- local any = false
- for _, player in pairs(players) do
- -- Yes, a null check is required.
- -- You can replace with "if name == your name" to be you-only.
- if player ~= '' then
- -- Get position data
- -- So this method fails sometimes.
- -- pcall() doesn't seem to work.
- --- You will need to call a wrapper script.
- local data = sensor.getPlayerByUUID(player.uuid)
- if data ~= nil and data.all ~= nil then
- local pos = data.all().position
- -- Check if the player is in range
- 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.living.isSneaking == true then
- any = true
- break
- end
- end
- end
- end
- if any then -- shifting players found
- if not toggle then
- toggle = true
- if current_signal then
- redstone.setAnalogOutput(output, 0)
- else
- redstone.setAnalogOutput(output, redstone_level)
- end
- current_signal = not current_signal
- end
- else -- no shifting
- toggle = false
- end
- -- If we detect any players, we should sleep less between sweeps.
- sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment