Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local p = peripheral.wrap("right")
- local door = false
- door = false
- redstone.setOutput("left", true)
- --i = 1
- -- The following 3 functions need to be like this
- -- to use the return feature. This is done to
- -- refresh the information coming in.
- function getInfo()
- info = p.getPlayers()
- return info
- end
- function getUsername()
- getInfo()
- username = info[1].name
- return username
- end
- function getPos()
- pos = p.getPlayerByName(username).position
- return pos
- end
- function chkDoor()
- if door == true then
- redstone.setOutput("left", false)
- else
- redstone.setOutput("left", true)
- end
- end
- --Main Program. A lot of frustration went into this.
- --I'm glad it works now.
- function chkPlayer()
- if #p.getPlayers() ~= 0 then
- -- print("Somone is online! Who is it?")
- getInfo()
- getUsername()
- getPos()
- -- print(username.." is at coords: "..pos.x.."x, "..pos.y.."y, "..pos.z.."z, ")
- if pos.x >= -5 and pos.x <= 5
- and pos.y >= -5 and pos.y <= 0
- and pos.z >= -5 and pos.z <= 5 then
- -- print(username.."is in the spot. Opening Door.")
- door = true
- else
- -- print(username.."is not in the spot. Closing Door.")
- door = false
- end
- end
- end
- while true do
- sleep(0.5)
- --print("Iteration: "..i)
- --i = i + 1
- chkDoor()
- chkPlayer()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement