Advertisement
MavricMC

Bank Server Controller

Aug 21st, 2022 (edited)
1,760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. --Must be called control.lua--
  2.  
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5.  
  6. local ATM = "server"
  7. local drive = "bottom"
  8.  
  9. while true do
  10.     term.setTextColor(colors.yellow)
  11.     print("For balance type 1, for deposit type 2")
  12.     print("For withdraw type 3, for transfer type 4")
  13.     print("For add account type 5")
  14.     term.setTextColor(1)
  15.     local txt = read()
  16.     if txt == "1" or txt == "2" or txt == "3" or txt == "4" or txt == "5" then
  17.         print("Please enter the card")
  18.         while disk.isPresent(drive) == false do
  19.             sleep(0.1)
  20.         end
  21.         local id = disk.getID(drive)
  22.         disk.eject(drive)
  23.         if id == nil then
  24.             printError("Must be valid card")
  25.         else
  26.             print("Please enter 5 number pin")
  27.             local pin = read("*")
  28.             if (tonumber(pin)) then
  29.                 if string.len(pin) ~= 5 then
  30.                     printError("Must be 5 numbers")
  31.                 else
  32.                     if txt == "1" then
  33.                         print(bankAPI.balance(id, ATM, pin))
  34.                     elseif txt == "2" then
  35.                         print("Please enter deposit amount")
  36.                         local amount = read()
  37.                         if (tonumber(amount)) then
  38.                             amount = tonumber(amount)
  39.                             print(bankAPI.deposit(id, amount, ATM, pin))
  40.                         else
  41.                             printError("Must be a number")
  42.                         end
  43.                     elseif txt == "3" then
  44.                         print("Please enter withdraw amount")
  45.                         local amount = read()
  46.                         if (tonumber(amount)) then
  47.                             amount = amount tonumber(amount)
  48.                             print(bankAPI.withdraw(id, amount, ATM, pin))
  49.                         else
  50.                             printError("Must be a number")
  51.                         end
  52.                     elseif txt == "4" then
  53.                         print("Please enter the amount")
  54.                         local amount = read()
  55.                         if (tonumber(amount)) then
  56.                             print("Please enter id to transfer to")
  57.                             local id2 = read()
  58.                             if (tonumber(id2)) then
  59.                                 id2 = tonumber(id2)
  60.                                 print(bankAPI.transfer(id, id2, amount, ATM, pin))
  61.                             else
  62.                                 printError("Must be a valid id")
  63.                             end
  64.                            
  65.                         else
  66.                             printError("Must be a number")
  67.                         end
  68.                     elseif txt == "5" then    
  69.                         print(bankAPI.create(id, ATM, pin))
  70.                     end
  71.                 end
  72.             else
  73.                 printError("Must be a number")
  74.             end
  75.         end
  76.     else
  77.         printError("Must be a number from the list")
  78.     end
  79. end
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement