Posted 15 October 2013 - 06:45 PM
Here's my current code:
The authorized file simply has the word "test" on the first line, though it still gives me access granted. Also it says "Access granted nil, welcome in!" rather than my username. Any ideas?
Spoiler
-- sets up stuff
-- put your allowed players here:
pd = peripheral.wrap("right") -- pd = playerdetector
speaker = peripheral.wrap("top")
print("yolo")
getTable = {}
function checkFile()
if fs.exists("authorized") == true then
i = 1
loadFile = fs.open("authorized", "r")
print("table thing")
-- If the last attempt to read from the file failed, stop the "while" loop.
getEvent()
print("Banlist exists already.")
else
openThat = fs.open("authorized", "w")
openThat.close()
print("Banlist created!")
end
end
function getEvent()
eventData = {os.pullEvent()}
if eventData[1] == "player" then
checkAuthority(eventData[2])
print("Checking!")
end
end
function allowed(player)
speaker.speak("Access granted, "..tostring(player).."Welcome in!", 1)
end
function deny(player)
speaker.speak("Sorry, but you're not allowed in here "..player.." If you feel this was a mistake, contact Intoxicated.", 1)
end
function checkAuthority(player)
if getTable[i] == player then
allowed(player)
else
while true do
i=i+1
checkAuthority()
if i <= 200 then
deny()
else
checkAuthority(player)
end
break
end
end
end
while true do
checkFile()
end