Advertisement
Marlingaming

Player shop Currency test 3

Oct 30th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. --Edit This\/
  2. local Items = {{"minecraft:stone","Stone",5,2,true}} --ID/Tag,Label,AmountPerSale,Cost,Selling(true/false)
  3. local BankNet_En = false
  4. local BankKey = 0001
  5. --DONT TOUCH
  6. local Payment = {{"currency:dollar_bill",1},{"currency:ten_dollar_bill",10},{"currency:twenty_dollar_bill",20},{"currency:fifty_dollar_bill",50},{"currency:hundred_dollar_bill",100}}
  7. local Version = "1.2.0"
  8. local Storage = {}
  9. --Change to sides of computer for chests
  10. local PayChest = peripheral.wrap("top")
  11. local StoreChest = peripheral.wrap("bottom")
  12. --Your Name
  13. local Owner = "Marlin"
  14. --Company
  15. local Company = "WST"
  16.  
  17.  
  18. --DONT TOUCH ANYTHING BEYOND THIS
  19. local function start()
  20. for i = 1, #Items do
  21. local Amount = 0
  22. for slot, item in pairs(StoreChest.list()) do
  23. if item.name == Items[i][1] then Amount = Amount + item.count end
  24. end
  25. if Amount >= Items[i][3] then Storage[i] = true else Storage[i] = false end
  26. end
  27. if Receipt.CheckPrinter() == false then error("printer error") end
  28. Menu()
  29. Options()
  30. end
  31.  
  32. local function CurrencyCheck(name)
  33. local Worth = 0
  34. for i = 1, #Payment do
  35. if name == Payment[i][1] then Worth = Payment[i][2] end
  36. end
  37. return Worth
  38. end
  39.  
  40. local function CountCash(Target)
  41. local Pay = 0
  42. for slot, item in pairs(PayChest.list()) do
  43. Pay = Pay + (CurrencyCheck(item.name) * item.count)
  44. end
  45. Pass = false
  46. if Pay >= Target then Pass = true end
  47. return Pass
  48. end
  49.  
  50. local function TakePayment(Target)
  51. local Pay = 0
  52. Pass = false
  53. for slot, item in pairs(PayChest.list()) do
  54. local Cash = CurrencyCheck(item.name)
  55. repeat
  56. if (Pay + Cash) <= Target then Pay = Pay + Cash TransferItem(slot,"PayChest",1) end
  57. until (Pay + Cash) > Target
  58. end
  59. if Pay == Target then Pass = true end
  60. return Pass
  61. end
  62.  
  63. local function FindStoredItem(Name,amount)
  64. local F = 0
  65. for slot, item in pairs(StoreChest.list()) do
  66. if item.name == Name and F ~= amount then
  67. if item.count >= amount then
  68. F = amount
  69. TransferItem(slot,"StoreChest",F)
  70. else
  71.  
  72. end
  73. end
  74. end
  75. end
  76.  
  77. function TransferItem(slot,from,amount)
  78. if from == "PayChest" then
  79. PayChest.pushItems(peripheral.getName(StoreChest),slot,amount)
  80. else
  81. StoreChest.pushItems(peripheral.getName(PayChest),slot,amount)
  82. end
  83. end
  84.  
  85.  
  86. local function PurchaseLoad(item,price,amount)
  87. local Total = price + (price * GovEc.GetTax("sales"))
  88. if CountCash(Total) == true then
  89. print("Correct Amount")
  90. if TakePayment(Total) == true then
  91. FindStoredItem(item,amount)
  92. Receipt.PrintReceipt(Company,"Commercial Purchase","Purchase Receipt","n",{{item,amount,price}})
  93. end
  94. end
  95. end
  96.  
  97. function Buy(I)
  98. print("loading...")
  99. if Items[I][5] == true then
  100. if BankNet_En == true then
  101. print("1 - Cash, 2 - Debit")
  102. local a, b
  103. repeat
  104. a, b = os.pullEvent("key")
  105. until b == keys.one or b == keys.two
  106. if b == keys.one then PurchaseLoad(Items[I][1],Items[I][4],Items[I][3]) elseif b == keys.two then if BankNet.charge(BankKey,Items[I][4])[1] == true then FindStoredItem(Items[I][1],Items[I][3]) Receipt.PrintReceipt(Company,"Commercial Purchase","Purchase Receipt","n",{{Items[I][2],Items[I][3],Items[I][4]}}) end end
  107. else
  108. PurchaseLoad(Items[I][1],Items[I][4],Items[I][3])
  109. end
  110. else
  111. error("Buying System not Implemented in Current Version, Contact Administrator for More Info")
  112. end
  113. end
  114.  
  115. function Menu()
  116. term.setBackgroundColor(colors.white)
  117. term.setTextColor(colors.black)
  118. term.clear()
  119. term.setCursorPos(1,1)
  120. print(Company.." Shop - "..Owner.." - V"..Version)
  121. end
  122.  
  123.  
  124. function Options()
  125. local n = 0
  126. local T = 1
  127. local a, b, c
  128. local Printed_Selling = {}
  129. local Printed_Buying = {}
  130. for i = 1, #Items do
  131. if Items[i][5] == true and Storage[i] == true then Printed_Selling[#Printed_Selling + 1] = {i,Items[i][2].." x"..Items[i][3].." - $"..(Items[i][4]+(Items[i][4]*GovEc.GetTax("sales")))} elseif Items[i][5] == true and Storage[i] == false then Printed_Selling[#Printed_Selling + 1] = {i,Items[i][2].." x"..Items[i][3].." - OUT OF STOCK"} end
  132. end
  133. local Gap = #Printed_Selling + 300
  134. print("==Selling==")
  135. repeat
  136. for i = 1, #Items do
  137. if i + 2 < Gap then term.setCursorPos(1,i + 2) else term.setCursorPos(1,i + 3) end
  138. term.clearLine()
  139. if T == i and i + 2 < Gap then term.write(">> "..Printed_Selling[i][2]) elseif i + 2 < Gap then term.write(Printed_Selling[i][2]) end
  140. end
  141. a, b, c = os.pullEvent("key")
  142. if b == keys.w and T > 1 then T = T - 1 end
  143. if b == keys.s and T < #Items then T = T + 1 end
  144. if b == keys.enter then n = T end
  145. until n ~= 0
  146. if Storage[n] == true then Buy(Printed_Selling[n][1]) end
  147. end
  148.  
  149. while true do
  150. start()
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement