Marlingaming

Local Based Terminal

Dec 2nd, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.28 KB | None | 0 0
  1. --this script acts as an enclosed Local ATM, meaning all accounts on it cant be transfered to other computers, and cant use rednet, instead the player can deposit and withdraw acceptable currencies
  2. version = "1.4.5"
  3. Version = "1.4.0"
  4. local Ver = "1.4.0"
  5. local Terminal State = false
  6. local TerminalAdminCode = 0000
  7. local SelectedAccount = 'n'
  8. local AccountBalance = 0
  9. local AcceptableItems = {false,false,false,false,false} --Iron,Gold,Emeralds,Diamonds
  10. local ItemValues = {1,2,20,25,0}
  11. local CurrencyName = {"$1","$5","$20"}
  12. local CurrencyValue = {1,5,20}
  13. local StorageChestID = {"minecraft:chest_1", "minecraft:chest_2", "minecraft:chest_3"}
  14. local DepositChestID = "minecraft:chest_0"
  15. local Username = "guest"
  16. local Password = "guest"
  17.  
  18. local function LoginMenu()
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. print("-----Logint----")
  22. print("Username")
  23. term.setCursorPos(5,3)
  24. repeat
  25. local event, key = os.pullEvent("key")
  26. local User = read()
  27. until key == keys.enter
  28. Username = User
  29. term.setCursorPos(1,4)
  30. print("Password")
  31. term.setCursorPos(5,5)
  32. repeat
  33. local event, key = os.pullEvent("key")
  34. local Pass = read()
  35. until key == keys.enter
  36. Password = Pass
  37. if fs.exists(Username) == true then
  38. local file = fs.open(Username,"r")
  39. if file.readLine() == Password then
  40. SelectedAccount = Username
  41. AccountBalance = file.readLine()
  42. file.close()
  43. AccountManagement()
  44. else
  45. os.sleep(2)
  46. os.reboot()
  47. end
  48. else
  49. os.sleep(2)
  50. os.reboot()
  51. end
  52. end
  53.  
  54. local function SignupMenu()
  55. term.clear()
  56. term.setCursorPos(1,1)
  57. print("-----Create Account----")
  58. print("Username")
  59. term.setCursorPos(5,3)
  60. repeat
  61. local event, key = os.pullEvent("key")
  62. local User = read()
  63. until key == keys.enter
  64. Username = User
  65. term.setCursorPos(1,4)
  66. print("Password")
  67. term.setCursorPos(5,5)
  68. repeat
  69. local event, key = os.pullEvent("key")
  70. local Pass = read()
  71. until key == keys.enter
  72. Password = Pass
  73. term.clear()
  74. term.setCursorPos(1,1)
  75. print("Creating account....")
  76. sleep(1)
  77. local file = fs.open(Username,"w")
  78. file.writeLine(Password)
  79. file.writeLine(0)
  80. file.close()
  81. print("Rebooting, you can login after the restart")
  82. os.sleep(2)
  83. os.reboot()
  84. end
  85.  
  86. local function AdminLogin()
  87. print("Currently Unavaliable")
  88. os.sleep(5)
  89. os.reboot()
  90. end
  91.  
  92. local function AccountManagement()
  93. Clear()
  94. print("-----"..SelectedAccount.."----")
  95. print("Balance = $"..AccountBalance)
  96. print("--Options--")
  97. print("1 - Deposit")
  98. print("2 - Withdraw")
  99. print("3 - WIP Checks Menu")
  100. print("4 - nil")
  101. print("5 - nil")
  102. print("6 - Logout")
  103. repeat
  104. local event, key = os.pullEvent("key")
  105. until key == keys.one or key == keys.two or key == keys.three or key == keys.four or key == keys.five or key == keys.six
  106. local event, key = os.pullEvent("key")
  107. if key == keys.one then
  108. DepositMenu()
  109. elseif key == keys.two then
  110. WithdrawMenu()
  111. elseif key == keys.three then
  112. ChecksMenu()
  113. elseif key == keys.four then
  114.  
  115. elseif key == keys.five then
  116.  
  117. elseif key == keys.six then
  118. os.reboot()
  119. end
  120. end
  121.  
  122. local function ChecksMenu()
  123. Clear()
  124. print("- -WIP- - -Checks Menu- - -")
  125. print("this is a WIP feature")
  126. print("options")
  127. print("1 - Print Check")
  128. print("2 - Redeem Check")
  129. print("3 - Uncashed Checks")
  130. print("4 - return")
  131. repeat
  132. local event, key = os.pullEvent("key")
  133. until key == keys.one or key == keys.two or key == keys.three or key == keys.four
  134. if key == keys.one then
  135. Checks_PrintMenu()
  136. elseif key == keys.two then
  137. Checks_Claim()
  138. elseif key == keys.three then
  139. DisplayUnclaimedChecks()
  140. elseif key == keys.four then
  141. AccountManagement()
  142. end
  143. end
  144.  
  145. local function Checks_PrintMenu()
  146. Clear()
  147. print("Please Enter Desired Amount, then press enter")
  148. repeat
  149. local event, key = os.pullEvent("key")
  150. local input = read()
  151. until key == keys.enter
  152. print(input)
  153. print("Checking Balance")
  154. if AccountBalance >= input then
  155. print("Significant Funds")
  156. print("Printing Check")
  157. local CheckID = #fs.list("Checks") + 1
  158. local check = fs.open("Checks/Check_"..CheckID,"w")
  159. check.writeLine(SelectedAccount)
  160. check.writeLine(input)
  161. check.close()
  162. print(CheckID)
  163. os.sleep(5)
  164. ChecksMenu()
  165. else
  166. print("Insignificant Funds")
  167. os.sleep(2)
  168. ChecksMenu()
  169. end
  170. end
  171.  
  172. local function Checks_Claim()
  173. Clear()
  174. print("please Enter Check ID, then press Enter")
  175. local input = read()
  176. Repeat
  177. local event, key = os.pullEvent("key")
  178. until key == keys.enter
  179. print("checking files")
  180. if fs.exists("Check_"..input) == true then
  181. print("Transfering Credit")
  182. local TargetAccount = ‘guest’
  183. local Amount = 0
  184. local check = fs.open("Check_"..input,"r")
  185. TargetAccount = check.readLine()
  186. Amount = check.readLine()
  187. print(TargetAccount)
  188. print("$"..Amount)
  189. AccountBalance = AccountBalance + Amount
  190. UpdateAccount()
  191. ChargeAccount(TargetAccount,Amount)
  192. print("Completed")
  193. os.sleep(4)
  194. ChecksMenu()
  195. else
  196. print("Check doesn’t Exist")
  197. os.sleep(4)
  198. ChecksMenu()
  199. end
  200. end
  201.  
  202. local function DisplayUnclaimedChecks()
  203. ChecksMenu()
  204. end
  205.  
  206. local function ChargeAccount(Account, Amount)
  207. local file = fs.open(Account,"w")
  208. file.nextLine()
  209. local Balance = file.readLine() - Amount
  210. file.clearLine()
  211. file.writeLine(Balance)
  212. file.close()
  213. end
  214.  
  215. local function DepositMenu()
  216. term.clear()
  217. term.setCursorPos(2,5)
  218. print("DEPOSIT MENU")
  219. print("Press t once your desired items are in the container to YOUR left of the Terminal")
  220. print("or press x to exit")
  221. repeat
  222. local event, key = os.pullEvent("key")
  223. until key == keys.t or key == keys.x
  224. if key == keys.t then
  225. local Deposit = peripherals.find(DepositChestID)
  226. local item = Deposit.getItemDetails(1)
  227. if item.displayName == CurrencyName[0] then
  228. Deposit.pushItems( peripheral.find(StorageChestID[0]), 1)
  229. AccountBalance = AccountBalance + CurrencyValue[0]
  230. elseif item.displayName == CurrencyName[1] then
  231. Deposit.pushItems( peripheral.find( StorageChestID[1]), 1)
  232. AccountBalance = AccountBalance + CurrencyValue[1]
  233. elseif item.displayName == CurrencyName[2] then
  234. Deposit.pushItems( peripheral.find( StorageChestID[2]), 1)
  235. AccountBalance = AccountBalance + CurrencyValue[2]
  236. end
  237. elseif key == keys.x then
  238. os.sleep(1)
  239. UpdateAccount()
  240. AccountManagement()
  241. end
  242. end
  243.  
  244. local function WithdrawMenu()
  245. term.clear()
  246. term.setCursorPos(2,5)
  247. print("Withdraw MENU")
  248. print("Please Press Keys Relating to your request, then Press t")
  249. print(" 1 - "..CurrencyName[0])
  250. print(" 2 - "..CurrencyName[1])
  251. print(" 3 - "..CurrencyName[2])
  252. local RequestedItems = {0,0,0}
  253. local RequestedValue = 0
  254. repeat
  255. local event, key = os.pullEvent("key")
  256. term.setCursorPos(3,6)
  257. term.clearLine()
  258. term.write("$"..RequestedAmount)
  259. if key == keys.one then
  260. RequestedValue = RequestedValue + CurrencyValue[0]
  261. RequestedItems[0] = RequestedItems[0] + 1
  262. elseif key == keys.two then
  263.  
  264. RequestedValue = RequestedValue + CurrencyValue[1]
  265. RequestedItems[1] = RequestedItems[1] + 1
  266.  
  267. elseif key == keys.three then
  268.  
  269. RequestedValue = RequestedValue + CurrencyValue[2]
  270. RequestedItems[2] = RequestedItems[2] + 1
  271.  
  272. end
  273. until key == keys.t
  274. print("Processing Request")
  275. if RequestedValue <= AccountBalance then
  276. local Deposit = peripheral.find(DepositChestID)
  277. print("Request Accepted, now Dispensing")
  278. for i = 0, #RequestedItems do
  279. for i1 = 0, #RequestedItems[i] do
  280. Deposit.pullItem( peripheral.find( StorageChestID[I]),1,[0])
  281. end
  282. end
  283. else
  284. print("Request Declined")
  285. end
  286. os.sleep(2)
  287. AccountManagement()
  288. end
  289.  
  290. local function UpdateAccount()
  291. local file = fs.open(SelectedAccount,"w")
  292. file.nextLine()
  293. file.clearLine()
  294. file.writeLine(AccountBalance)
  295. file.close()
  296. end
  297.  
  298. local function Clear()
  299. term.clear()
  300. term.setCursorPos()
  301. end
  302.  
  303. Clear()
  304. if fs.exists("InstalledFile") == true then
  305.  
  306. else
  307. local file = fs.open("InstalledFile","w")
  308. file.writeLine("Ready")
  309. file.writeLine("Installed")
  310. file.close()
  311. shell.run("pastebin","get","2KmEkzCF","startup")
  312. shell.run("pastebin","get","Fpt9sZvz","Updater")
  313. os.sleep(3)
  314. os.reboot()
  315. end
  316. print("----------Banking Termainal---"..Ver)
  317. print("Options")
  318. print("1 - Login")
  319. print("2 - Create Account")
  320. print("3 - Admin Login")
  321. print("4 - Reboot")
  322. repeat
  323. local event, key = os.pullEvent("key")
  324. until key == keys.one or key == keys.two or key == keys.three or key == keys.four
  325. if key == keys.one then
  326. LoginMenu()
  327. elseif key == keys.two then
  328. SignupMenu()
  329. elseif key == keys.three then
  330. AdminLogin()
  331. elseif key == keys.four then
  332. os.reboot()
  333. end
  334.  
  335.  
  336.  
Add Comment
Please, Sign In to add comment