DrFair

resupplier

Mar 18th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. rednet.open("right")
  2. m = peripheral.wrap("top")
  3. wr = peripheral.wrap("left")
  4. w,h = m.getSize()
  5. w = w + 1
  6. h = h + 1
  7. value = 64
  8. 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 }
  9.  
  10. function pulse(freq,num)
  11. wr.setFreq(freq)
  12. for i=1,num do
  13. redstone.setOutput("left",true)
  14. os.sleep(0.1)
  15. redstone.setOutput("left",false)
  16. os.sleep(0.2)
  17. end
  18. end
  19.  
  20. function swrite(str,x,y,color)
  21. m.setCursorPos(x,y)
  22. m.setTextColor(col[color])
  23. m.write(str)
  24. end
  25.  
  26. function swritecenter(str,y,color)
  27. m.setCursorPos((w/2-#str/2)+1,y)
  28. m.setTextColor(col[color])
  29. m.write(str)
  30. end
  31.  
  32. function drawbox(str,x1,x2,y1,y2,strcol,color)
  33. m.setCursorPos(x1,y1)
  34. m.setBackgroundColor(col[color])
  35. m.setTextColor(col[strcol])
  36. local bw = x2-x1
  37. local bh = y2-y1
  38. local bstr = " "
  39. while #bstr < bw do
  40. bstr = bstr.." "
  41. end
  42. for i=1,bh do
  43. m.setCursorPos(x1,y1+i-1)
  44. m.write(bstr)
  45. end
  46. m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
  47. m.write(str)
  48. m.setBackgroundColor(col["black"])
  49. return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
  50. end
  51.  
  52. function drawtext(str,x,y,color)
  53. m.setCursorPos(x,y)
  54. m.setTextColor(col[color])
  55. m.write(str)
  56. return { [1]=x, [2]=x+1, [3]=y, [4]=y+#str }
  57. end
  58.  
  59. function press(but)
  60. if event == "monitor_touch" then
  61. if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
  62. return true
  63. else
  64. return false
  65. end
  66. end
  67. end
  68.  
  69. function drawoutline(str,strcol,color)
  70. m.setBackgroundColor(col[color])
  71. m.setTextColor(col[strcol])
  72. drawbox(str,1,w,1,2,strcol,color)
  73. drawbox("",1,2,1,h,strcol,color)
  74. drawbox("",w-1,w,1,h,strcol,color)
  75. drawbox("",1,w,h-1,h,strcol,color)
  76. end
  77.  
  78. function drawmenu()
  79. m.clear()
  80. drawoutline("Fair's resupply system","black","white")
  81. bronze = drawbox("Bronze",4,19,3,6,"black","blue")
  82. brass = drawbox("Brass",22,37,3,6,"black","blue")
  83. redaingot = drawbox("Red AIngot",4,19,7,10,"black","blue")
  84. blueaingot = drawbox("Blue AIngot",22,37,7,10,"black","blue")
  85. riron = drawbox("Ref. Iron",4,19,11,14,"black","blue")
  86. smoothstone = drawbox("Smoothstone",22,37,11,14,"black","blue")
  87. sand = drawbox("Sand",4,19,15,18,"black","blue")
  88. glass = drawbox("Glass",22,37,15,18,"black","blue")
  89. obsidian = drawbox("Obsidian",4,19,19,22,"black","blue")
  90. planks = drawbox("Wood Planks",22,37,19,22,"black","blue")
  91. negplus = drawtext("--",14,23,"white")
  92. neg = drawtext("-",17,23,"white")
  93. swritecenter(" "..value.." ",23,"white")
  94. addplus = drawtext("++",26,23,"white")
  95. add = drawtext("+",24,23,"white")
  96. end
  97.  
  98. function drawvalue()
  99. swritecenter(" "..value.." ",23,"white")
  100. end
  101.  
  102. drawmenu()
  103.  
  104. while true do
  105. event,pr1,pr2,pr3 = os.pullEvent()
  106.  
  107. if press(negplus) then
  108. value = value - 64
  109. if value < 4 then
  110. value = 4
  111. end
  112. drawvalue()
  113. elseif press(neg) then
  114. value = value - 4
  115. if value < 4 then
  116. value = 4
  117. end
  118. drawvalue()
  119. elseif press(addplus) then
  120. value = value + 64
  121. if value > 320 then
  122. value = 320
  123. end
  124. drawvalue()
  125. elseif press(add) then
  126. value = value + 4
  127. if value > 320 then
  128. value = 320
  129. end
  130. drawvalue()
  131. elseif press(bronze) then
  132.  
  133. elseif press(brass) then
  134.  
  135. elseif press(redaingot) then
  136.  
  137. elseif press(blueaingot) then
  138.  
  139. elseif press(riron) then
  140. pulse(2222,value)
  141. elseif press(smoothstone) then
  142. pulse(2224,value)
  143. elseif press(sand) then
  144. pulse(2225,value)
  145. elseif press(glass) then
  146. pulse(2223,value)
  147. elseif press(obsidian) then
  148.  
  149. elseif press(planks) then
  150.  
  151. end
  152. end
Advertisement
Add Comment
Please, Sign In to add comment