Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- os.loadAPI("pimPayment")
- os.loadAPI("strSplit")
- os.loadAPI("loadInventory")
- m = peripheral.wrap("monitor_28")
- m.clear()
- local items = {}
- local displayedItems = {} -- 12 long max
- local curIndex = 1
- local tX = {5,17,29,41,53,65}
- local tY = {3, 11}
- function fillTable()
- y1 = 7
- y2 = 9
- y3 = 15
- y4 = 17
- button.setTable(1,"Purchase", b1, 5,15,y1,y2)
- button.setTable(2,"Purchase", b2, 17,27,y1,y2)
- button.setTable(3, "Purchase", b3, 29, 39, y1,y2)
- button.setTable(4, "Purchase", b4, 41, 51, y1,y2)
- button.setTable(5, "Purchase", b5,53, 63, y1, y2)
- button.setTable(6,"Purchase", b6, 65,75, y1, y2)
- button.setTable(7,"Purchase", b7, 5,15,y3,y4)
- button.setTable(8, "Purchase", b8, 17,27,y3,y4)
- button.setTable(9, "Purchase", b9, 29, 39, y3,y4)
- button.setTable(10, "Purchase", b10,41,51,y3,y4)
- button.setTable(11,"Purchase", b11, 53,63, y3,y4)
- button.setTable(12,"Purchase", b12, 65,75, y3,y4)
- button.setTable(13, "Previous", bPrev, 5,15, 20,22)
- button.setTable(14,"Next", bNext, 65,75, 20,22)
- -- button.
- button.screen()
- end
- function getClick()
- event,side,x,y = os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- function purchase(ind)
- if displayedItems[ind] ~= nil then
- if pimPayment.deductFunds(displayedItems[ind][2]) then
- --put item in
- loadInventory.giveItem(displayedItems[ind][1])
- if pimPayment.giveItemToPIM(displayedItems[ind][1],1) then
- print("Item Transferred")
- else
- print("Player moved off pad")
- end
- end
- end
- sleep(2)
- end
- function b1()
- button.flash(1)
- purchase(1)
- end
- function b2()
- button.flash(2)
- purchase(2)
- end
- function b3()
- button.flash(3)
- purchase(3)
- end
- function b4()
- button.flash(4)
- purchase(4)
- end
- function b5()
- button.flash(5)
- purchase(5)
- end
- function b6()
- button.flash(6)
- purchase(6)
- end
- function b7()
- button.flash(7)
- purchase(7)
- end
- function b8()
- button.flash(8)
- purchase(8)
- end
- function b9()
- button.flash(9)
- purchase(9)
- end
- function b10()
- button.flash(10)
- purchase(10)
- end
- function b11()
- button.flash(11)
- purchase(11)
- end
- function b12()
- button.flash(12)
- purchase(12)
- end
- function bPrev()
- button.flash(13)
- curIndex = curIndex - 12
- if curIndex < 0 then
- curIndex = #items + curIndex
- end
- setDisplay(items)
- end
- function bNext()
- button.flash(14)
- curIndex = curIndex + 12
- if curIndex > #items then
- curIndex = curIndex - #items
- end
- setDisplay(items)
- end
- function compare(a,b)
- return a[2] < b[2]
- end
- function setDisplay(availableItems)
- j = 1
- for i = curIndex, curIndex + 11 do
- newInd = i
- if newInd > #availableItems then
- newInd = newInd - #availableItems
- end
- n = availableItems[newInd][1]
- c = availableItems[newInd][2]
- displayedItems[j] = {n, c}
- writeItemNameandCost(j, n, c)
- print(n .. ": " .. c)
- j = j + 1
- end
- end
- function write(x,y, text, color)
- m.setCursorPos(x,y)
- m.setTextColor( color )
- m.write(text)
- m.setTextColor( colors.white )
- end
- function writeItemNameandCost(ind, name, cost)
- y = 1
- x = ind
- if ind > 6 then
- x = x - 6
- y = 2
- end
- x = tX[x]
- y = tY[y]
- if x == nil then
- print("X IS NIL!")
- print("Ind: " .. ind)
- end
- if y == nil then
- print("Y IS NIL!")
- print("Ind: " .. ind)
- end
- names = strSplit.lines(name)
- y = y - 1
- a = 1
- for a = 1, #names do
- xc = (11 - (#names[a]))/2
- write(x+xc,y+a, names[a], colors.yellow)
- end
- ccost = cost .. " ic"
- xc = (11 - #ccost)/2
- write(x+xc,y+4, ccost, colors.lime)
- end
- fillTable()
- loadInventory.init()
- --button.label(1,5,"Demo!")
- while true do
- m.clear()
- button.heading("The Lucky Diamond")
- iList = loadInventory.buildChestsItemList() --Everything in chests
- items = loadInventory.getChestItemsInTable(iList) --Everything that has a price (only 1 instance of it)
- table.sort(items, compare)
- setDisplay(items)
- button.screen()
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement