DrFair

Enchant Monitor

Apr 2nd, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. m = peripheral.wrap("top")
  2. w,h = m.getSize()
  3. tID = 61
  4. w = w + 1
  5. h = h + 1
  6. col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
  7. rednet.open("right")
  8. menu = 0
  9. wait = false
  10. orders = {}
  11.  
  12. function loadmenus()
  13. menus = {}
  14. options = { [1]="Efficiency III", [2]="Efficiency IV", [3]="Fortune II", [4]="Fortune III", [5]="Silk Touch I", [6]="Unbreaking III", [7]="Repair I", [8]="Repair II", }
  15. table.insert(menus,textutils.serialize(options))
  16. options = { [1]="Sharpness III", [2]="Sharpness IV", [3]="Fire Aspect II", [4]="Vorpal I", [5]="Vorpal II", [6]="Soul Stealer III", [7]="Soul Stealer IV", [8]="Knockback II", [9]="Disjunction II", [10]="Disjunction III", [11]="Bane of Arthropods III", [12]="Bane of Arthropods IV", [13]="Smite III", [14]="Smite IV", }
  17. table.insert(menus,textutils.serialize(options))
  18. options = { [1]="Power III", [2]="Power IV", [3]="Flame I", [4]="Infinity I", }
  19. table.insert(menus,textutils.serialize(options))
  20. options = { [1]="Potency II", [2]="Potency III", [3]="Frugal III", [4]="Charging I", [5]="Treasure II", }
  21. table.insert(menus,textutils.serialize(options))
  22. options = { [1]="Protection III", [2]="Fire Protection III", [3]="Fire Protection IV", [4]="Blast Protection III", [5]="Blast Protection IV", [6]="Projectile Protection IV", [7]="Feather Falling IV", [8]="Haste II", [9]="Haste III", [10]="Aqua Affinity I", [11]="Respiration III", }
  23. table.insert(menus,textutils.serialize(options))
  24. end
  25.  
  26. function swrite(str,x,y,color)
  27. m.setCursorPos(x,y)
  28. m.setTextColor(col[color])
  29. m.write(str)
  30. end
  31.  
  32. function swritecenter(str,y,color)
  33. m.setCursorPos((w/2-#str/2)+1,y)
  34. m.setTextColor(col[color])
  35. m.write(str)
  36. end
  37.  
  38. function drawbox(str,x1,x2,y1,y2,strcol,color)
  39. m.setCursorPos(x1,y1)
  40. m.setBackgroundColor(col[color])
  41. m.setTextColor(col[strcol])
  42. local bw = x2-x1
  43. local bh = y2-y1
  44. local bstr = " "
  45. while #bstr < bw do
  46. bstr = bstr.." "
  47. end
  48. for i=1,bh do
  49. m.setCursorPos(x1,y1+i-1)
  50. m.write(bstr)
  51. end
  52. m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
  53. m.write(str)
  54. m.setBackgroundColor(col["black"])
  55. return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
  56. end
  57.  
  58. function drawtext(str,x,y,color)
  59. m.setCursorPos(x,y)
  60. m.setTextColor(col[color])
  61. m.write(str)
  62. return { [1]=x, [2]=x+1, [3]=y, [4]=y+#str }
  63. end
  64.  
  65. function press(but)
  66. if event == "monitor_touch" then
  67. if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
  68. return true
  69. else
  70. return false
  71. end
  72. end
  73. end
  74.  
  75. function drawoutline(str,strcol,color)
  76. m.setBackgroundColor(col[color])
  77. m.setTextColor(col[strcol])
  78. drawbox(str,1,w,1,2,strcol,color)
  79. drawbox("",1,2,1,h,strcol,color)
  80. drawbox("",w-1,w,1,h,strcol,color)
  81. drawbox("",1,w,h-1,h,strcol,color)
  82. end
  83.  
  84. function drawmenu()
  85. m.clear()
  86. drawoutline("Fair's Enchant System","black","white")
  87. if menu == 0 then
  88. cats = {}
  89. swritecenter("Pick a category.",3,"white")
  90. table.insert(cats,textutils.serialize(drawbox("Tool Enchants",w/2-15,w/2+15,5,8,"white","lime")))
  91. table.insert(cats,textutils.serialize(drawbox("Weapon Enchants",w/2-15,w/2+15,9,12,"white","lime")))
  92. table.insert(cats,textutils.serialize(drawbox("Bow Enchants",w/2-15,w/2+15,13,16,"white","lime")))
  93. table.insert(cats,textutils.serialize(drawbox("Wand Enchants",w/2-15,w/2+15,17,20,"white","lime")))
  94. table.insert(cats,textutils.serialize(drawbox("Armor Enchants",w/2-15,w/2+15,21,24,"white","lime")))
  95. else
  96. swritecenter("Pick enchants.",3,"white")
  97. options = textutils.unserialize(menus[menu])
  98. buttons = {}
  99. if (#options-6*page) > 6 then
  100. temp = 6
  101. else
  102. temp = (#options-6*page)
  103. end
  104. for i=1,temp do
  105. table.insert(buttons,textutils.serialize(drawbox(options[i+6*page],w/2-15,w/2+15,4+i,5+i,"white","black")))
  106. end
  107. swritecenter("Order list:",12,"white")
  108. orderbuttons = {}
  109. if #orders > 0 then
  110. for i=1,#orders do
  111. swritecenter(orders[i],12+i,"white")
  112. end
  113. undo = drawbox("UNDO",w/2+14,w/2+18,12+#orders,13+#orders,"white","red")
  114. accept = drawbox("Accept",w/2-6,w/2+7,22,25,"white","lime")
  115. else
  116. undo = drawbox("UNDO",w/2+14,w/2+18,120,130,"white","red")
  117. accept = drawbox("Accept",w/2-6,w/2+7,122,125,"white","lime")
  118. end
  119. back = drawbox("Back",w/2-17,w/2-7,22,25,"white","red")
  120. if #options > (page*6+temp) then
  121. next = drawbox("Next",w/2+8,w/2+18,22,25,"white","red")
  122. else
  123. next = drawbox("Next",w/2+8,w/2+18,100,101,"black","black")
  124. end
  125. end
  126. end
  127.  
  128. function draworder()
  129. drawbox("",w/2-16,w/2+16,4,21,"white","white")
  130. drawbox("",w/2-15,w/2+15,5,20,"white","black")
  131. swritecenter("Status:",6,"white")
  132. for i=1,#orders do
  133. if orderstats[i] then
  134. swritecenter(orders[i],7+i,"lime")
  135. else
  136. swritecenter(orders[i],7+i,"red")
  137. end
  138. end
  139. swritecenter(" ",17,"white")
  140. swritecenter(ordermsg,17,"white")
  141. end
  142.  
  143. loadmenus()
  144. drawmenu()
  145.  
  146. while true do
  147. event,pr1,pr2,pr3 = os.pullEvent()
  148. if not wait then
  149. if menu == 0 then
  150. for i=1,5 do
  151. if press(textutils.unserialize(cats[i])) then
  152. menu = i
  153. page = 0
  154. drawmenu()
  155. end
  156. end
  157. else
  158. if page == 0 then
  159. if press(back) then
  160. menu = 0
  161. drawmenu()
  162. end
  163. else
  164. if press(back) then
  165. page = page - 1
  166. drawmenu()
  167. end
  168. end
  169. if press(next) then
  170. page = page + 1
  171. drawmenu()
  172. elseif press(undo) then
  173. table.remove(orders,#orders)
  174. drawmenu()
  175. elseif press(accept) then
  176. wait = true
  177. orderstats = {}
  178. ordermsg = "Finding enchants.."
  179. for i=1,#orders do
  180. table.insert(orderstats,false)
  181. end
  182. draworder()
  183. end
  184. for i=1,temp do
  185. if press(textutils.unserialize(buttons[i])) and #orders < 8 then
  186. table.insert(orders,options[i+6*page])
  187. drawmenu()
  188. end
  189. end
  190. end
  191. else
  192.  
  193. end
  194. end
Advertisement
Add Comment
Please, Sign In to add comment