Advertisement
Marlingaming

CC Tweaked Shopping Terminal - banking_public2

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