Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Items = {}
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function GetItems()
- local file = fs.open("system/ItemList.txt","r")
- local Contents = file.readAll()
- Items = textutils.unserialize(Contents)
- file.close()
- end
- function DisplayItems()
- local X = 2
- local Y = 2
- for i + 1, #Items do
- term.setCursorPos(1,i + 1)
- term.write(Items[i][1])
- end
- end
- function TouchCUI()
- local n = 0
- while true do
- local event, a, b, c = os.pullEvent("mouse_click")
- for i = 1, #Items do
- if c == i + 1 then n = i end
- end
- if n > 0 then break end
- end
- return n
- end
- function Menu()
- term.setBackgroundColor(colors.lightBlue)
- Clear()
- print("shopping Terminal")
- DisplayItems()
- DisplayItem(TouchCUI())
- Menu()
- end
- function DisplayItem(I)
- Clear()
- print(Items[I][1], " for ", Items[I][3])
- print("buy 1")
- print("buy 5")
- print("cancel")
- local event, a, b, c
- repeat
- event, a, b, c = os.pullEvent("mouse_click")
- until c == 2 or c == 3 or c == 4
- local Amount = 0
- if c == 2 then
- Amount = 1
- elseif c == 3 then
- Amount = 5
- elseif c == 4 then
- Amount = 0
- end
- if Amount > 0 then
- if Transaction(I,Amount) == true then Transfer(I,Amount) end
- end
- end
- function Transfer(I,A)
- local ChestA = peripheral.find("minecraft:chest_0")
- local ChestB = peripheral.find("minecraft:chest_1")
- local List = ChestA.list()
- local Req = 0
- for i = 1, #List do
- if Req < A then
- local Item = ChestA.getItemDetail(i)
- if Item.displayName == Items[I][1] then
- 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
- end
- end
- end
- end
- function Transaction(item, Amount)
- local Result
- while true do
- shell.run("Trans",Items[item][3] * Amount, Items[item][1])
- local event, a, b = os.pullEvent()
- if event == "Transaction_Accepted" then
- print("accepted")
- Result = true
- break
- elseif event == "Transaction_Declined" then
- print("declined: ", a)
- Result = false
- break
- end
- end
- return Result
- end
Add Comment
Please, Sign In to add comment