Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Accounts File
- Written by TheShadow989
- ]]--
- os.pullEvent = os.pullEventRaw
- local verNumber = "Alpha 1.24"
- local nOption = 1
- local z = 1
- userfinal = {}
- userlenght = {}
- rRead = fs.open("xos/.usertable", "r")
- users = textutils.unserialize(rRead.readAll())
- rRead.close()
- cu = tonumber(users[1])
- cs = tonumber(users[cu+1])
- cp = tonumber(users[cu+2])
- if users[5] == nil then
- users[5] = "Empty"
- end
- if users[8] == nil then
- users[8] = "Empty"
- end
- if users[11] == nil then
- users[11] = "Empty"
- end
- userlenght[1] = string.len(users[2])
- userlenght[2] = string.len(users[5])
- userlenght[3] = string.len(users[8])
- userlenght[4] = string.len(users[11])
- for i=2, 11, 3 do
- if userlenght[z] == 9 then
- userfinal[z] = ""..users[i]..""
- elseif userlenght[z] == 8 then
- userfinal[z] = ""..users[i].." "
- elseif userlenght[z] == 7 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 6 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 5 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 4 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 3 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 2 then
- userfinal[z] = " "..users[i].." "
- elseif userlenght[z] == 1 then
- userfinal[z] = " "..users[i].." "
- end
- z = z + 1
- end
- local w,h = term.getSize()
- local function drawMenu()
- local time = os.time()
- local formattedTime = textutils.formatTime(time, false)
- term.clear()
- term.setCursorPos(1,1)
- term.write("Logged in as: ")
- term.setTextColor( colors.red )
- term.write(""..users[cu].."")
- term.setTextColor( colors.white )
- term.setCursorPos(1,2)
- write(formattedTime)
- term.setCursorPos(1,19)
- term.write("xOS "..verNumber.." by TheShadow989")
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write(""..users[2].."")
- elseif nOption == 2 then
- term.write(""..users[5].."")
- elseif nOption == 3 then
- term.write(""..users[8].."")
- elseif nOption == 4 then
- term.write(""..users[11].."")
- elseif nOption == 5 then
- term.write("Remove")
- elseif nOption == 6 then
- term.write("Back")
- end
- end
- function printCentered(y,s)
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write( s )
- end
- term.clear()
- local function drawFrontend()
- printCentered( math.floor(h/2) - 4, "")
- printCentered( math.floor(h/2) - 3, "Accounts" )
- printCentered( math.floor(h/2) - 2, "")
- printCentered( math.floor(h/2) - 1, ((nOption == 1) and "["..userfinal[1].."]") or userfinal[1] )
- printCentered( math.floor(h/2) + 0, ((nOption == 2) and "["..userfinal[2].."]") or userfinal[2] )
- printCentered( math.floor(h/2) + 1, ((nOption == 3) and "["..userfinal[3].."]") or userfinal[3] )
- printCentered( math.floor(h/2) + 2, ((nOption == 4) and "["..userfinal[4].."]") or userfinal[4] )
- printCentered( math.floor(h/2) + 3, "")
- printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ Remove ]") or " Remove " )
- printCentered( math.floor(h/2) + 5, ((nOption == 6) and "[ Back ]") or " Back " )
- end
- local function errormsg()
- local time = os.time()
- local formattedTime = textutils.formatTime(time, false)
- term.setCursorPos(1,1)
- term.write("Logged in as: ")
- term.setTextColor( colors.red )
- term.write(""..users[cu].."")
- term.setTextColor( colors.white )
- term.setCursorPos(1,2)
- write(formattedTime)
- term.setCursorPos(1,19)
- term.write("xOS "..verNumber.." by TheShadow989")
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write(""..users[2].."")
- elseif nOption == 2 then
- term.write(""..users[5].."")
- elseif nOption == 3 then
- term.write(""..users[8].."")
- elseif nOption == 4 then
- term.write(""..users[11].."")
- end
- term.setCursorPos(11,8)
- term.setTextColor( colors.red )
- write("This slot is already occupied!")
- term.setTextColor( colors.white )
- sleep(2)
- shell.run("xos/.accounts")
- end
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == 17 or key == 200 then
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 31 or key == 208 then
- if nOption < 6 then
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 28 then
- break
- end
- end
- end
- term.clear()
- if nOption == 1 then
- errormsg()
- elseif nOption == 2 then
- if users[5] == "Empty" then
- shell.run("xos/.addaccounts")
- else
- errormsg()
- end
- elseif nOption == 3 then
- if users[8] == "Empty" then
- shell.run("xos/.addaccounts")
- else
- errormsg()
- end
- elseif nOption == 4 then
- if users[11] == "Empty" then
- shell.run("xos/.addaccounts")
- else
- errormsg()
- end
- elseif nOption == 5 then
- shell.run("xos/.removeaccounts")
- elseif nOption == 6 then
- shell.run("back")
- end
Add Comment
Please, Sign In to add comment