Capt-O

Direwolf's MobControl

Apr 15th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local term = peripheral.wrap("top")
  2. term.setTextScale(1.5)
  3. local mob={}
  4.  
  5. function setTable(name, freq, xmin, xmax, ymin, ymax)
  6.    mob[name] = {}
  7.    mob[name]["freq"] = freq
  8.    mob[name]["active"] = false
  9.    mob[name]["xmin"] = xmin
  10.    mob[name]["ymin"] = ymin
  11.    mob[name]["xmax"] = xmax
  12.    mob[name]["ymax"] = ymax
  13. end
  14.  
  15. function fillTable()
  16.    setTable("Chicken", colors.red, 17, 24, 2, 3)
  17.    setTable("Cow", colors.white, 17, 20, 6, 7)
  18.    setTable("Pig", colors.yellow, 17, 20, 4, 5)
  19. end
  20.  
  21. function fill(x,y,color,text)
  22.   term.setBackgroundColor(color)
  23.   term.setCursorPos(x,y)
  24.   term.write(text)
  25.   term.setBackgroundColor(colors.black)
  26. end
  27.  
  28. function screen()
  29.    local y = 2
  30.    local currColor
  31.    for name,data in pairs(mob) do
  32.       local on = data["active"]
  33.       if on == true then currColor = colors.lime else currColor = colors.red end
  34.       fill(17,y,currColor, name)
  35.       y = y+2
  36.    end
  37. end
  38.  
  39. function checkxy(x, y)
  40.    for name, data in pairs(mob) do
  41.       if y>=data["ymin"] and  y <= data["ymax"] then
  42.         if x>=data["xmin"] and x<= data["xmax"] then
  43.           data["active"] = not data["active"]
  44.           print(name)
  45.         end
  46.       end
  47.    end
  48. end
  49.  
  50. function setWire()
  51.    local wire = 0
  52.    for name, data in pairs(mob) do
  53.       if data["active"] == false then
  54.          wire = colors.combine(wire, data["freq"])
  55.       end
  56.    end
  57.    redstone.setBundledOutput("bottom", wire)
  58. end
  59.  
  60. fillTable()
  61. setWire()
  62. while true do
  63.   term.clear()
  64.   screen()
  65. --  fill(17,2,colors.lime, "Chicken")
  66.   local e,side,x,y = os.pullEvent("monitor_touch")
  67.   print(x..":"..y)
  68.   checkxy(x,y)
  69.   setWire()
  70.   sleep(.1)
  71. end
Add Comment
Please, Sign In to add comment