Marlingaming

Kiosk 1

Mar 7th, 2022 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. local Items = {}
  2.  
  3. local function Clear()
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. end
  7.  
  8. function GetItems()
  9. local file = fs.open("system/ItemList.txt","r")
  10. local Contents = file.readAll()
  11. Items = textutils.unserialize(Contents)
  12. file.close()
  13. end
  14.  
  15. function DisplayItems()
  16. local X = 2
  17. local Y = 2
  18. for i + 1, #Items do
  19. term.setCursorPos(1,i + 1)
  20. term.write(Items[i][1])
  21. end
  22. end
  23.  
  24. function TouchCUI()
  25. local n = 0
  26. while true do
  27. local event, a, b, c = os.pullEvent("mouse_click")
  28. for i = 1, #Items do
  29. if c == i + 1 then n = i end
  30. end
  31. if n > 0 then break end
  32. end
  33. return n
  34. end
  35.  
  36. function Menu()
  37. term.setBackgroundColor(colors.lightBlue)
  38. Clear()
  39. print("shopping Terminal")
  40. DisplayItems()
  41. DisplayItem(TouchCUI())
  42. Menu()
  43. end
  44.  
  45. function DisplayItem(I)
  46. Clear()
  47. print(Items[I][1], " for ", Items[I][3])
  48. print("buy 1")
  49. print("buy 5")
  50. print("cancel")
  51. local event, a, b, c
  52. repeat
  53. event, a, b, c = os.pullEvent("mouse_click")
  54. until c == 2 or c == 3 or c == 4
  55. local Amount = 0
  56. if c == 2 then
  57. Amount = 1
  58. elseif c == 3 then
  59. Amount = 5
  60. elseif c == 4 then
  61. Amount = 0
  62. end
  63. if Amount > 0 then
  64. if Transaction(I,Amount) == true then Transfer(I,Amount) end
  65. end
  66. end
  67.  
  68. function Transfer(I,A)
  69. local ChestA = peripheral.find("minecraft:chest_0")
  70. local ChestB = peripheral.find("minecraft:chest_1")
  71. local List = ChestA.list()
  72. local Req = 0
  73. for i = 1, #List do
  74. if Req < A then
  75. local Item = ChestA.getItemDetail(i)
  76. if Item.displayName == Items[I][1] then
  77. if Item.count => A then Req = A ChestA.pushItems(ChestB,i,{limit = A - Req}) else Req = Req + Item.count ChestA.pushItems(ChestB,i,{limit = A - Req}) end
  78. end
  79. end
  80. end
  81. end
  82.  
  83. function Transaction(item, Amount)
  84. local Result
  85. while true do
  86. shell.run("Trans",Items[item][3] * Amount, Items[item][1])
  87. local event, a, b = os.pullEvent()
  88. if event == "Transaction_Accepted" then
  89. print("accepted")
  90. Result = true
  91. break
  92. elseif event == "Transaction_Declined" then
  93. print("declined: ", a)
  94. Result = false
  95. break
  96. end
  97. end
  98. return Result
  99. end
Add Comment
Please, Sign In to add comment