Marlingaming

CC Tweaked ATM - banking_public2

Feb 4th, 2022 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. settings.load(".settings")
  3. local ItemNames = {}
  4. local ItemTags = {}
  5. local ItemPrices = {}
  6. local ItemAmount = {}
  7. local ItemSellAmount = {}
  8. local ItemInStock = {}
  9. local Balance = 0
  10. local BankScript = "Kiosk/KioskBankSystem-banking_public2"
  11. --DO NOT MESS WITH COIN NAMES AND VALUES
  12. local CoinNames = {"Neb","Thero","Gold Coin"}
  13. local CoinValues = {1,32,128}
  14. --wither to use data off of a file or set program values
  15. local FileUse = true
  16. local CardAccept = false
  17. local Storage = peripherals.wrap("minecraft:chest_0")
  18. local Deposit = peripherals.wrap("minecraft:chest_1")
  19.  
  20. local function Clear()
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. end
  24.  
  25. local function Setup()
  26. Clear()
  27. print("Files not found, please create 'Shop' file in 'Kiosk' file")
  28. print("should be named this 'Kiosk/Shop'")
  29. os.sleep(7)
  30. exit
  31. end
  32.  
  33. function Purchase_Card(item)
  34. Clear()
  35. print("Please Swipe Card")
  36. local Reader = peripherals.find("reader")
  37. local event, a, b, c = os.pullEvent("mag_swipe)
  38. shell.run(BankScript,"transfer",ItemPrices[item],c)
  39. settings.load(".settings")
  40. if settings.get("Pass") == true then
  41. print("Transaction Accepted")
  42. Dispense(item,ItemSellAmount[item])
  43. os.sleep(3)
  44. else
  45. print("Transaction Rejected")
  46. os.sleep(3)
  47. end
  48. end
  49.  
  50. function Purchase_Manual(item,Set)
  51. Clear()
  52. print("please place current change into chest, then press enter")
  53. print("Costs ",ItemPrices[item])
  54. repeat
  55. local event, key = os.pullEvent("key")
  56. until key == keys.enter
  57. term.setCursorPos(1,7)
  58. local PaidAmount = 0
  59. if Set ~= nil then
  60. PaidAmount = Set
  61. end
  62. for slot, item in pairs(Deposit.list()) do
  63. term.clearLine()
  64. term.write(PaidAmount)
  65. if PaidAmount < ItemPrices[item] then
  66. if item.name == CoinNames[1] then
  67. PaidAmount = PaidAmount + (CoinValues[1] * item.amount)
  68. Deposit.pushItems(peripheral.getName(Storage),slot)
  69. elseif item.name == CoinNames[2] then
  70. PaidAmount = PaidAmount + CoinValues[2] * item.amount)
  71. Deposit.pushItems(peripheral.getName(Storage),slot)
  72. elseif item.name == CoinNames[3] then
  73. PaidAmount = PaidAmount + CoinValues[3] * item.amount)
  74. Deposit.pushItems(peripheral.getName(Storage),slot)
  75. end
  76. end
  77. end
  78. if PaidAmount >= ItemPrices[item] then
  79. print("Sufficent Payment")
  80. Dispense(item,ItemSellAmount[item])
  81. else
  82. print("Insufficent Payment")
  83. Purchase_Manual(item,PaidAmount)
  84. end
  85. end
  86.  
  87. function Dispense(item,x)
  88. local DisAmount = 0
  89. for slot, item in pairs(Storage.list()) do
  90. if DisAmount < ItemSellAmount[item] then
  91. if item.name == ItemNames[item] then
  92. DisAmount = DisAmount + item.count
  93. Storage.pushItems(peripheral.getName(Deposit),slot,(ItemSellAmount[item] - DisAmount))
  94. end
  95. end
  96. end
  97. end
  98.  
  99. function TransactionMenu(method)
  100. Clear()
  101. if method == "deposit" then
  102. print("please place Currency in chest below, then press enter")
  103. repeat
  104. local event, key = os.pullEvent("key")
  105. until key == keys.enter
  106. PullCash()
  107. elseif method == "withdraw" then
  108. print("please type amount then press enter")
  109. local input
  110.  
  111. if Balance - input >= 0 then
  112. PushCash(input)
  113. else
  114. print("insignificant funds")
  115. os.sleep(2)
  116. end
  117. end
  118. end
  119.  
  120. function ATMMenu()
  121. Clear()
  122. if fs.exists("User") then fs.delete("User") end
  123. shell.run(BankScript,"Details")
  124. local options = {"withdraw","deposit","logout"}
  125. print("hello, ",settings.get("User"))
  126. print(Balance)
  127. local n = CUI(options)
  128. if options[n] == "logout" then
  129. settings.set("User","n")
  130. settings.save(".settings")
  131. else
  132. TransactionMenu(options[n])
  133. ATMMenu()
  134. end
  135. end
  136.  
  137. function ATMLogin()
  138. settings.set("User","n")
  139. settings.save(".settings")
  140. settings.load(".settings")
  141. Clear()
  142. print("===Login=ATM===")
  143. print ("if you have a account, please swipe card now")
  144. print("if you don’t have a account, please contact closest bank member for help")
  145. local a, b, c, d
  146. repeat
  147. a, b, c, d = os.pullEvent("mag_swipe")
  148. until a == "mag_swipe"
  149. shell.run(BankScript,"Login",d)
  150. if settings.get("User") ~= "n" then
  151. ATMMenu()
  152. else
  153. print("account not found")
  154. os.sleep(2)
  155. end
  156. ATMLogin()
  157. end
  158.  
  159. function GetStock()
  160. for slot, item in pairs(Storage.list()) do
  161. for I = 1, #ItemNames do
  162. if item.name == ItemNames[I] then
  163. if ItemAmount[I] == nil then
  164. ItemAmount[I] = item.count
  165. else
  166. ItemAmount[I] = ItemAmount[I] + item.count
  167. end
  168. end
  169. end
  170. end
  171. for i = 1, #ItemNames do
  172. if ItemAmount[i] >= ItemSellAmount[i] then
  173. ItemInStock[i] = true
  174. else
  175. ItemInStock[i] = false
  176. end
  177. end
  178. local SellItems = {}
  179. for A = 1, #ItemNames do
  180. if ItemInStock[A] == true then
  181. SellItems[#SellItems + 1] = A
  182. end
  183. end
  184. return(SellItems)
  185. end
  186.  
  187. ATMLogin()
Add Comment
Please, Sign In to add comment