Advertisement
Susceptance

atm_start

May 7th, 2022 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. validItems = {'minecraft:emerald', 'minecraft:diamond', 'minecraft:gold_ingot', 'minecraft:iron_ingot'}
  2. term.setBackgroundColor(2048)
  3.  
  4. rednet.open('left')
  5. database = rednet.lookup("C_ACC", 'database')
  6. rednet.close()
  7.  
  8. pin = 0
  9.  
  10. function GetAccount(pin)
  11. rednet.open('left')
  12. rednet.send(database, textutils.serialise({'account', pin}), 'C_ACC')
  13. sender,message,distance = rednet.receive('C_ACC')
  14. account = textutils.unserialise(message)
  15. rednet.close()
  16.  
  17. if account ~= nil then
  18. return account
  19. else
  20. return nil
  21. end
  22. end
  23.  
  24. function PromptAccount(clear)
  25. while true do
  26. if clear then
  27. term.clear()
  28. term.setCursorPos(1,1)
  29. end
  30. print("enter pin: ")
  31. pin = read()
  32.  
  33. if pin == 'e' or pin == exit then
  34. break
  35. end
  36.  
  37. print('Fetching account...')
  38.  
  39. account = GetAccount(pin)
  40.  
  41. if account ~= nil then
  42. return account
  43. else
  44. print("Invalid pin!")
  45. sleep(1.5)
  46. end
  47. end
  48. end
  49.  
  50. function ShowAccount(account, clear)
  51. if clear then
  52. term.clear()
  53. term.setCursorPos(1,1)
  54. end
  55.  
  56. print('Welcome, '..account[1])
  57. print('')
  58. print('Enter your requested action:')
  59. print('Check balance: C')
  60. print('Deposit: D')
  61. print('Withdraw: W')
  62. print('Exit: E')
  63. end
  64.  
  65. while true do
  66. account = PromptAccount(true)
  67.  
  68. ShowAccount(account, true)
  69.  
  70. while true do
  71. command = read()
  72. command = string.lower(command)
  73. if command == 'c' or command == 'check' or command == balance then
  74. ShowAccount(account, true)
  75. print('Please re-enter your PIN')
  76. PromptAccount(false)
  77. ShowAccount(account, true)
  78. print('Your account balance is: '..account[2]..' credits')
  79. elseif command == 'd' or command == 'deposit' then
  80. print('Place items you wish to deposit in the inventory and press ENTER')
  81. read()
  82. print('Depositing...')
  83. for i=1, 16 do
  84. data = turtle.getItemDetail(i)
  85. if data ~= nil then
  86. turtle.select(i)
  87.  
  88. data = turtle.getItemDetail(i)
  89. amount = turtle.getItemCount(i)
  90.  
  91. if data.name == validItems[1] then --Emerald
  92. turtle.drop()
  93. elseif data.name == validItems[2] then --Diamond
  94. turtle.turnRight()
  95. turtle.drop()
  96. turtle.turnLeft()
  97. elseif data.name == validItems[3] then --Gold
  98. turtle.dropUp()
  99. elseif data.name == validItems[4] then --Iron
  100. turtle.dropDown()
  101. end
  102.  
  103. rednet.open('left')
  104. rednet.send(database, textutils.serialise({'depo', pin, {data.name, amount}}), 'C_ACC')
  105. rednet.close()
  106. end
  107. end
  108.  
  109. account = GetAccount(pin)
  110. print('Your account balance is: '..account[2]..' credits')
  111.  
  112. elseif command == 'w' or command == 'withdraw' then
  113. term.clear()
  114. term.setCursorPos(1,1)
  115. print('Please re-enter your PIN')
  116. if PromptAccount(false) == account then
  117. term.clear()
  118. term.setCursorPos(1,1)
  119. print('Enter items to withdraw as')
  120.  
  121. print('Emeralds: E')
  122. print('Diamonds: D')
  123. print('Gold Ingots: G')
  124. print('Iron Ingots: I')
  125.  
  126. withdraw = read()
  127. withdraw = string.lower(withdraw)
  128.  
  129. if withdraw == 'e' or withdraw == 'emerald' then
  130. withdraw = 1
  131. elseif withdraw == 'd' or withdraw == 'diamond' then
  132. withdraw = 2
  133. elseif withdraw == 'g' or withdraw == 'gold' then
  134. withdraw = 3
  135. elseif withdraw == 'i' or withdraw == 'iron' then
  136. withdraw = 4
  137. end
  138.  
  139. rednet.open('left')
  140. rednet.send(database, textutils.serialise({'with', pin, validItems[withdraw]}), 'C_ACC')
  141. sender,message,distance = rednet.receive('C_ACC')
  142. message = textutils.unserialise(message)
  143. rednet.close()
  144. print('Withdrawing items...')
  145. print(withdraw)
  146. withdrawAmount = math.ceil(message[2] / 64)
  147. if withdraw == 1 then --Emeralds
  148. for i=1, range(withdrawAmount) do
  149. turtle.suck(64)
  150. end
  151. elseif withdraw == 2 then --Diamonds
  152. turtle.turnRight()
  153. for i=1, range(withdrawAmount) do
  154. turtle.suck(64)
  155. end
  156. turtle.turnLeft()
  157. elseif withdraw == 3 then --Gold
  158. for i=1, range(withdrawAmount) do
  159. turtle.suckUp(64)
  160. end
  161. elseif withdraw == 4 then --Iron
  162. for i=1, range(withdrawAmount) do
  163. turtle.suckDown(64)
  164. end
  165. end
  166. account = GetAccount(pin)
  167. ShowAccount(account, true)
  168. print('Items withdrawn. Your account balance is: '..account[2]..' credits')
  169. end
  170. elseif command == 'e' or command == 'exit' then
  171. break
  172. else
  173. print('Command not recognized! Try again.')
  174. end
  175. end
  176. pin = 0
  177. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement