Right so I am no way the best coder so below is my code to open a door automatically depending who is in the room.
I got that part to work
So if me (lce123) is in the room the door is open
if me and someone else is in the room the door is open
if someone else is in the room without me the door is closed
However if no one is in the room the code won't shut the door (which is not what I want)
if that makes sense
So if someone knows how I can code the door close when no one is there that would be great
I got that part to work
So if me (lce123) is in the room the door is open
if me and someone else is in the room the door is open
if someone else is in the room without me the door is closed
However if no one is in the room the code won't shut the door (which is not what I want)
if that makes sense
Code:
p = peripheral.wrap("left")
function unlock()
rs.setOutput("right", true)
end
while true do
os.pullEvent =os.pullEventRaw
var = 0
players = p.getPlayerNames()
for num, name in pairs(players) do
if name == "lce123" then
print("variable set to 1")
var = 1
sleep(1)
end
if var == 1 then
print("unlocking")
unlock()
sleep(1)
elseif var == 0 then
rs.setOutput("right", false)
end
print(num..":"..name)
var = 0
end
sleep(1)
end
So if someone knows how I can code the door close when no one is there that would be great