Guest User

mobcontrol

a guest
Jul 15th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2.         mon.setTextScale(1)
  3.         local button={}  
  4.         function setTable(name, func, xmin, xmax, ymin, ymax, freq)
  5.            button[name] = {}
  6.            button[name]["func"] = func
  7.            button[name]["active"] = false
  8.            button[name]["xmin"] = xmin
  9.            button[name]["ymin"] = ymin
  10.            button[name]["xmax"] = xmax
  11.            button[name]["ymax"] = ymax
  12.            button[name]["freq"] = freq
  13.            end
  14.          
  15.         function funcName()
  16.            print("You clicked buttonText")
  17.         end
  18.                
  19.                
  20.         function fillTable()
  21.            setTable("Blaze", funcName, 2, 12, 4, 6, colors.lightBlue)
  22.            setTable("Skeleton", funcName, 2, 12, 8, 10, colors.red)
  23.            setTable("Pigmen", funcName, 2, 12, 12, 14, colors.orange)
  24.            setTable("Zombie", funcName, 2, 12, 16, 18, colors.blue)
  25.            setTable("Wither", funcName, 16, 25, 4, 6, colors.brown)
  26.            setTable("Creeper", funcName, 16, 25, 8, 10, colors.magenta)
  27.            setTable("Witch", funcName, 16, 25, 12, 14, colors.white)
  28.            setTable("Cow", funcName, 16, 25, 16, 18, colors.green)
  29.            setTable("Blizz", funcName, 29, 38, 4, 6, colors.cyan)
  30.            setTable("Endermen", funcName, 29, 38, 8, 10, colors.yellow)    
  31.          end    
  32.          
  33.         function fill(text, color, bData)
  34.            mon.setBackgroundColor(color)
  35.            local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  36.            local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  37.            for j = bData["ymin"], bData["ymax"] do
  38.               mon.setCursorPos(bData["xmin"], j)
  39.               if j == yspot then
  40.                  for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  41.                     if k == xspot then
  42.                        mon.write(text)
  43.                     else
  44.                        mon.write(" ")
  45.                     end
  46.                  end
  47.               else
  48.                  for i = bData["xmin"], bData["xmax"] do
  49.                     mon.write(" ")
  50.                  end
  51.               end
  52.            end
  53.            mon.setBackgroundColor(colors.black)
  54.         end
  55.              
  56.         function screen()
  57.            local currColor
  58.            for name,data in pairs(button) do
  59.               local on = data["active"]
  60.               if on == true then currColor = colors.lime else currColor = colors.red end
  61.               fill(name, currColor, data)
  62.            end
  63.         end
  64.                    
  65.         function checkxy(x, y)
  66.            for name, data in pairs(button) do
  67.               if y>=data["ymin"] and  y <= data["ymax"] then
  68.                  if x>=data["xmin"] and x<= data["xmax"] then
  69.                     data["func"]()
  70.                     data["active"] = not data["active"]
  71.                     print(name)
  72.                  end
  73.               end
  74.            end
  75.         end
  76.      
  77.     function setWire()
  78.        local wire = 0
  79.        for name, data in pairs(button) do
  80.           if data["active"] == false then
  81.              wire = colors.combine(wire, data["freq"])
  82.           end
  83.        end
  84.        redstone.setBundledOutput("bottom", wire)
  85.     end
  86.            
  87.         function heading(text)
  88.            w, h = mon.getSize()
  89.            mon.setCursorPos((w-string.len(text))/2+1, 1)
  90.            mon.write(text)
  91.         end
  92.              
  93.         fillTable()
  94.             setWire()
  95.         while true do
  96.            mon.clear()
  97.            heading("Mob Farm Control")
  98.            screen()
  99.            local e,side,x,y = os.pullEvent("monitor_touch")
  100.            print(x..":"..y)
  101.            checkxy(x,y)
  102.                setWire()
  103.            sleep(.1)
  104.         end
Advertisement
Add Comment
Please, Sign In to add comment