Advertisement
Marlingaming

Chunk Purchase Terminal

Nov 2nd, 2022 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. local Folder = "LandPlots"
  2. local w, h = term.getSize()
  3. local Plots = {}
  4. local TileColors = {colors.green,colors.red,colors.blue}
  5.  
  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.  
  8. local PayChest = peripheral.wrap("top")
  9. local StoreChest = peripheral.wrap("bottom")
  10.  
  11. local Printer = peripheral.wrap("right")
  12.  
  13. local TaxRate = 0.01
  14. local Plot_Prices = {200,400,600}
  15.  
  16. local function Start()
  17. if Printer.getPaperLevel() > 0 then Map() else error("low supplies, contact administrator") end
  18. end
  19.  
  20. local function PrintReceipt(Pl,Cost)
  21. local Layout = {"Proof of Purchase",os.date(),"Deed to the chunk of "..Plots[Pl][1].." "..Plots[Pl][2],"Paid $"..Cost,"//Do not give away//","please keep in safe spot","Government issued Receipt"}
  22. Printer.newPage()
  23. for i = 1, #Layout do
  24. Printer.write(Layout[i])
  25. end
  26. Printer.setPageTitle("Deed for Plot #"..Pl)
  27. Printer.endPage()
  28. end
  29.  
  30. local function GetPlots()
  31. local plots = fs.list(Folder)
  32. for i = 1, #plots do
  33. local file = fs.open(fs.combine(Folder,plots[i]),"r")
  34. Plots[i] = textutils.unserialize(file.readAll())--chunkx,chunky,owner,mapx,mapy,type
  35. file.close()
  36. end
  37. end
  38.  
  39. local function Clear()
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. end
  43.  
  44. local function CurrencyCheck(name)
  45. local Worth = 0
  46. for i = 1, #Payment do
  47. if name == Payment[i][1] then Worth = Payment[i][2] end
  48. end
  49. return Worth
  50. end
  51.  
  52. local function CountCash(Target)
  53. local Pay = 0
  54. for slot, item in pairs(PayChest.list()) do
  55. Pay = Pay + (CurrencyCheck(item.name) * item.count)
  56. end
  57. Pass = false
  58. if Pay >= Target then Pass = true end
  59. return Pass
  60. end
  61.  
  62. local function TakePayment(Target)
  63. local Pay = 0
  64. Pass = false
  65. for slot, item in pairs(PayChest.list()) do
  66. local Cash = CurrencyCheck(item.name)
  67. repeat
  68. TransferItem(slot,1)
  69. if (Pay + Cash) <= Target then Pay = Pay + Cash end
  70. until (Pay + Cash) > Target
  71. end
  72. if Pay == Target then Pass = true end
  73. return Pass
  74. end
  75.  
  76. function TransferItem(slot,amount)
  77. PayChest.pushItems(peripheral.getName(StoreChest),slot,amount)
  78. end
  79.  
  80.  
  81. local function PurchaseLoad(Pl,price)
  82. if CountCash(price) == true then
  83. print("Correct Amount")
  84. if TakePayment(price) == true then
  85. print("printing receipt, please take with you")
  86. PrintReceipt(Pl,price)
  87. os.sleep(3)
  88. UpdatePlot(Pl)
  89. end
  90. end
  91. end
  92.  
  93. local function UpdatePlot(Pl)
  94. local Data = Plots[Pl]
  95. Data[3] = 2
  96. local plots = fs.list(Folder)
  97. local file = fs.open(fs.combine(Folder,plots[i]),"w")
  98. file.write(textutils.serialize(Data))
  99. file.close()
  100. os.reboot()
  101. end
  102.  
  103. local function PurchaseMenu(Pl)
  104. Clear()
  105. local Cost = Plot_Prices[Plots[Pl][6]] + (Plot_Prices[Plots[Pl][6]] * TaxRate)
  106. print("Chunk x"..Plots[Pl][1].." y"..Plots[Pl][2])
  107. print("price $"..Plot_Prices[Plots[Pl][6]])
  108. print("taxes $"..Plot_Prices[Plots[Pl][6]]*TaxRate)
  109. print("total $"..Cost)
  110. print("y/n")
  111. print("y purchase")
  112. print("n cancel")
  113. local e, k
  114. repeat
  115. e, k = os.pullEvent("key")
  116. until k == keys.y or k == keys.n
  117. if k == keys.y then
  118. PurchaseLoad(Pl,Cost)
  119. else
  120. Map()
  121. end
  122. end
  123.  
  124. function Map()
  125. GetPlots()
  126. term.setBackgroundColor(colors.black)
  127. term.setTextColor(colors.white)
  128. Clear()
  129. print("chunks for Sale")
  130. for i = 1, #Plots do
  131. paintutils.drawPixel(Plots[i][4],Plots[i][5],TileColors[Plots[i][3]])
  132. end
  133. term.setBackgroundColor(colors.black)
  134. local e, a, x, y
  135. repeat
  136. e, a, x, y = os.pullEvent("mouse_click")
  137. until e == "mouse_click"
  138. local I
  139. for i = 1, #Plots do
  140. if x == Plots[i][4] and y == Plots[i][5] and Plots[i][3] == 1 then
  141. I = i
  142. end
  143. end
  144. if I ~= nil then PurchaseMenu(I) else Map() end
  145. end
  146.  
  147. Start()
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement