Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ATM version 0.1.2--
- --Must be startup program--
- os.pullEvent = os.pullEventRaw
- local vers = "0.1.2"
- --Settings--
- local server = 0
- local atm = "atm_1"
- local bankSide = "modem_0"
- local drive = "bottom"
- local chests = {"minecraft:chest_0"}
- local dropper = "minecraft:dropper_0"
- local junk = "minecraft:dropper_1"
- local logFile = "log"
- local enableLogging = true
- local coin = "minecraft:diamond"
- local coinValue = 1 --How much currency each physical coin is worth. Values other than one will cause both currency and coin amounts to be displayed. greater or less than 1 work
- local withdrawFee = 0 -- 0.05 = 5% --Percentage of coin withheld at withdrawl. When set to 0 fee calculation will not be displayed
- local transferFee = 0 -- 0.1 = 10% --Percentage of currecy withheld at transfer. When set to 0 fee calculation will not be displayed
- local transferMax = 1000 -- Max amount that a transfer can be
- local allowSignUp = true
- local backgroundColour = colors.black
- local bankTimeout = 10 --How many seconds the bank function will wait before timing out
- local enableReceipt = false
- local printer = "printer_0"
- local inkStorage = "minecraft:chest_0"
- local textColour = "minecraft:black_dye"
- local output = drive --Drive must be connected to the wired modem and drive must be "drive_0" or similar. Drive as simply "bottom" wont work
- --Default config is: Each page is moved to drive and ejected. If you want something else, then change the output and edit sendToOutput()
- --Also add some code to the end of printReceipt() when sendToOutput() is run for thne last time. Eg: If you want to output all pages at once or bind them together
- --Button settings. Changes to any setting will not break click detection
- local doneButton = {"Done", 23, 10, colors.blue, colors.white} --Text, lop left x and y, background color, text color
- local createButton = {"Sign Up", 39, 15, colors.blue, colors.white}
- local receiptButton = {"Recepit", 39, 15, colors.blue, colors.white}
- local mainButtons = {
- {"Deposit", 10, 10, colors.green, colors.white},
- {"Withdraw", 21, 10, colors.red, colors.white},
- {"Transfer", 33, 10, colors.lightBlue, colors.white}
- }
- local backupDyes = { --Fallback dyes for if the correct dye is not found. White dye is illegible
- "minecraft:light_gray_dye",
- "minecraft:gray_dye",
- "minecraft:black_dye",
- "minecraft:brown_dye",
- "minecraft:red_dye",
- "minecraft:orange_dye",
- "minecraft:yellow_dye",
- "minecraft:lime_dye",
- "minecraft:green_dye",
- "minecraft:cyan_dye",
- "minecraft:light_blue_dye",
- "minecraft:blue_dye",
- "minecraft:purple_dye",
- "minecraft:magenta_dye",
- "minecraft:pink_dye"
- }
- --Vars--
- local d = peripheral.wrap(dropper)
- local j = peripheral.wrap(junk)
- local screen = 0
- local padAmm = ""
- local pin = ""
- local afterFees = 0
- local padAcc = ""
- local tranFee = 0
- local transActionList = {}
- local newSession = true
- local p
- local s
- if (enableReceipt) then
- p = peripheral.wrap(printer)
- s = peripheral.wrap(inkStorage)
- end
- if (enableLogging) then
- os.loadAPI("json.lua") --No need to load up json api and waste ram if not logging json
- end
- --Functions--
- --From pullapi--
- function getStored()
- local count = 0
- for _, v in pairs(chests) do
- cs = peripheral.wrap(v)
- for k2, v2 in pairs(cs.list()) do
- if v2.name == coin then
- count = count + v2.count
- else
- j.pullItems(v, k2, v2.count)
- end
- end
- end
- return count
- end
- function pullapideposit()
- local count = 0
- for _, v in pairs(chests) do
- for i = 1, 9 do
- local tab = d.getItemDetail(i)
- if tab ~= nil then
- if tab.name == coin then
- local deped = d.pushItems(v, i, 64)
- count = count + deped
- else
- d.pushItems(junk, i, 64)
- end
- end
- end
- end
- if count > 0 then
- return true, count
- else
- return false, "Ammount enterd must be more than 0"
- end
- end
- function pullapiwithdraw(amount)
- if amount > 576 then
- return false, "Amount must be at maximum 9 stacks or 576 items"
- end
- if amount > getStored() then
- return false, "Not enough in storage"
- end
- local count = 0
- for _, v in pairs(chests) do
- cs = peripheral.wrap(v)
- for i = 1, 54 do
- tab = cs.getItemDetail(i)
- if tab ~= nil then
- if tab.name == coin then
- if (count + tab.count) > amount then
- d.pullItems(v, i, (amount - count))
- return true
- else
- d.pullItems(v, i, tab.count)
- count = count + tab.count
- end
- if count == amount then
- return true
- end
- else
- j.pullItems(chests, i, 64)
- end
- end
- end
- end
- end
- --From api--
- function smallLogo(x, y)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(x + 2, y)
- term.write("\134")
- term.setCursorPos(x, y + 2)
- term.write("\134")
- term.setTextColor(1)
- term.setCursorPos(x + 1, y + 1)
- term.write("M")
- term.setTextColor(colors.cyan)
- term.setCursorPos(x + 3, y)
- term.write("\134")
- term.setCursorPos(x + 1, y + 2)
- term.write("\134")
- term.setTextColor(1)
- term.setCursorPos(x + 2, y + 1)
- term.write("P")
- term.setTextColor(colors.blue)
- term.setCursorPos(x + 4, y)
- term.write("\134")
- term.setCursorPos(x + 2, y + 2)
- term.write("\134")
- term.setTextColor(1)
- term.setCursorPos(x + 3, y + 1)
- term.write("N")
- end
- function clear(col, exit, small, id)
- term.setBackgroundColor(col)
- term.setTextColor(colors.yellow)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("ATM ".. vers)
- term.setCursorPos(1, 19)
- term.setTextColor(colors.lightGray)
- term.write("Made By Mavric, Please Report Bugs")
- term.setTextColor(colors.white)
- if (small) then
- smallLogo(46, 2)
- end
- if (exit) then
- term.setBackgroundColor(colors.red)
- term.setTextColor(1)
- term.setCursorPos(49, 17)
- term.write("X")
- term.setBackgroundColor(colors.black)
- end
- if id >= 0 then --Use -1 to disable
- term.setBackgroundColor(col)
- term.setTextColor(colours.lime)
- term.setCursorPos(1, 3)
- term.write("ID: ".. id)
- end
- end
- function balance(account, ATM, pin)
- local msg = {"bal", account, ATM, pin, getStored(), coinValue, coin}
- rednet.send(server, msg, "banking")
- local send, mes, pro = rednet.receive("banking", bankTimeout)
- if not send then
- return false, "timeout"
- else
- if mes[1] == "balR" then
- return mes[2], mes[3]
- end
- end
- return false, "oof"
- end
- function deposit(account, amount, ATM, pin)
- local msg = {"dep", account, amount, ATM, pin, getStored(), coinValue, coin}
- rednet.send(server, msg, "banking")
- local send, mes, pro = rednet.receive("banking", bankTimeout)
- if not send then
- return false, "timeout"
- else
- if mes[1] == "depR" then
- return mes[2], mes[3]
- end
- end
- return false, "oof"
- end
- function withdraw(account, amount, ATM, pin)
- local msg = {"wit", account, amount, ATM, pin, getStored(), coinValue, coin}
- rednet.send(server, msg, "banking")
- local send, mes, pro = rednet.receive("banking", bankTimeout)
- if not send then
- return false, "timeout"
- else
- if mes[1] == "witR" then
- return mes[2], mes[3], amount
- end
- end
- return false, "oof"
- end
- function transfer(account, account2, amount, ATM, pin)
- local msg = {"tra", account, account2, amount, ATM, pin, getStored(), coinValue, coin}
- rednet.send(server, msg, "banking")
- local send, mes, pro = rednet.receive("banking", bankTimeout)
- if not send then
- return false, "timeout"
- else
- if mes[1] == "traR" then
- return mes[2], mes[3]
- end
- end
- return false, "oof"
- end
- function create(account, ATM, pin)
- local msg = {"cre", account, ATM, pin, getStored(), coinValue, coin}
- rednet.send(server, msg, "banking")
- local send, mes, pro = rednet.receive("banking", bankTimeout)
- if not send then
- return false, "timeout"
- else
- if mes[1] == "creR" then
- return mes[2], mes[3]
- end
- end
- return false, "oof"
- end
- --From printer test--
- function prepForPrint()
- for i = 1, 13 do
- j.pullItems(peripheral.getName(p), i) --Empty printer
- end
- j.pullItems(peripheral.getName(s), s.size()) --Empty last slot in ink storage. Used as temporary storage by recycle()
- end
- function backupInk()
- for k, v in pairs(s.list()) do
- for _, v2 in pairs(backupDyes) do
- if v.name == v2 then
- s.pushItems(peripheral.getName(p), k, 1, 1)
- return true
- end
- end
- end
- return false
- end
- function addInk(name) --Add 1 ink of desired name to printer
- for k, v in pairs(s.list()) do
- if v.name == name then
- s.pushItems(peripheral.getName(p), k, 1, 1)
- return true
- end
- end
- return backupInk() --Get a dye if correct dye is not found
- end
- function addPaper() --Add 1 paper to printer
- for k, v in pairs(s.list()) do
- if v.name == "minecraft:paper" then
- s.pushItems(peripheral.getName(p), k, 1, 2)
- return true
- end
- end
- return false
- end
- function recycle() --Moves paper from output to input of printer for new ink
- s.pullItems(peripheral.getName(p), 8, 1, s.size())
- s.pushItems(peripheral.getName(p), s.size(), 1, 2)
- end
- function sendToOutput()
- p.endPage()
- s.pullItems(peripheral.getName(p), 8, 1, s.size())
- s.pushItems(output, s.size(), 1)
- --Change up the code here if outputing to something differnt
- if (output == drive) then --Dont eject if not outputing to drive
- disk.eject(output)
- end
- end
- function printDate(y, date)
- p.setCursorPos(16, y)
- p.write(string.format("%02d/", date.day))
- p.write(string.format("%02d/", date.month))
- p.write(date.year)
- end
- function printTime(y, time)
- p.setCursorPos(18, y)
- p.write(string.format("%02d:", time.hour))
- p.write(string.format("%02d:", time.min))
- p.write(string.format("%02d", time.sec))
- end
- function lineBreak(y)
- p.setCursorPos(1, y)
- p.write("\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140\140")
- end
- function startPage(number)
- prepForPrint()
- if (not addInk("minecraft:light_blue_dye")) then
- return false, "Out of ink: minecraft:light_blue_dye"
- end
- if (not addPaper()) then
- return false, "Out of paper"
- end
- p.newPage()
- p.setPageTitle(string.format("Receipt #%03d", number))
- p.setCursorPos(13, 1)
- p.write("\134")
- p.setCursorPos(11, 3)
- p.write("\134")
- p.setCursorPos(12, 2)
- p.write("M")
- p.endPage()
- if (not addInk("minecraft:cyan_dye")) then
- return false, "Out of ink: minecraft:cyan_dye"
- end
- recycle()
- p.newPage()
- p.setCursorPos(14, 1)
- p.write("\134")
- p.setCursorPos(12, 3)
- p.write("\134")
- p.setCursorPos(13, 2)
- p.write("P")
- p.endPage()
- if (not addInk("minecraft:blue_dye")) then
- return false, "Out of ink: minecraft:blue_dye"
- end
- recycle()
- p.newPage()
- p.setCursorPos(15, 1)
- p.write("\134")
- p.setCursorPos(13, 3)
- p.write("\134")
- p.setCursorPos(14, 2)
- p.write("N")
- if textColour ~= "minecraft:blue_dye" then --Dont waste blue dye
- p.endPage()
- if (not addInk(textColour)) then
- return false, "Out of ink: ".. textColour
- end
- recycle()
- p.newPage()
- end
- return true
- end
- function printReceipt(transAcs)
- drawScreen(9)
- local result, response = startPage(1)
- if (not result) then
- return false, response
- end
- p.setCursorPos(1, 4)
- p.write("ID")
- p.setCursorPos(1, 5)
- p.write(transAcs[1].card)
- p.setCursorPos(1, 7)
- p.write("Balance")
- p.setCursorPos(1, 8)
- p.write("$".. transAcs[1].startingBalance)
- p.setCursorPos(18, 4)
- p.write("Location")
- p.setCursorPos(26 - string.len(transAcs[1].location), 5)
- p.write(transAcs[1].location)
- printTime(7, transAcs[1].sessionStart)
- printDate(8, transAcs[1].sessionStart)
- lineBreak(9)
- local y = 10
- local page = 1
- for i = 2, table.maxn(transAcs) do
- if (y > 19) then
- page = page + 1
- y = 4
- sendToOutput()
- local result, response = startPage(page)
- if (not result) then
- return false, response
- end
- end
- p.setCursorPos(1, y)
- if transAcs[i].type == 0 then
- p.write("Deposit")
- elseif transAcs[i].type == 1 then
- p.write("Withdraw")
- elseif transAcs[i].type == 2 then
- p.write("Transfer")
- elseif transAcs[i].type == 1 then
- p.write("Item") --Write item title here
- elseif transAcs[i].type == 1 then
- p.write("Refund")
- else
- p.write("N/A")
- end
- p.setCursorPos(12, y)
- p.write("$".. transAcs[i].amount)
- p.setCursorPos(22, y)
- if transAcs[i].success then
- p.write("Pass")
- else
- p.write("Fail")
- end
- p.setCursorPos(1, y + 1)
- p.write(string.format("%02d/", transAcs[i].date.day))
- p.write(string.format("%02d/", transAcs[i].date.month))
- p.write(transAcs[i].date.year)
- printTime(y + 1, transAcs[i].date)
- if (transAcs[i].success) then
- if (transAcs[i].fee > 0) then
- local temp = "Fee $".. tostring(transAcs[i].fee)
- p.setCursorPos(26 - string.len(temp), y + 2)
- p.write(temp)
- end
- p.setCursorPos(1, y + 2)
- p.write("Bal $")
- else
- p.setCursorPos(1, y + 2)
- end
- p.write(transAcs[i].result)
- y = y + 4
- end
- if y > 20 then
- page = page + 1
- y = 4
- sendToOutput()
- local result, response = startPage(page)
- if (not result) then
- return false, response
- end
- else
- y = y - 1 --Remove the padding from for loop
- end
- lineBreak(y)
- p.setCursorPos(1, y + 1)
- p.write("Balance")
- p.setCursorPos(1, y + 2)
- p.write("$".. transAcs[1].finalBalance)
- local tempMsg = "Powered by MPN"
- p.setCursorPos(26 - string.len(tempMsg), y + 1)
- p.write(tempMsg)
- printTime(y + 2, transAcs[1].sessionEnd)
- sendToOutput()
- return true, page
- end
- --Normal--
- function cleanUp()
- if (transActionList[1] ~= nil) then
- transActionList[1].sessionEnd = os.date("*t")
- transActionList[1].receipt = false
- if (enableLogging) then
- local logLine = json.encode(transActionList)
- local log = fs.open(logFile, "a")
- log.writeLine(logLine)
- log.close()
- end
- transActionList ={}
- end
- pin = ""
- padAmm = ""
- padAcc = ""
- afterFees = 0
- tranFee = 0
- newSession = true
- drawScreen(0)
- end
- function writeCenter(text, y)
- term.setCursorPos(math.floor(26 - (string.len(text) / 2)), y)
- term.write(text)
- end
- function pinpad(key)
- if (key == ".") then
- return true, 10
- else
- if (tonumber(key)) then
- if tonumber(key) == 259 then
- return true, 10
- elseif (tonumber(key) == 257 or tonumber(key) == 335) then
- return true, 11
- elseif tonumber(key) >= 0 and tonumber(key) <= 9 then
- return true, tonumber(key)
- end
- end
- end
- return false
- end
- function drawButton(buttonArray)
- term.setBackgroundColor(buttonArray[4])
- term.setTextColor(buttonArray[4])
- term.setCursorPos(buttonArray[2], buttonArray[3])
- term.write("OO".. buttonArray[1])
- term.setCursorPos(buttonArray[2], buttonArray[3] + 1)
- term.write("O")
- term.setTextColor(buttonArray[5])
- term.write(buttonArray[1])
- term.setTextColor(buttonArray[4])
- term.write("O")
- term.setCursorPos(buttonArray[2], buttonArray[3] + 2)
- term.write("OO".. buttonArray[1])
- end
- function checkButton(x, y, buttonArray)
- if x >= buttonArray[2] and x < (buttonArray[2] + string.len(buttonArray[1]) + 2) and y >= buttonArray[3] and y < (buttonArray[3] + 3) then
- return true
- else
- return false
- end
- end
- function drawScreen(scrn)
- if ((scrn > 0 and (not disk.isPresent(drive))) and (not (scrn == 7))) then --Catch if disk was removed when sleeping or waiting for some code
- scrn = 0
- end
- if scrn == 0 then
- screen = 0
- term.setCursorBlink(false)
- clear(backgroundColour, false, false, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please insert card", 13)
- local pic = paintutils.loadImage("MPNLogo.nfp")
- paintutils.drawImage(pic, 18, 3)
- if (allowSignUp) then
- drawButton(createButton)
- end
- elseif scrn == 1 then
- screen = 1
- clear(backgroundColour, true, true, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.lime)
- writeCenter("ID: ".. acc, 5)
- term.setCursorPos(20, 9)
- term.setTextColor(1)
- term.write("PIN: ")
- term.setCursorBlink(true)
- pin = ""
- elseif scrn == 2 then
- screen = 2
- term.setCursorBlink(false)
- local suc, res = balance(acc, atm, pin)
- if (suc) then
- if (newSession) then
- transActionList = {{ card = acc, sessionStart = os.date("*t"), location = atm, startingBalance = res, finalBalance = res}}
- newSession = false
- else
- transActionList[1].finalBalance = res
- end
- disk.setLabel(drive, "ID:".. acc.." $".. tostring(res))
- clear(backgroundColour, true, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.lime)
- writeCenter("$".. res, 5)
- if (coinValue ~= 1) then
- writeCenter("In coins(3dp): ".. (math.floor((tonumber(res) / coinValue) * 100) / 100), 6)
- end
- for _, v in pairs(mainButtons) do
- drawButton(v)
- end
- if (enableReceipt) then
- drawButton(receiptButton)
- end
- else
- clear(backgroundColour, false, true, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Retrieving balance ID: ".. acc, 9)
- pin = ""
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.red)
- writeCenter(res, 10)
- sleep(3)
- cleanUp()
- disk.eject(drive)
- end
- elseif scrn == 3 then
- screen = 3
- term.setCursorBlink(false)
- clear(backgroundColour, true, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please insert coins into dropper", 5)
- writeCenter("then click done", 6)
- drawButton(doneButton)
- elseif scrn == 4 then
- screen = 4
- clear(backgroundColour, true, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please enter the ammount of coins", 5)
- writeCenter("you want to withdraw", 6)
- if withdrawFee > 0 then
- term.setCursorPos(20, 10)
- term.write("Fee: 0 (".. (100 * withdrawFee).. "%)")
- term.setCursorPos(20, 11)
- term.write("Res: 0")
- end
- term.setCursorPos(20, 9)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.write("Amm: ")
- term.setCursorBlink(true)
- padAmm = ""
- elseif scrn == 5 then
- screen = 5
- clear(backgroundColour, true, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please enter the ammount of currency", 5)
- writeCenter("you want to transfer", 6)
- if transferFee > 0 then
- term.setCursorPos(20, 10)
- term.write("Fee $0 (".. (100 * transferFee).. "%)")
- term.setCursorPos(20, 11)
- term.write("Res $0")
- end
- term.setCursorPos(20, 9)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.write("Amm $")
- term.setCursorBlink(true)
- padAmm = ""
- elseif scrn == 6 then
- screen = 6
- clear(backgroundColour, true, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please enter the account number you", 5)
- writeCenter("want to transfer to", 6)
- term.setCursorPos(20, 9)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.write("Acc: ")
- term.setCursorBlink(true)
- padAcc = ""
- elseif scrn == 7 then
- screen = 7
- term.setCursorBlink(false)
- clear(backgroundColour, true, true, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Please insert card for new account", 9)
- elseif scrn == 8 then
- screen = 8
- clear(backgroundColour, true, true, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.lime)
- writeCenter("ID: ".. acc, 5)
- term.setCursorPos(16, 9)
- term.setTextColor(1)
- term.write("New PIN: ")
- term.setCursorBlink(true)
- pin = ""
- elseif scrn == 9 then
- screen = 9
- term.setCursorBlink(false)
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Printing receipt", 9)
- end
- end
- function checkX(bX, bY)
- if (bX == 49 and bY == 17) then
- return true
- end
- end
- --Setup--
- rednet.open(bankSide)
- drawScreen(0)
- --MainLoop--
- while true do
- event = {os.pullEvent()}
- if (event[1] == "terminate") then
- if (redstone.getInput("right")) then
- return
- end
- elseif (event[1] == "disk") then
- if (event[2] == drive) then --Only respond to messages from the configured disk drive
- acc = disk.getID(drive)
- if acc ~= nil then
- if (screen == 0) then
- drawScreen(1)
- elseif (screen == 7) then
- drawScreen(8)
- else --Something weird has happened
- cleanUp()
- disk.eject(drive)
- end
- end
- end
- elseif (event[1] == "disk_eject") then
- if (event[2] == drive) then --Only respond to messages from the configured disk drive
- cleanUp()
- end
- elseif (event[1] == "mouse_click") then
- if screen == 0 then
- if (allowSignUp) then
- if checkButton(event[3], event[4], createButton) then
- drawScreen(7)
- end
- end
- elseif (screen == 1) then
- if (checkX(event[3], event[4])) then
- cleanUp()
- disk.eject(drive)
- end
- elseif screen == 2 then
- if (checkX(event[3], event[4])) then
- cleanUp()
- disk.eject(drive)
- elseif checkButton(event[3], event[4], receiptButton) then
- if (enableReceipt) then
- disk.eject(drive)
- if (transActionList[1] ~= nil) then
- transActionList[1].sessionEnd = os.date("*t")
- local result, response = printReceipt(transActionList)
- if (not result) then
- term.setTextColor(colours.red)
- writeCenter(response, 10)
- sleep(3)
- end
- transActionList[1].receipt = true
- transActionList[1].receiptSuccess = result
- transActionList[1].receiptResult = response
- if (enableLogging) then
- local logLine = json.encode(transActionList)
- local log = fs.open(logFile, "a")
- log.writeLine(logLine)
- log.close()
- end
- end
- transActionList ={}
- pin = ""
- padAmm = ""
- padAcc = ""
- afterFees = 0
- tranFee = 0
- newSession = true
- drawScreen(0)
- end
- else
- for _, v in pairs(mainButtons) do
- if checkButton(event[3], event[4], v) then
- if v[1] == "Deposit" then
- drawScreen(3)
- elseif v[1] == "Withdraw" then
- drawScreen(4)
- elseif v[1] == "Transfer" then
- drawScreen(5)
- end
- end
- end
- end
- elseif screen == 3 then
- if (checkX(event[3], event[4])) then
- drawScreen(2)
- else
- if checkButton(event[3], event[4], doneButton) then
- isDep, dep = pullapideposit()
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- if (isDep) then
- term.setTextColor(1)
- writeCenter("Depositing $".. (dep * coinValue).. " into you account", 9)
- local isDep, dep2 = deposit(acc, (dep * coinValue), atm, pin)
- local temp = { type = 0, date = os.date("*t"), amount = (dep * coinValue), fee = 0, success = isDep, result = tostring(dep2)}
- table.insert(transActionList, temp)
- if (isDep) then
- disk.setLabel(drive, "$".. tostring(dep2))
- term.setTextColor(colours.green)
- writeCenter("Success", 10)
- else
- term.setTextColor(colours.red)
- writeCenter(dep2, 10)
- pullapiwithdraw(dep)
- end
- else
- term.setTextColor(colours.red)
- writeCenter(dep, 9)
- end
- sleep(3)
- drawScreen(2)
- end
- end
- elseif (screen == 4 or screen == 5 or screen == 6) then
- if (checkX(event[3], event[4])) then
- drawScreen(2)
- end
- elseif (screen == 7 or screen == 8) then
- if (checkX(event[3], event[4])) then
- cleanUp()
- disk.eject(drive)
- end
- end
- elseif (event[1] == "char" or event[1] == "key") then
- if screen == 1 then
- local isKey, keyNum = pinpad(event[2])
- if (isKey) then
- if keyNum == 10 then
- if string.len(pin) > 0 then
- pin = string.sub(pin, 1, string.len(pin) - 1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(20, 9)
- term.clearLine()
- term.write("PIN: ".. string.sub("****", 1, string.len(pin)))
- end
- elseif keyNum == 11 then
- if string.len(pin) == 5 then
- drawScreen(2)
- end
- elseif keyNum >= 0 and keyNum <= 9 then
- if string.len(pin) < 5 then
- pin = pin.. keyNum
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(24 + string.len(pin), 9)
- term.write("*")
- end
- end
- end
- elseif screen == 4 then
- local isKey, keyNum = pinpad(event[2])
- if (isKey) then
- if keyNum == 10 then
- if string.len(padAmm) > 0 then
- padAmm = string.sub(padAmm, 1, string.len(padAmm) - 1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- if withdrawFee > 0 then
- term.setCursorPos(20, 10)
- term.clearLine()
- if tonumber(padAmm) then
- term.write("Fee: ".. math.floor((tonumber(padAmm) * withdrawFee) + 0.5).." (".. (100 * withdrawFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- afterFees = (tonumber(padAmm) - math.floor((tonumber(padAmm) * withdrawFee) + 0.5))
- term.write("Res: ".. afterFees)
- else
- term.write("Fee: 0 (".. (100 * withdrawFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- term.write("Res: 0")
- afterFees = 0
- end
- end
- term.setCursorPos(20, 9)
- term.clearLine()
- term.write("Amm: ".. padAmm)
- end
- elseif keyNum == 11 then
- if withdrawFee == 0 then
- afterFees = tonumber(padAmm)
- end
- if afterFees > 0 then
- term.setCursorBlink(false)
- local temp = { type = 1, date = os.date("*t"), amount = (tonumber(padAmm) * coinValue) }
- if withdrawFee > 0 then
- temp.fee = (math.floor((tonumber(padAmm) * withdrawFee) + 0.5) * coinValue)
- else
- temp.fee = 0
- end
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- if (afterFees == 0) then
- temp.success = false
- temp.result = "Withdraw more than 0"
- term.setTextColor(colours.red)
- writeCenter("Withdraw more than 0", 9)
- elseif (afterFees > 576) then
- temp.success = false
- temp.result = "Withdrawal maximum 576"
- term.setTextColor(colours.red)
- writeCenter("Withdrawal maximum 576", 9)
- elseif (getStored() < afterFees) then
- temp.success = false
- temp.result = "Not enough stored"
- term.setTextColor(colours.red)
- writeCenter("Not enough stored", 9)
- else
- term.setTextColor(1)
- writeCenter("Withdrawing $".. (tonumber(padAmm) * coinValue).. " from you account", 9)
- local isWith, with = withdraw(acc, (tonumber(padAmm) * coinValue), atm, pin)
- if (isWith) then
- disk.setLabel(drive, "$".. tostring(with))
- local isWith2, with2 = pullapiwithdraw(afterFees)
- if (isWith2) then
- temp.success = true
- temp.result = tostring(with)
- term.setTextColor(colours.green)
- writeCenter("Success", 10)
- else
- term.setTextColor(colours.red)
- writeCenter(with2.. "Returning money", 10)
- local isDep2, dep3 = deposit(acc, (tonumber(padAmm) * coinValue), atm, pin)
- if (isDep2) then
- temp.success = false
- temp.result = "Refund successful"
- disk.setLabel(drive, "$".. tostring(dep3))
- term.setTextColor(colours.green)
- writeCenter("Refund successful", 11)
- else
- temp.success = false
- temp.result = tostring(dep3)
- term.setTextColor(colours.red)
- writeCenter(dep3, 11)
- end
- end
- else
- temp.success = false
- temp.result = tostring(with)
- term.setTextColor(colours.red)
- writeCenter(with, 10)
- end
- end
- table.insert(transActionList, temp)
- sleep(3)
- drawScreen(2)
- end
- elseif keyNum >= 0 and keyNum <= 9 then
- if string.len(padAmm) < 3 then --Max is 576 so max of 3 char
- padAmm = padAmm.. keyNum
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- if withdrawFee > 0 then
- term.setCursorPos(20, 10)
- term.clearLine()
- term.write("Fee: ".. math.floor((tonumber(padAmm) * withdrawFee) + 0.5).." (".. (100 * withdrawFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- afterFees = (tonumber(padAmm) - math.floor((tonumber(padAmm) * withdrawFee) + 0.5))
- term.write("Res: ".. afterFees)
- end
- term.setCursorPos(24 + string.len(padAmm), 9)
- term.write(keyNum)
- end
- end
- end
- elseif screen == 5 then
- local isKey, keyNum = pinpad(event[2])
- if (isKey) then
- if keyNum == 10 then
- if string.len(padAmm) > 0 then
- padAmm = string.sub(padAmm, 1, string.len(padAmm) - 1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- if transferFee > 0 then
- term.setCursorPos(20, 10)
- term.clearLine()
- if tonumber(padAmm) then
- tranFee = (math.floor((tonumber(padAmm) * transferFee) + 0.5))
- term.write("Fee $".. tranFee.." (".. (100 * transferFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- afterFees = (tonumber(padAmm) - tranFee)
- term.write("Res $".. afterFees)
- else
- tranFee = 0
- term.write("Fee $0 (".. (100 * transferFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- term.write("Res $0")
- afterFees = 0
- end
- end
- term.setCursorPos(20, 9)
- term.clearLine()
- term.write("Amm $".. padAmm)
- end
- elseif keyNum == 11 then
- if transferFee == 0 then
- afterFees = tonumber(padAmm)
- end
- if afterFees > 0 then
- term.setCursorBlink(false)
- if (tonumber(padAmm) == 0) then
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.red)
- writeCenter("Transfer must be greater than $0", 9)
- sleep(3)
- drawScreen(2)
- elseif (tonumber(padAmm) > transferMax) then
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.red)
- writeCenter("Transfer maximum is $".. transferMax, 9)
- sleep(3)
- drawScreen(2)
- else
- drawScreen(6)
- end
- end
- elseif keyNum >= 0 and keyNum <= 9 then
- if string.len(padAmm) < string.len(tostring(transferMax)) then
- padAmm = padAmm.. keyNum
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- if transferFee > 0 then
- term.setCursorPos(20, 10)
- term.clearLine()
- tranFee = (math.floor((tonumber(padAmm) * transferFee) + 0.5))
- term.write("Fee $".. tranFee.." (".. (100 * transferFee).. "%)")
- term.setCursorPos(20, 11)
- term.clearLine()
- afterFees = (tonumber(padAmm) - tranFee)
- term.write("Res $".. afterFees)
- end
- term.setCursorPos(24 + string.len(padAmm), 9)
- term.write(keyNum)
- end
- end
- end
- elseif screen == 6 then
- local isKey, keyNum = pinpad(event[2])
- if (isKey) then
- if keyNum == 10 then
- if string.len(padAcc) > 0 then
- padAcc = string.sub(padAcc, 1, string.len(padAcc) - 1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(20, 9)
- term.clearLine()
- term.write("Acc: ".. padAcc)
- end
- elseif keyNum == 11 then
- if transferFee == 0 then
- tranFee = 0
- end
- term.setCursorBlink(false)
- clear(backgroundColour, false, true, acc)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Transfering $".. afterFees.. " from you account", 9)
- local isTras, tras = transfer(acc, tonumber(padAcc), afterFees, atm, pin)
- local temp = { type = 2, date = os.date("*t"), amount = tonumber(padAmm), fee = tranFee, payee = tonumber(padAcc) }
- if (isTras) then
- disk.setLabel(drive, "$".. tostring(tras))
- term.setTextColor(colours.green)
- writeCenter("Success", 10)
- if (transferFee > 0) then
- term.setTextColor(1)
- if (tranFee > 0) then
- writeCenter("Withdrawing $"..tranFee .. " transfer fee (".. (100 * transferFee).. "%)", 11)
- local isTras2, tras2 = withdraw(acc, tranFee, atm, pin)
- if (isTras2) then
- temp.success = true
- temp.result = tostring(tras2)
- disk.setLabel(drive, "$".. tostring(tras2))
- term.setTextColor(colours.green)
- writeCenter("Success", 12)
- else
- temp.success = false
- temp.result = "Fee-".. tostring(tras2)
- term.setTextColor(colours.red)
- writeCenter(tras2, 12)
- end
- else
- temp.success = true
- temp.result = tostring(tras)
- writeCenter("No transfer fee", 11)
- end
- else
- temp.success = true
- temp.result = tostring(tras)
- end
- else
- temp.success = false
- temp.result = tostring(tras)
- term.setTextColor(colours.red)
- writeCenter(tras, 10)
- end
- table.insert(transActionList, temp)
- sleep(3)
- drawScreen(2)
- elseif keyNum >= 0 and keyNum <= 9 then
- if string.len(padAcc) < 9 then --Gives a billion possilbe account numbers. More than you would ever need
- padAcc = padAcc.. keyNum
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(24 + string.len(padAcc), 9)
- term.write(keyNum)
- end
- end
- end
- elseif screen == 8 then
- local isKey, keyNum = pinpad(event[2])
- if (isKey) then
- if keyNum == 10 then
- if string.len(pin) > 0 then
- pin = string.sub(pin, 1, string.len(pin) - 1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(16, 9)
- term.clearLine()
- term.write("New PIN: ".. string.sub("****", 1, string.len(pin)))
- end
- elseif keyNum == 11 then
- if string.len(pin) == 5 then
- term.setCursorBlink(false)
- clear(backgroundColour, false, true, -1)
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- writeCenter("Creating account ID: ".. acc, 9)
- local suc, res = create(acc, atm, pin)
- if (suc) then
- disk.setLabel(drive, "$0")
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.green)
- writeCenter("Success", 10)
- sleep(3)
- drawScreen(2)
- else
- pin = ""
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(colours.red)
- writeCenter(res, 10)
- sleep(3)
- cleanUp()
- disk.eject(drive)
- end
- end
- elseif keyNum >= 0 and keyNum <= 9 then
- if string.len(pin) < 5 then
- pin = pin.. keyNum
- term.setBackgroundColor(backgroundColour)
- term.setTextColor(1)
- term.setCursorPos(24 + string.len(pin), 9)
- term.write("*")
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment