Advertisement
jtams322

Untitled

Dec 20th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. -- PRO BANK
  2. os.pullEvent = os.pullEventRaw
  3. rednet.open("bottom")
  4. serverID = 1
  5. printer = peripheral.wrap("bottom")
  6. w, h = term.getSize()
  7. select1 = {"[ Login ]", 6}
  8. select2 = {"Create Account", 9}
  9. loginItems = {"Username: ", "Password: "}
  10. newAccountItems = {"New Username: ", "New Password: "}
  11. bankItems = {"[ Deposit ]", " Withdraw ", " Transfer ", " Logout "}
  12. bankSel = 1
  13. selection = 1
  14. showMain = 1
  15. showExtra = 0
  16. balance = 0
  17. function printSel()
  18. term.setBackgroundColor(colors.black)term.clear()
  19. paintutils.drawLine(1,1,w,1, colors.cyan)
  20. term.setCursorPos(1,1)
  21. term.setTextColor(colors.white)
  22. print("ProBank V0.1 Created By Actiquack")
  23. term.setBackgroundColor(colors.black)
  24. if showMain == 3 then
  25. term.setCursorPos(12, 7)
  26. print(newAccountItems[1])
  27. term.setCursorPos(12, 8)
  28. print(newAccountItems[2])
  29. term.setCursorPos(26, 7)
  30. end
  31. if showMain == 1 then
  32. term.setCursorPos(26-select1[2],7)
  33. print(select1[1])
  34. term.setCursorPos(26-select2[2],8)
  35. print(select2[1])
  36. end
  37. if showMain == 0 then
  38. term.setCursorPos(16,7)
  39. print(loginItems[1])
  40. term.setCursorPos(16,8)
  41. print(loginItems[2])
  42. term.setCursorPos(26,7)
  43. end
  44. if showMain == 2 then
  45. term.setCursorPos(1,3)
  46. print("---------------------------------------------------")
  47. term.setCursorPos(25-#username/2,3)
  48. print(username)
  49. term.setCursorPos(1,4)
  50. if bankSel == 1 then
  51. bankItems = {"[ Deposit ]", " Withdraw ", " Transfer ", " Logout "}
  52. end
  53. if bankSel == 2 then
  54. bankItems = {" Deposit ", "[ Withdraw ]", " Transfer ", " Logout "}
  55. end
  56. if bankSel == 3 then
  57. bankItems = {" Deposit ", " Withdraw ", "[ Transfer ]", " Logout "}
  58. end
  59. if bankSel == 4 then
  60. bankItems = {" Deposit ", " Withdraw ", " Transfer ", "[ Logout ]"}
  61. end
  62. print(bankItems[1])
  63. print(bankItems[2])
  64. print(bankItems[3])
  65. print(bankItems[4])
  66. print("---------------------------------------------------")
  67. print("Balance: " .. balance)
  68. print(" ")
  69. if showExtra == 1 then
  70. print("Enter Check Key: ")
  71. term.setCursorPos(18,11)
  72. code = read()
  73. ammountAdded = checkCode(code)
  74. if ammountAdded == false or type(ammountAdded) == "string" then
  75. term.setTextColor(colors.red)print("Invalid Code")term.setTextColor(colors.white)
  76. sleep(3)
  77. showExtra = 0
  78. printSel()
  79. else
  80. term.setTextColor(colors.lime)print("Code Found! " .. ammountAdded .. " added to account balance")term.setTextColor(colors.white)
  81. sleep(3)
  82. balance = balance + ammountAdded
  83. sendBalance = {"balance", username, password, balance}
  84. rednet.send(serverID, sendBalance)
  85. showExtra = 0
  86. printSel()
  87. end
  88. end
  89. if showExtra == 2 then
  90. print("Enter Withdraw Ammount: ")
  91. term.setCursorPos(25,11)
  92. withAmmount = tonumber(read())
  93. if withAmmount > balance then
  94. term.setTextColor(colors.red)print("You're too poor to withdraw this ammount!")term.setTextColor(colors.white)
  95. sleep(3)
  96. showExtra = 0
  97. printSel()
  98. else
  99. printer.newPage()
  100. printer.write("Withdrew from " .. username)
  101. printer.setCursorPos(1,2)
  102. printer.write("--------------------------------------")
  103. printer.setCursorPos(1,3)
  104. printer.write("Ammount: " .. withAmmount)
  105. printer.setCursorPos(1,4)
  106. all = "123456789abcdefghijklmnopqrstuvwrxyz"
  107. e = ""
  108. for i=1, 10 do
  109. r = math.random(#all)
  110. e = e .. string.sub(all, r, r)
  111. end
  112. printer.write("Code: " .. e)
  113. newCode = {"newCode", e, withAmmount}
  114. rednet.send(serverID, newCode)
  115. sleep(2)
  116. printer.endPage()
  117. balance = balance - withAmmount
  118. sendBalance = {"balance", username, password, balance}
  119. rednet.send(serverID, sendBalance)
  120. term.setTextColor(colors.lime)print("A check worth " .. withAmmount .. " has been printed!")
  121. sleep(3)
  122. showExtra = 0
  123. printSel()
  124. end
  125. end
  126. end
  127. end
  128. printSel()
  129. function checkLogin(username, password)
  130. userCred = {"usercred", username, password}
  131. rednet.send(serverID, userCred)
  132. id, msg = rednet.receive()
  133. if msg == false then
  134. return false
  135. else
  136. balance = tonumber(msg)
  137. end
  138. end
  139. function checkCode(code)
  140. code = {"code", code}
  141. rednet.send(serverID, code)
  142. id, msg = rednet.receive()
  143. if msg == false then
  144. return false
  145. else
  146. return msg
  147. end
  148. end
  149. while true do
  150. _,key = os.pullEvent("key")
  151. if key == 200 or key == 208 then
  152. if select1[1] == "[ Login ]" then
  153. select1 = {"Login", 4}
  154. select2 = {"[ Create Account ]", 11}
  155. selection = 2
  156. printSel()
  157. else
  158. select1 = {"[ Login ]", 6}
  159. select2 = {"Create Account", 9}
  160. selection = 1
  161. printSel()
  162. end
  163. end
  164. if key == 28 then
  165. if selection == 2 then
  166. showMain = 3
  167. printSel()
  168. newUsername = read()
  169. term.setCursorPos(26,8)
  170. newPassword = read()
  171. newCred = {"newUser", newUsername, newPassword}
  172. rednet.send(serverID, newCred)
  173. term.setTextColor(colors.lime)
  174. term.setCursorPos(18,9)
  175. id, msg = rednet.receive()
  176. if msg == true then
  177. print("Account Created!")
  178. elseif msg == false then
  179. term.setTextColor(colors.red)
  180. print("Account Exists")
  181. end
  182. term.setTextColor(colors.white)
  183. sleep(3)
  184. os.reboot()
  185. end
  186. if selection == 1 then
  187. showMain = 0
  188. printSel()
  189. username = read()
  190. term.setCursorPos(26,8)
  191. password = read("*")
  192. if checkLogin(username, password) == false then
  193. term.setCursorPos(18,9)
  194. term.setTextColor(colors.red)print("Login Failed")term.setTextColor(colors.white)
  195. sleep(3)
  196. showMain = 1
  197. printSel()
  198. else
  199. showMain = 2
  200. printSel()
  201. --BANK
  202. while showMain == 2 do
  203. _, key = os.pullEvent("key")
  204. if key == 200 then
  205. bankSel = bankSel - 1
  206. if bankSel <= 0 then
  207. bankSel = 4
  208. end
  209. printSel()
  210. end
  211. if key == 208 then
  212. bankSel = bankSel + 1
  213. if bankSel >= 5 then
  214. bankSel = 1
  215. end
  216. printSel()
  217. end
  218. if key == 28 then
  219. if bankSel == 4 then
  220. os.reboot()
  221. end
  222. if bankSel == 1 then
  223. showExtra = 1
  224. printSel()
  225. end
  226. if bankSel == 2 then
  227. showExtra = 2
  228. printSel()
  229. end
  230. end
  231. end
  232. --END BANK
  233. end
  234. end
  235. end
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement