Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables--
- local userAccount
- local userPIN
- local userBalance
- local otherAccount
- local otherPIN
- local otherBalance
- local input
- local amount
- --Basic Functions--
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --Bank Functions--
- local function ReviewSend()
- Clear()
- term.write("Confirm Information")
- term.setCursorPos(1,2)
- term.write("Sending $" .. amount .. " to " .. otherAccount .. " from " .. userAccount)
- term.setCursorPos(1,3)
- term.write("Enter PIN To Authenticate Transaction:")
- term.setCursorPos(1,4)
- input = read("*")
- if input == userPIN then
- local UserFile = fs.open("accounts/" .. userAccount, "w")
- UserFile.writeLine(userAccount)
- UserFile.writeLine(userPIN)
- userBalance = tostring(tonumber(userBalance) - tonumber(amount))
- UserFile.writeLine(userBalance)
- UserFile.close()
- local OtherFile = fs.open("accounts/" .. otherAccount, "w")
- OtherFile.writeLine(otherAccount)
- OtherFile.writeLine(otherPIN)
- otherBalance = tostring(tonumber(otherBalance) + tonumber(amount))
- OtherFile.writeLine(otherBalance)
- OtherFile.close()
- else
- term.setCursorPos(1,4)
- term.write("Incorrect PIN")
- os.sleep(2)
- ReviewSend()
- end
- os.reboot()
- end
- local function SendMoney()
- Clear()
- term.write("Input Account Name:")
- term.setCursorPos(1,2)
- userAccount = read()
- if fs.exists("accounts/" .. userAccount) then
- local UserFile = fs.open("accounts/" .. userAccount, "r")
- UserFile.readLine()
- userPIN = UserFile.readLine()
- userBalance = UserFile.readLine()
- UserFile.close()
- term.setCursorPos(1,3)
- term.write("Input Account To Send Money To:")
- term.setCursorPos(1,4)
- otherAccount = read()
- if fs.exists("accounts/" .. otherAccount) then
- local OtherFile = fs.open("accounts/" .. otherAccount, "r")
- OtherFile.readLine()
- otherPIN = OtherFile.readLine()
- otherBalance = OtherFile.readLine()
- OtherFile.close()
- term.setCursorPos(1,5)
- term.write("Input Amount Of Money To Send:")
- term.setCursorPos(1,6)
- amount = read()
- if tonumber(amount) <= tonumber(userBalance) then
- ReviewSend()
- else
- term.setCursorPos(1,7)
- term.write("Insufficient Funds")
- os.sleep(2)
- SendMoney()
- end
- else
- term.setCursorPos(1,3)
- term.write("Account Not Found")
- os.sleep(2)
- SendMoney()
- end
- else
- term.setCursorPos(1,3)
- term.write("Account Not Found")
- os.sleep(2)
- SendMoney()
- end
- end
- local function RecieveMoney()
- Clear()
- term.write("Coming Soon!")
- os.sleep(3)
- os.reboot()
- end
- local function CheckBalance()
- Clear()
- term.write("Input Account Name:")
- term.setCursorPos(1,2)
- userAccount = read()
- if fs.exists("accounts/" .. userAccount) then
- local UserFile = fs.open("accounts/" .. userAccount, "r")
- UserFile.readLine()
- userPIN = UserFile.readLine()
- userBalance = UserFile.readLine()
- UserFile.close()
- else
- term.setCursorPos(1,3)
- term.write("Account Not Found")
- os.sleep(2)
- CheckBalance()
- end
- term.setCursorPos(1,3)
- term.write("Enter PIN")
- term.setCursorPos(1,4)
- input = read("*")
- if input == userPIN then
- term.setCursorPos(1,5)
- term.write("Account Balance: " .. userBalance)
- else
- term.setCursorPos(1,5)
- term.write("Incorrect PIN")
- os.sleep(2)
- CheckBalance()
- end
- term.setCursorPos(1,6)
- term.write("Press Any Key To Continue")
- os.pullEvent("key")
- os.reboot()
- end
- Clear()
- term.write("1). Send Money")
- term.setCursorPos(1,2)
- term.write("2). Recieve Money")
- term.setCursorPos(1,3)
- term.write("3). Check Balance")
- term.setCursorPos(1,4)
- input = read()
- if input == "1" then
- SendMoney()
- elseif input == "2" then
- RecieveMoney()
- elseif input == "3" then
- CheckBalance()
- else
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement