Advertisement
RemiCraft

Bank Manual

Jun 30th, 2022 (edited)
448
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None
  1. --Variables--
  2. local userAccount
  3. local userPIN
  4. local userBalance
  5. local otherAccount
  6. local otherPIN
  7. local otherBalance
  8. local input
  9. local amount
  10.  
  11. --Basic Functions--
  12. local function Clear()
  13.     term.clear()
  14.     term.setCursorPos(1,1)
  15. end
  16.  
  17. --Bank Functions--
  18.  
  19. local function ReviewSend()
  20.     Clear()
  21.     term.write("Confirm Information")
  22.     term.setCursorPos(1,2)
  23.     term.write("Sending $" .. amount .. " to " .. otherAccount .. " from " .. userAccount)
  24.     term.setCursorPos(1,3)
  25.     term.write("Enter PIN To Authenticate Transaction:")
  26.     term.setCursorPos(1,4)
  27.     input = read("*")
  28.     if input == userPIN then
  29.         local UserFile = fs.open("accounts/" .. userAccount, "w")
  30.         UserFile.writeLine(userAccount)
  31.         UserFile.writeLine(userPIN)
  32.         userBalance = tostring(tonumber(userBalance) - tonumber(amount))
  33.         UserFile.writeLine(userBalance)
  34.         UserFile.close()
  35.         local OtherFile = fs.open("accounts/" .. otherAccount, "w")
  36.         OtherFile.writeLine(otherAccount)
  37.         OtherFile.writeLine(otherPIN)
  38.         otherBalance = tostring(tonumber(otherBalance) + tonumber(amount))
  39.         OtherFile.writeLine(otherBalance)
  40.         OtherFile.close()
  41.     else
  42.         term.setCursorPos(1,4)
  43.         term.write("Incorrect PIN")
  44.         os.sleep(2)
  45.         ReviewSend()
  46.     end
  47.     os.reboot()
  48.  
  49. end
  50.  
  51. local function SendMoney()
  52.     Clear()
  53.     term.write("Input Account Name:")
  54.     term.setCursorPos(1,2)
  55.     userAccount = read()
  56.     if fs.exists("accounts/" .. userAccount) then
  57.         local UserFile = fs.open("accounts/" .. userAccount, "r")
  58.         UserFile.readLine()
  59.         userPIN = UserFile.readLine()
  60.         userBalance = UserFile.readLine()
  61.         UserFile.close()
  62.         term.setCursorPos(1,3)
  63.         term.write("Input Account To Send Money To:")
  64.         term.setCursorPos(1,4)
  65.         otherAccount = read()
  66.         if fs.exists("accounts/" .. otherAccount) then
  67.             local OtherFile = fs.open("accounts/" .. otherAccount, "r")
  68.             OtherFile.readLine()
  69.             otherPIN = OtherFile.readLine()
  70.             otherBalance = OtherFile.readLine()
  71.             OtherFile.close()
  72.             term.setCursorPos(1,5)
  73.             term.write("Input Amount Of Money To Send:")
  74.             term.setCursorPos(1,6)
  75.             amount = read()
  76.             if tonumber(amount) <= tonumber(userBalance) then
  77.                 ReviewSend()
  78.             else
  79.                 term.setCursorPos(1,7)
  80.                 term.write("Insufficient Funds")
  81.                 os.sleep(2)
  82.                 SendMoney()
  83.             end
  84.         else
  85.             term.setCursorPos(1,3)
  86.             term.write("Account Not Found")
  87.             os.sleep(2)
  88.             SendMoney()
  89.         end
  90.     else
  91.         term.setCursorPos(1,3)
  92.         term.write("Account Not Found")
  93.         os.sleep(2)
  94.         SendMoney()
  95.     end
  96. end
  97.  
  98. local function RecieveMoney()
  99.     Clear()
  100.     term.write("Coming Soon!")
  101.     os.sleep(3)
  102.     os.reboot()
  103. end
  104.  
  105. local function CheckBalance()
  106.     Clear()
  107.     term.write("Input Account Name:")
  108.     term.setCursorPos(1,2)
  109.     userAccount = read()
  110.     if fs.exists("accounts/" .. userAccount) then
  111.         local UserFile = fs.open("accounts/" .. userAccount, "r")
  112.         UserFile.readLine()
  113.         userPIN = UserFile.readLine()
  114.         userBalance = UserFile.readLine()
  115.         UserFile.close()
  116.     else
  117.         term.setCursorPos(1,3)
  118.         term.write("Account Not Found")
  119.         os.sleep(2)
  120.         CheckBalance()
  121.     end
  122.     term.setCursorPos(1,3)
  123.     term.write("Enter PIN")
  124.     term.setCursorPos(1,4)
  125.     input = read("*")
  126.     if input == userPIN then
  127.         term.setCursorPos(1,5)
  128.         term.write("Account Balance: " .. userBalance)
  129.     else
  130.         term.setCursorPos(1,5)
  131.         term.write("Incorrect PIN")
  132.         os.sleep(2)
  133.         CheckBalance()
  134.     end
  135.     term.setCursorPos(1,6)
  136.     term.write("Press Any Key To Continue")
  137.     os.pullEvent("key")
  138.     os.reboot()
  139. end
  140.  
  141. Clear()
  142. term.write("1). Send Money")
  143. term.setCursorPos(1,2)
  144. term.write("2). Recieve Money")
  145. term.setCursorPos(1,3)
  146. term.write("3). Check Balance")
  147. term.setCursorPos(1,4)
  148. input = read()
  149. if input == "1" then
  150.     SendMoney()
  151. elseif input == "2" then
  152.     RecieveMoney()
  153. elseif input == "3" then
  154.     CheckBalance()
  155. else
  156.     os.reboot()
  157. end
  158.  
Advertisement
RAW Paste Data Copied
Advertisement