Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this script deals with providing banking information to the user, also when open will allow transactions
- local w, h = term.getSize()
- local tArg = {...}
- version = "1.0.0"
- settings.load(".settings")
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function CenterText(y,text)
- local x = math.floor((w - string.len(text)) /2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write(text)
- end
- local function BalanceManager(Amount)
- local R = false
- local ACCFile = fs.open("Banking_AccountFile","a")
- local Balance = ACCFile.readLine()
- if Balance + Amount > 0 then
- ACCFile.clearLine()
- ACCFile.write(Balance + Amount)
- R = true
- else
- R = false
- end
- ACCFile.close()
- return(R)
- end
- local function TransferManage()
- Clear()
- CenterText(1,"Waiting for Request...")
- CenterText(2,"Press enter to cancel")
- local event
- repeat
- event = {os.pullEvent()}
- until (event[1] == "rednet_message" and event[4] == settings.get("Secure_WirelessProtocol") and event[3][3] == "Banking") or (event[1] == "key" and event[2] == keys.enter)
- if event[1] == "key" and event[2] == keys.enter then
- Menu()
- else
- local id = event[2]
- local message = event[3]
- local Details = {message}
- Clear()
- CenterText(1,"Transfer Request Recieved")
- CenterText(3,"Sent from "..id)
- CenterText(4,"Amount = $"..Details[1])
- CenterText(5,"Item = "..Details[2])
- CenterText(5,"1 - accept")
- CenterText(6,"2 - Decline")
- local event, key = os.pullEvent("key")
- if key == keys.one then
- if BalanceManager(Details[1]) == true then
- print("Accepted!")
- rednet.send(id,"Accepted",protocol)
- else
- print("Declined!")
- rednet.send(id,"Declined",protocol)
- end
- os.sleep(2)
- Menu()
- elseif key == keys.two then
- print("Declined")
- rednet.send(id,"Declined",protocol)
- os.sleep(2)
- Menu()
- else
- print("Not Acceptible input")
- rednet.send(id,"Declined",protocol)
- os.sleep(2)
- Menu()
- end
- end
- end
- local function RequestDetected()
- local Data = {tArg[2]}
- local id = Data[2]
- local message = {Data[3]}
- local protocol = settings.get("Secure_WirelessProtocol")
- CenterText(1,"Transfer Request Recieved")
- CenterText(2,os.date())
- CenterText(3,"Sent from "..id)
- CenterText(4,"Amount = $"..message[1])
- CenterText(5,"Item = "..message[2])
- CenterText(6,"1 - accept")
- CenterText(7,"2 - Decline")
- local event
- repeat
- event = {os.pullEvent("key")}
- until event[2] == keys.one or event[2] == keys.two
- if event[2] == keys.one then
- if BalanceManager(message[1]) == true then
- print("Accepted!")
- rednet.send(id,"Accepted",protocol)
- else
- print("Declined!")
- rednet.send(id,"Declined",protocol)
- end
- os.sleep(2)
- elseif event[2] == keys.two then
- print("Declined")
- rednet.send(id,"Declined",protocol)
- os.sleep(2)
- else
- print("Not Acceptible input")
- rednet.send(id,"Declined",protocol)
- os.sleep(2)
- end
- shell.run("os/os_Programs/os_MainScript")
- end
- function Menu()
- Clear()
- print("Banking Display")
- print("welcome, User")
- CenterText(5,"==Options==")
- CenterText(6,"1 - Wait for Transfer")
- CenterText(7,"2 - ")
- CenterText(8,"3 - Return to Menu")
- local event, key = os.pullEvent("key")
- if key == keys.one then
- TransferManage()
- elseif key == keys.two then
- Menu()
- elseif key == keys.three then
- shell.run(settings.get("os_DesktopLoc"))
- else
- Menu()
- end
- end
- Clear()
- if tArg[1] == "Request Detected" then
- RequestDetected()
- else
- Menu()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement