Advertisement
Zantag

shop

Sep 13th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. os.loadAPI("button")
  2. os.loadAPI("pimPayment")
  3. os.loadAPI("strSplit")
  4. os.loadAPI("loadInventory")
  5. m = peripheral.wrap("monitor_28")
  6. m.clear()
  7.  
  8. local items = {}
  9. local displayedItems = {} -- 12 long max
  10. local curIndex = 1
  11. local tX = {5,17,29,41,53,65}
  12. local tY = {3, 11}
  13. function fillTable()
  14. y1 = 7
  15. y2 = 9
  16. y3 = 15
  17. y4 = 17
  18. button.setTable(1,"Purchase", b1, 5,15,y1,y2)
  19. button.setTable(2,"Purchase", b2, 17,27,y1,y2)
  20. button.setTable(3, "Purchase", b3, 29, 39, y1,y2)
  21. button.setTable(4, "Purchase", b4, 41, 51, y1,y2)
  22. button.setTable(5, "Purchase", b5,53, 63, y1, y2)
  23. button.setTable(6,"Purchase", b6, 65,75, y1, y2)
  24. button.setTable(7,"Purchase", b7, 5,15,y3,y4)
  25. button.setTable(8, "Purchase", b8, 17,27,y3,y4)
  26. button.setTable(9, "Purchase", b9, 29, 39, y3,y4)
  27. button.setTable(10, "Purchase", b10,41,51,y3,y4)
  28. button.setTable(11,"Purchase", b11, 53,63, y3,y4)
  29. button.setTable(12,"Purchase", b12, 65,75, y3,y4)
  30.  
  31. button.setTable(13, "Previous", bPrev, 5,15, 20,22)
  32. button.setTable(14,"Next", bNext, 65,75, 20,22)
  33. -- button.
  34. button.screen()
  35. end
  36.  
  37. function getClick()
  38. event,side,x,y = os.pullEvent("monitor_touch")
  39. button.checkxy(x,y)
  40. end
  41. function purchase(ind)
  42. if displayedItems[ind] ~= nil then
  43. if pimPayment.deductFunds(displayedItems[ind][2]) then
  44. --put item in
  45. loadInventory.giveItem(displayedItems[ind][1])
  46. if pimPayment.giveItemToPIM(displayedItems[ind][1],1) then
  47. print("Item Transferred")
  48. else
  49. print("Player moved off pad")
  50. end
  51. end
  52. end
  53. sleep(2)
  54. end
  55. function b1()
  56. button.flash(1)
  57. purchase(1)
  58. end
  59. function b2()
  60. button.flash(2)
  61. purchase(2)
  62. end
  63. function b3()
  64. button.flash(3)
  65. purchase(3)
  66. end
  67. function b4()
  68. button.flash(4)
  69. purchase(4)
  70. end
  71. function b5()
  72. button.flash(5)
  73. purchase(5)
  74. end
  75. function b6()
  76. button.flash(6)
  77. purchase(6)
  78. end
  79. function b7()
  80. button.flash(7)
  81. purchase(7)
  82. end
  83. function b8()
  84. button.flash(8)
  85. purchase(8)
  86. end
  87. function b9()
  88. button.flash(9)
  89. purchase(9)
  90. end
  91. function b10()
  92. button.flash(10)
  93. purchase(10)
  94. end
  95. function b11()
  96. button.flash(11)
  97. purchase(11)
  98. end
  99. function b12()
  100. button.flash(12)
  101. purchase(12)
  102. end
  103.  
  104.  
  105. function bPrev()
  106. button.flash(13)
  107. curIndex = curIndex - 12
  108. if curIndex < 0 then
  109. curIndex = #items + curIndex
  110. end
  111. setDisplay(items)
  112. end
  113.  
  114. function bNext()
  115. button.flash(14)
  116. curIndex = curIndex + 12
  117. if curIndex > #items then
  118. curIndex = curIndex - #items
  119. end
  120. setDisplay(items)
  121. end
  122.  
  123. function compare(a,b)
  124. return a[2] < b[2]
  125. end
  126.  
  127. function setDisplay(availableItems)
  128. j = 1
  129. for i = curIndex, curIndex + 11 do
  130. newInd = i
  131. if newInd > #availableItems then
  132. newInd = newInd - #availableItems
  133. end
  134. n = availableItems[newInd][1]
  135. c = availableItems[newInd][2]
  136. displayedItems[j] = {n, c}
  137. writeItemNameandCost(j, n, c)
  138. print(n .. ": " .. c)
  139. j = j + 1
  140. end
  141. end
  142. function write(x,y, text, color)
  143. m.setCursorPos(x,y)
  144. m.setTextColor( color )
  145. m.write(text)
  146. m.setTextColor( colors.white )
  147.  
  148. end
  149. function writeItemNameandCost(ind, name, cost)
  150. y = 1
  151. x = ind
  152. if ind > 6 then
  153. x = x - 6
  154. y = 2
  155. end
  156. x = tX[x]
  157. y = tY[y]
  158. if x == nil then
  159. print("X IS NIL!")
  160. print("Ind: " .. ind)
  161. end
  162. if y == nil then
  163. print("Y IS NIL!")
  164. print("Ind: " .. ind)
  165. end
  166.  
  167. names = strSplit.lines(name)
  168. y = y - 1
  169. a = 1
  170. for a = 1, #names do
  171. xc = (11 - (#names[a]))/2
  172. write(x+xc,y+a, names[a], colors.yellow)
  173. end
  174. ccost = cost .. " ic"
  175. xc = (11 - #ccost)/2
  176. write(x+xc,y+4, ccost, colors.lime)
  177.  
  178. end
  179. fillTable()
  180.  
  181. loadInventory.init()
  182. --button.label(1,5,"Demo!")
  183.  
  184. while true do
  185. m.clear()
  186. button.heading("The Lucky Diamond")
  187. iList = loadInventory.buildChestsItemList() --Everything in chests
  188. items = loadInventory.getChestItemsInTable(iList) --Everything that has a price (only 1 instance of it)
  189. table.sort(items, compare)
  190. setDisplay(items)
  191. button.screen()
  192. getClick()
  193.  
  194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement