Advertisement
Marlingaming

Banking Terminal 0.1

Nov 3rd, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. local ControlChannel = 101
  3. local ListenChannel = 103
  4. local TransferChest = 1
  5. local UserDetails = {}
  6. local TerminalNum = 1
  7.  
  8.  
  9.  
  10. local function SystemInteraction(Key1,Key2,Action,Amount)
  11. local modem = peripheral.find("modem")
  12. local DT
  13. if Action == "signin" then DT = {Key1,Key2,Action} elseif Action == "Transfer" then DT = {Key1,Key2,Action,tonumber(Amount)} elseif Action == "Admin" then DT = {Key1,0,Action,Key2} elseif Action == "Details" then DT = {Key1,0,Action} end
  14. modem.transmit(ControlChannel, ListenChannel, textutils.serialize(DT))
  15. local a, b, c, d, e
  16. modem.open(103)
  17. repeat
  18. a, b, c, d, e = os.pullEvent()
  19. until c == 103
  20. return textutils.unserialize(e)
  21. end
  22.  
  23. local function TextField()
  24. local input
  25. local TX, TY = term.getCursorPos()
  26. TY = TY - 1
  27. while true do
  28. term.setCursorPos(TX,TY)
  29. term.clearLine()
  30. term.write()
  31. local e, a, b, c = os.pullEvent("key")
  32. if a == keys.enter then break elseif e == "key" then input = read(C) end
  33. end
  34. return input
  35. end
  36.  
  37.  
  38. local function Page(title,text)
  39. term.setBackgroundColor(colors.cyan)
  40. term.setTextColor(colors.white)
  41. term.clear()
  42. term.setCursorPos(1,1)
  43. print(title.." == Banking Terminal #"..TerminalNum)
  44. if text ~= nil and #text > 0 then
  45. print("[text]")
  46. for i = 1, #text do
  47. print(text[i])
  48. end
  49. end
  50. print("[options]")
  51. end
  52.  
  53. local function OptionList(y,options)
  54. local I
  55. local n = 1
  56. repeat
  57. for i = 1, #options do
  58. term.setCursorPos(1,(y - 1) + i)
  59. term.clearLine()
  60. if n == i then term.write(">> "..options[i]) else term.write(options[i]) end
  61. end
  62. local a, b = os.pullEvent("key")
  63. if b == keys.w and n > 1 then n = n - 1 end
  64. if b == keys.s and n < #options then n = n + 1 end
  65. if b == keys.enter then I = n end
  66. until I ~= nil
  67. return options[I]
  68. end
  69.  
  70. local function TransMenu(Key)
  71. Page("Transaction",{"Enter Amount, use Negatives for withdraw"})
  72. local Text = TextField()
  73. SystemInteraction(Key,TransferChest,"Transfer",Text)
  74. MMenu(Key)
  75. end
  76.  
  77. function MMenu(Key)
  78. local AccountDetails = {}
  79. AccountDetails = SystemInteraction(Key,0,"Details",0)--Balance,Username
  80. Page("User Menu",{"Welcome, "..AccountDetails[2],AccountDetails[1]})
  81. local Opt = OptionList(5,{"Transaction","logout"})
  82. if Opt == "logout" then os.reboot() else TransMenu(Key) end
  83.  
  84. end
  85.  
  86.  
  87.  
  88. local function AdminLogin()
  89.  
  90. end
  91.  
  92. local function Signin()
  93. Page("Welcome",{"Please Either Signin using your key","or create a new account by contacting a administrator"})
  94. local d, Y = term.getCursorPos()
  95. Y = Y + 1
  96. local Opt = OptionList(Y,{"Signin","admin"})
  97. if Opt == "admin" then
  98. AdminLogin()
  99. end
  100. Page("Signin")
  101. print("Key")
  102. print("|")
  103. local Key = TextField()
  104. local DE = SystemInteraction(Key,1,"signin",0)
  105. if DE[1] == true then MMenu(Key) else print("failed") os.sleep(1) os.reboot() end
  106. end
  107.  
  108. local function Start()
  109. Signin()
  110. end
  111.  
  112. Start()
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement