DrFair

Chicken Soul Farm

Jun 11th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. m = peripheral.wrap("top")
  2. w,h = m.getSize()
  3. w = w+1
  4. h = h+1
  5. 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 }
  6. dispenser = false
  7. extractor = false
  8. os.startTimer(1)
  9. cart = 0
  10. rednet.open("right")
  11. rednet.broadcast("dispoff")
  12.  
  13. function swrite(str,x,y,color)
  14. m.setCursorPos(x,y)
  15. m.setTextColor(col[color])
  16. m.write(str)
  17. end
  18.  
  19. function drawbox(str,x1,x2,y1,y2,strcol,color)
  20. m.setCursorPos(x1,y1)
  21. m.setBackgroundColor(col[color])
  22. m.setTextColor(col[strcol])
  23. local bw = x2-x1
  24. local bh = y2-y1
  25. local bstr = " "
  26. while #bstr < bw do
  27. bstr = bstr.." "
  28. end
  29. for i=1,bh do
  30. m.setCursorPos(x1,y1+i-1)
  31. m.write(bstr)
  32. end
  33. m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
  34. m.write(str)
  35. m.setBackgroundColor(col["black"])
  36. return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
  37. end
  38.  
  39. function press(but)
  40. if event == "monitor_touch" then
  41. if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
  42. return true
  43. else
  44. return false
  45. end
  46. end
  47. end
  48.  
  49. function drawbackground(str,strcol,color)
  50. drawbox("",1,w,1,h,strcol,color)
  51. drawbox("",2,w-1,2,h-1,"black","black")
  52. drawbox(str,1,w,1,2,strcol,color)
  53. end
  54.  
  55. function drawmenu()
  56. if dispenser then
  57. disb = drawbox("Egg Dispenser",4,w-3,5,8,"black","green")
  58. rednet.broadcast("dispon")
  59. else
  60. disb = drawbox("Egg Dispenser",4,w-3,5,8,"black","red")
  61. rednet.broadcast("dispoff")
  62. end
  63. if extractor then
  64. extb = drawbox("Chicken Carts",4,w-3,10,13,"black","green")
  65. else
  66. extb = drawbox("Chicken Carts",4,w-3,10,13,"black","red")
  67. end
  68. end
  69.  
  70. drawbackground("Chicken Soul Farm","black","white")
  71. drawmenu()
  72.  
  73. while true do
  74. event,pr1,pr2,pr3 = os.pullEvent()
  75. if press(disb) then
  76. dispenser = not dispenser
  77. drawmenu()
  78. elseif press(extb) then
  79. extractor = not extractor
  80. drawmenu()
  81. end
  82. if event == "timer" then
  83. if dispenser then
  84. rs.setOutput("bottom",not rs.getOutput("bottom"))
  85. end
  86. if extractor then
  87. cart = cart + 1
  88. if cart == 2 then
  89. rs.setOutput("back",not rs.getOutput("back"))
  90. cart = 0
  91. end
  92. end
  93. os.startTimer(1)
  94. end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment