Hello again, code is almost done now, one small (big?) problem left though.
Lets say there is a "whitelisted" and a "blacklisted" player in the room.
The redstone signal will then come on and off because the system dont know which one to choose from.
I want it to be that if there is only a whitelisted player in the area, open the door and let it stay open until he leaves or a blacklisted/stranger comes into the room.
So Whitelisted player only = Open
Whitelisted + Blacklisted / Stranger = Closed
Blacklisted + Stranger = Closed
Here comes the code:
p = peripheral.wrap("left")
m = peripheral.wrap("monitor_1")
local whiteList = {}
local blackList = {}
--whiteList["Player1"] = true
whiteList["Player1"] = true
blackList["Player2"] = true
function centerText(text)
m.setTextScale(0.5)
x,y = m.getSize()
x1,y1 = m.getCursorPos()
m.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
m.write(text)
end
function white(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, y2)
centerText("Hej "..playerName.."!")
m.setCursorPos(1, y2 +1)
centerText("Välkommen till Player1's & Player2's place!")
m.setCursorPos(1, y2 +2)
centerText("Du är Accepterad att komma in i denna bas.")
m.setCursorPos(1, y2 +3)
centerText("Vänligen ta Elevatorn ner till höger.")
rs.setBundledOutput("bottom", 1)
sleep(2)
rs.setBundledOutput("bottom", 0)
end
function black(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, y2)
centerText("Hej "..playerName.."!")
m.setCursorPos(1, y2 +1)
centerText("Du är inte välkommen här.")
m.setCursorPos(1, y2 +2)
centerText("Vänligen stick härifrån.")
m.setCursorPos(1, y2 +3)
centerText("Portal finns bakom dig.")
end
function nobody(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, y2)
centerText("Hej "..playerName.."!")
m.setCursorPos(1, y2 +1)
centerText("Du är varken nekad eller godkänd för åtkomst till denna bas.")
m.setCursorPos(1, y2 +2)
centerText("Vänligen kontakta Player1 eller Player2.")
m.setCursorPos(1, y2 +3)
centerText("Portal till Spawn finns bakom dig.")
end
function reset()
rs.setBundledOutput("bottom", 0)
end
while true do
sleep(1)
players = p.getPlayerNames()
for num,name in pairs(players) do
if whiteList[name] then
print("Vitlistad spelare: "..name.."")
white(name)
elseif blackList[name] then
print("Blacklistad spelare: "..name.."")
black(name)
else
print("Systemet känner inte igen: "..name.."")
nobody(name)
end
rs.setBundledOutput("bottom", 0)
end
end
I'm guessing it's possible, I just don't know how.
EDIT: Also can't get the Tab's to work in the code like the first post, don't know what I'm doing different this time.