Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local protocol = "doorOpener"
- local hostname = "doorLock"
- function main ()
- local detector = peripheral.find("playerDetector")
- rednet.host(protocol, hostname)
- parallel.waitForAny(
- -- physical
- function ()
- while true do
- -- player input
- term.clear()
- term.setCursorPos(1, 1)
- print ("Password: ")
- input = read("*")
- if input == "open" then
- redstone.setOutput("bottom", true)
- sleep(3)
- redstone.setOutput("bottom", false)
- end
- end
- end,
- -- player detector
- function ()
- while true do
- local playerInRange = function (range)
- local players = detector.getPlayersInRange(range)
- return #players > 0
- end
- if detector ~= nil then
- if playerInRange(3) then
- redstone.setOutput("bottom", true)
- else
- redstone.setOutput("bottom", false)
- end
- end
- end
- end,
- -- rednet recv
- function ()
- while true do
- if (peripheral.isPresent("back")) then
- _, message, _ = rednet.receive(protocol)
- local m = textutils.unserialize(message)
- local x, y, z = gps.locate()
- if m.x and m.y and m.z and math.floor(y) == math.floor(m.y) then
- if math.floor(math.sqrt(math.pow(m.x - x, 2) + math.pow(m.z - z, 2))) < 10 then
- redstone.setOutput("bottom", true)
- sleep(5)
- redstone.setOutput("bottom", false)
- end
- end
- end
- end
- end
- )
- rednet.unhost(protocol)
- end
- if args[1] == "update" then
- shell.run("pastebin", "run", "FuQ3WvPs B0699K9y doorLock")
- else
- peripheral.wrap("top")
- if (peripheral.isPresent("back")) then
- rednet.open("back")
- end
- main()
- if (peripheral.isPresent("back")) then
- rednet.close("back")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement