Advertisement
Guest User

startup

a guest
Jun 16th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.19 KB | None | 0 0
  1. local oldPullEvent = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3. breakclause = true
  4. while breakclause do
  5.  
  6.  local file = fs.open(usernamedata,"r")
  7.  local data = file.readAll()
  8.  file.close()
  9.  return textutils.unserialize(data)
  10.  file = fs.open(passworddata,"r")
  11.  file.close()
  12.  return textutils.unserialize(data)
  13.  file = fs.open(amountdata,"r")
  14.  file.close()
  15.  return textutils.unserialize(data)
  16.  
  17.  term.clear()
  18.  term.setCursorPos(1,1)
  19.  print("Welcome to VolcBank's Automated Teller System.")
  20.  print("Please Select an option.")
  21.  print("[1] Login")
  22.  print("[2] Create a New Account")
  23.  local startinput = read()
  24.  if startinput == "CactiJammer" then
  25.   print("Terminated")
  26.   breakclause = false
  27.  elseif startinput == "1" then
  28.   term.clear()
  29.   term.setCursorPos(1,1)
  30.  
  31.    print("Please Login Below.")
  32.    write("Username: ")
  33.    user = read()
  34.    write("Password: ")
  35.    pass = read("*")
  36.    for i,v in ipairs(usernames) do
  37.     if user == v then
  38.      validuser = true
  39.     end
  40.     if validuser == true then
  41.      if pass == passwords[i] then
  42.       print("Logging in...")
  43.       sleep(1)
  44.       while true do
  45.        term.clear()
  46.        term.setCursorPos(1,1)
  47.        print("What would you like to do today, "..usernames[i].."?")
  48.        print("[1] Check Amount in Account")
  49.        print("[2] Deposit")
  50.        print("[3] Withdraw")
  51.        print("[4] Change Password")
  52.        print("[5] Logout")
  53.        local input2 = read()
  54.        if input2 == "1" then
  55.         term.clear()
  56.         term.setCursorPos(1,1)
  57.         print("Amount in Account: "..amounts[i].."IC.")
  58.         print("To deposit or withdraw, please return to the main page and select their corresponding options.")
  59.         sleep(3)
  60.         textutils.slowPrint("Returning to main page...")
  61.         sleep(2)
  62.        elseif input2 == "2" then
  63.         term.clear()
  64.         term.setCursorPos(1,1)
  65.         print("How much would you like to deposit?")
  66.         depamt = read()
  67.         amounts[i] = amounts[i]+depamt
  68.         print("Please place amount of IC deposited into chest above. When finished, type \"1\".")
  69.         local depositans = read()
  70.         if depositans == "1" then
  71.          for num=1,depamt do
  72.           rs.setOutput("back",true)
  73.           sleep(1)
  74.           rs.setOutput("back",false)
  75.           num=num+1
  76.          end
  77.          sleep(1)
  78.          print("You now have "..amounts[i].."IC in your account.")
  79.          sleep(2)
  80.          textutils.slowPrint("Returning to main page...")
  81.          sleep(2)
  82.         end
  83.        elseif input2 == "3" then
  84.         term.clear()
  85.         term.setCursorPos(1,1)
  86.         print("How much would you like to withdraw?")
  87.         wdamt = read()
  88.         if amounts[i]-wdamt ~= 0 then
  89.          print("Error: withdrawal amount is less than amount in account. Please enter a different amount.")
  90.          wdamt = read()
  91.         else
  92.          amounts[i] = amounts[i]-wdamt
  93.          for num = 1,wdamt do
  94.           rs.setOutput("bottom",true)
  95.           sleep(1)
  96.           rs.setOutput("bottom",false)
  97.           num=num+1
  98.          end
  99.          sleep(1)
  100.          print("You now have "..amounts[i].."IC in your account.")
  101.          sleep(3)
  102.          textutils.slowPrint("Returning to main page...")
  103.          sleep(2)
  104.         end
  105.        elseif input2 == "4" then
  106.         term.clear()
  107.         term.setCursorPos(1,1)
  108.         write("Enter your current password: ")
  109.         currpass = read("*")
  110.         if currpass == passwords[i] then
  111.          write("Enter new password: ")
  112.          newpass = read("*")
  113.          write("Re-enter new password: ")
  114.          newpass2 = read("*")
  115.          if newpass == newpass2 then
  116.           passwords[i] = newpass
  117.           print("Password changed. Please login with your new details.")
  118.           sleep(3)
  119.           os.reboot()
  120.          else
  121.           print("New passwords do not match.")
  122.           sleep(1)
  123.          end
  124.         else
  125.          print("Password is incorrect. Please re-enter password.")
  126.          sleep(3)
  127.         end
  128.        elseif input2 == "5" then
  129.         save(usernames,usernamedata)
  130.         save(passwords,passworddata)
  131.         save(amounts.amountdata)
  132.         print("Thank you for banking with VolcBank.")
  133.         sleep(3)
  134.         os.reboot()
  135.        else
  136.         print("Error: invalid command.")
  137.         sleep(1)
  138.        end
  139.       end
  140.      else
  141.       print("Invalid username or password. Please try again.")
  142.       sleep(2)
  143.      end
  144.     else
  145.      print("Error: user not found.")
  146.      sleep(2)
  147.     end
  148.    end  
  149.  elseif startinput == "2" then
  150.   while true do
  151.    term.clear()
  152.    term.setCursorPos(1,1)
  153.    print("Thank you for choosing VolcBank. Enter your details below.")
  154.    write("Username: ")
  155.    newuser = read()
  156.    write("Password: ")
  157.    newuserpass = read("*")
  158.    for i,v in ipairs(usernames) do
  159.     if newuser == v then
  160.      print("Error. Username already taken.")
  161.      sleep(2)
  162.     else
  163.      table.insert(usernames,newuser)
  164.      table.insert(passwords,newuserpass)
  165.      table.insert(amounts,64)
  166.      save(usernames,usernamedata)
  167.      save(passwords,passworddata)
  168.      save(amounts,amountdata)
  169.      print("New account created. Please login with new details to enter account.")
  170.      sleep(3)
  171.      os.reboot()
  172.     end
  173.    end
  174.   end
  175.  end
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement