Advertisement
Marlingaming

CC Tweaked Banking Program Addon

Jan 5th, 2022 (edited)
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. --this script deals with providing banking information to the user, also when open will allow transactions
  2. local w, h = term.getSize()
  3. local tArg = {...}
  4. version = "1.0.0"
  5. settings.load(".settings")
  6. local function Clear()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. end
  10.  
  11. local function CenterText(y,text)
  12.   local x = math.floor((w - string.len(text)) /2)
  13.   term.setCursorPos(x,y)
  14.   term.clearLine()
  15.   term.write(text)
  16. end
  17.  
  18. local function BalanceManager(Amount)
  19. local R = false
  20. local ACCFile = fs.open("Banking_AccountFile","a")
  21. local Balance = ACCFile.readLine()
  22. if Balance + Amount > 0 then
  23.     ACCFile.clearLine()
  24.     ACCFile.write(Balance + Amount)
  25.     R = true
  26. else
  27.     R = false
  28. end
  29. ACCFile.close()
  30. return(R)
  31. end
  32.  
  33. local function TransferManage()
  34. Clear()
  35. CenterText(1,"Waiting for Request...")
  36. CenterText(2,"Press enter to cancel")
  37. local event
  38. repeat
  39.     event = {os.pullEvent()}
  40. 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)
  41. if event[1] == "key" and event[2] == keys.enter then
  42.     Menu()
  43. else
  44.     local id = event[2]
  45.     local message = event[3]
  46.     local Details = {message}
  47.     Clear()
  48.     CenterText(1,"Transfer Request Recieved")
  49.     CenterText(3,"Sent from "..id)
  50.     CenterText(4,"Amount = $"..Details[1])
  51.     CenterText(5,"Item = "..Details[2])
  52.     CenterText(5,"1 - accept")
  53.     CenterText(6,"2 - Decline")
  54.     local event, key = os.pullEvent("key")
  55.     if key == keys.one then
  56.         if BalanceManager(Details[1]) == true then
  57.             print("Accepted!")
  58.             rednet.send(id,"Accepted",protocol)
  59.         else
  60.             print("Declined!")
  61.             rednet.send(id,"Declined",protocol)
  62.         end
  63.         os.sleep(2)
  64.         Menu()
  65.     elseif key == keys.two then
  66.         print("Declined")
  67.         rednet.send(id,"Declined",protocol)
  68.         os.sleep(2)
  69.         Menu()
  70.     else
  71.         print("Not Acceptible input")
  72.         rednet.send(id,"Declined",protocol)
  73.         os.sleep(2)
  74.         Menu()
  75.     end
  76. end
  77. end
  78.  
  79. local function RequestDetected()
  80. local Data = {tArg[2]}
  81. local id = Data[2]
  82. local message = {Data[3]}
  83. local protocol = settings.get("Secure_WirelessProtocol")
  84. CenterText(1,"Transfer Request Recieved")
  85. CenterText(2,os.date())
  86. CenterText(3,"Sent from "..id)
  87. CenterText(4,"Amount = $"..message[1])
  88. CenterText(5,"Item = "..message[2])
  89. CenterText(6,"1 - accept")
  90. CenterText(7,"2 - Decline")
  91. local event
  92. repeat
  93.     event = {os.pullEvent("key")}
  94. until event[2] == keys.one or event[2] == keys.two
  95. if event[2] == keys.one then
  96.     if BalanceManager(message[1]) == true then
  97.         print("Accepted!")
  98.         rednet.send(id,"Accepted",protocol)
  99.     else
  100.         print("Declined!")
  101.         rednet.send(id,"Declined",protocol)
  102.     end
  103.     os.sleep(2)
  104. elseif event[2] == keys.two then
  105.     print("Declined")
  106.     rednet.send(id,"Declined",protocol)
  107.     os.sleep(2)
  108.    
  109. else
  110.     print("Not Acceptible input")
  111.     rednet.send(id,"Declined",protocol)
  112.     os.sleep(2)
  113. end
  114. shell.run("os/os_Programs/os_MainScript")
  115. end
  116.  
  117. function Menu()
  118. Clear()
  119. print("Banking Display")
  120. print("welcome, User")
  121. CenterText(5,"==Options==")
  122. CenterText(6,"1 - Wait for Transfer")
  123. CenterText(7,"2 - ")
  124. CenterText(8,"3 - Return to Menu")
  125. local event, key = os.pullEvent("key")
  126. if key == keys.one then
  127.     TransferManage()
  128. elseif key == keys.two then
  129.     Menu()
  130. elseif key == keys.three then
  131.     shell.run(settings.get("os_DesktopLoc"))
  132. else
  133.     Menu()
  134. end
  135. end
  136.  
  137. Clear()
  138. if tArg[1] == "Request Detected" then
  139.     RequestDetected()
  140. else
  141.     Menu()
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement