DrFair

Mob Farms

Jul 31st, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. m = peripheral.wrap("back")
  2. w,h = m.getSize()
  3. w = w+1
  4. h = h+1
  5. page = 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("top")
  8. mobfarmsname = { [1]="ZombiePig Farm", [2]="Blaze Farm", }
  9. mobfarmscode = { [1]="zombiepig", [2]="blaze", }
  10. mobfarmsactive = { [1]=false, [2]=false, }
  11. mobfarmsbutton = {}
  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. m.clear()
  57. drawbackground("Mob Farms","black","white")
  58. if page > 1 then
  59. back = drawbox("Back",4,w/2-2,h-5,h-2,"white","red")
  60. end
  61. for i=1,3 do
  62. if mobfarmsname[i+(page-1)*3] == nil then
  63. mobfarmsbutton[i+(page-1)*3] = drawbox("",w+4,w+6,4,4,"black","black")
  64. else
  65. if mobfarmsactive[i+(page-1)*3] then color = "green" else color = "red" end
  66. mobfarmsbutton[i+(page-1)*3] = textutils.serialize(drawbox(mobfarmsname[i+(page-1)*3],4,w-3,4*i-1,4*i+2,"white",color))
  67. end
  68. if i == 3 and mobfarmsname[i+(page-1)*3+1] ~= nil then
  69. next = drawbox("Next",w/2+2,w-3,h-5,h-2,"white","green")
  70. else
  71. next = drawbox("Next",w/2+2,w-3,h+5,h+2,"white","green")
  72. end
  73. end
  74. end
  75.  
  76. function updatemobfarms()
  77. for i=1,#mobfarmsactive do
  78. if mobfarmsactive[i] then
  79. rednet.broadcast(mobfarmscode[i].."on")
  80. else
  81. rednet.broadcast(mobfarmscode[i].."off")
  82. end
  83. end
  84. drawmenu()
  85. end
  86.  
  87. drawmenu()
  88. updatemobfarms()
  89.  
  90. while true do
  91. event,pr1,pr2,pr3 = os.pullEvent()
  92. for i=1,3 do
  93. if mobfarmsname[i+(page-1)*3] ~= nil then
  94. if press(textutils.unserialize(mobfarmsbutton[i+(page-1)*3])) then
  95. mobfarmsactive[i+(page-1)*3] = not mobfarmsactive[i+(page-1)*3]
  96. updatemobfarms()
  97. end
  98. end
  99. end
  100. if page > 1 then
  101. if press(back) then
  102. page = page - 1
  103. drawmenu()
  104. end
  105. end
  106. if press(next) then
  107. page = page + 1
  108. drawmenu()
  109. end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment