This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
predatorxil's profile picture

[lua][question] Please help ASAP :D

Started by predatorxil, 24 August 2012 - 10:45 PM
predatorxil #1
Posted 25 August 2012 - 12:45 AM
Hello, im trying to add multiple users to my program, so that i can allow friends to access doors also.
im having trouble with adding more than two names, please help. if u can help, please tell me what is needed to add another user, like an elseif statement, or anything else and where to add it, thanks and srry if im confusing!


local sPath = ":/rom/programs"
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Welcome to R.S. Incorporated")
term.setCursorPos(1,2)
print("----------------------------------------------------------")
term.setCursorPos(1,3)
print("Terminal Version 2.1")
term.setCursorPos(1,4)
print("Users: ")
term.setCursorPos(1,5)
textutils.slowPrint("- predatorxil  - nexoigi")
term.setCursorPos(1,6)
textutils.slowPrint("- axel1298	 - ztrevetty88")
term.setCursorPos(1,7)
textutils.slowPrint("- coolwater97")
term.setCursorPos(1,8)
print("----------------------------------------------------------")
term.setCursorPos(1,9)
textutils.slowPrint("Message: ")
term.setCursorPos(1,10)
os.pullEvent
maxuser = "admin"
maxpassword = "13034"
write("Username: ")
input = read()
if input == maxuser then
term.setCursorPos(1,11)
write("Password: ")
input = read("*")
if input == maxpassword then
  term.setCursorPos(10,9)
  textutils.slowPrint("Access Approved")
  sleep(2)
  term.clear()
  term.setCursorPos(1,1)
  textutils.slowPrint("R.S. Incorporated Terminal")
  term.setCursorPos(1,2)
  print("----------------------------------------------------------")
  term.setCursorPos(1,3)
  textutils.slowPrint("Administrator: Full Access")
  term.setCursorPos(1,4)
else
term.setCursorPos(10,9)
textutils.slowPrint("Access Denied")
sleep(2)
os.reboot()
    end
end
Noodle #2
Posted 25 August 2012 - 01:11 AM
Just add another user?
User2 = "Bob"
Pass2 = "Jose"

if input == maxuser or input == User2 then
etc
end
BigSHinyToys #3
Posted 25 August 2012 - 01:21 AM
I have added multi user support. just follow the pattern to create new users.
at the start you have to some term.setCursorPos() statements that are not needed. after a print() the cursor is moved to the bellow line at the left side.this is the same as your term.setCursorPos() i have left them in but you may want to look at removing them
Spoiler

local sPath = ":/rom/programs"
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Welcome to R.S. Incorporated")
term.setCursorPos(1,2)
print("----------------------------------------------------------")
term.setCursorPos(1,3)
print("Terminal Version 2.1")
term.setCursorPos(1,4)
print("Users: ")
term.setCursorPos(1,5)
textutils.slowPrint("- predatorxil  - nexoigi")
term.setCursorPos(1,6)
textutils.slowPrint("- axel1298  - ztrevetty88")
term.setCursorPos(1,7)
textutils.slowPrint("- coolwater97")
term.setCursorPos(1,8)
print("----------------------------------------------------------")
term.setCursorPos(1,9)
textutils.slowPrint("Message: ")
term.setCursorPos(1,10)
os.pullEvent = os.pullEventRaw -- this disables Ctrl+T
local tUsers = {}
tUsers["admin"] = "13034"
tUsers["ted"] = "225"
tUsers["Random"] = "555"
tUsers["OtherRandom"] = "PASSWORD"
while true do
    write("Username: ")
    name = read()
    if tUsers[name] then
	    term.setCursorPos(1,11)
	    write("Password: ")
	    pass = read("*")
	    if tUsers[name] == pass then
		    term.setCursorPos(10,9)
		    textutils.slowPrint("Access Approved")
		    sleep(2)
		    term.clear()
		    term.setCursorPos(1,1)
		    textutils.slowPrint("R.S. Incorporated Terminal")
		    term.setCursorPos(1,2)
		    print("----------------------------------------------------------")
		    term.setCursorPos(1,3)
		    textutils.slowPrint("Administrator: Full Access")
		    term.setCursorPos(1,4)
		    break
	    else
	    end
    end
    term.setCursorPos(10,9)
    textutils.slowPrint("Access Denied")
    sleep(2)
    os.reboot()
end