DeliciousJaffa

Shard spawner room (Potato Craft)

Mar 23rd, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. mon.setTextScale(1)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6.      
  7. function setTable(name, func, xmin, xmax, ymin, ymax)
  8.    button[name] = {}
  9.    button[name]["func"] = func
  10.    button[name]["active"] = false
  11.    button[name]["xmin"] = xmin
  12.    button[name]["ymin"] = ymin
  13.    button[name]["xmax"] = xmax
  14.    button[name]["ymax"] = ymax
  15. end
  16.  
  17. function skeleClick(state)
  18.   print(state)
  19.   redstone.setOutput("right",state)
  20. end
  21.  
  22. function zombClick(state)
  23.   print(state)
  24.   redstone.setOutput("left",state)
  25. end
  26.        
  27. function fillTable()
  28.    setTable("Skeleton", skeleClick, 2, 28, 3, 9)
  29.    setTable("Zombie", zombClick, 2, 28, 12, 18)
  30. end    
  31.  
  32. function fill(text, color, bData)
  33.    mon.setBackgroundColor(color)
  34.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  35.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  36.    for j = bData["ymin"], bData["ymax"] do
  37.       mon.setCursorPos(bData["xmin"], j)
  38.       if j == yspot then
  39.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  40.             if k == xspot then
  41.                mon.write(text)
  42.             else
  43.                mon.write(" ")
  44.             end
  45.          end
  46.       else
  47.          for i = bData["xmin"], bData["xmax"] do
  48.             mon.write(" ")
  49.          end
  50.       end
  51.    end
  52.    mon.setBackgroundColor(colors.black)
  53. end
  54.      
  55. function screen()
  56.    local currColor
  57.    for name,data in pairs(button) do
  58.       local on = data["active"]
  59.       if on == true then currColor = colors.lime else currColor = colors.red end
  60.       fill(name, currColor, data)
  61.    end
  62. end
  63.      
  64. function checkxy(x, y)
  65.    for name, data in pairs(button) do
  66.       if y>=data["ymin"] and  y <= data["ymax"] then
  67.          if x>=data["xmin"] and x<= data["xmax"] then
  68.             data["active"] = not data["active"]
  69.             data["func"](data["active"])
  70.          end
  71.       end
  72.    end
  73. end
  74.      
  75. function center(line,text)
  76.    w, h = mon.getSize()
  77.    mon.setCursorPos((w-string.len(text))/2+1, line)
  78.    mon.write(text)
  79. end
  80.      
  81. fillTable()
  82. skeleClick(false)
  83. zombClick(false)
  84. while true do
  85.    mon.clear()
  86.    center(1,"Spawner On/Off")
  87.    screen()
  88.    local e,side,x,y = os.pullEvent()
  89.    if e == "redstone" then
  90.     sleep(0.25)
  91.     if redstone.getInput("bottom") == false then
  92.       skeleClick(false)
  93.       zombClick(false)
  94.       button["Skeleton"]["active"] = false
  95.       button["Zombie"]["active"] = false
  96.     end
  97.    elseif e == "monitor_touch" then
  98.     checkxy(x,y)
  99.    else
  100.     sleep(0.9)
  101.    end
  102.    sleep(0.1)
  103. end
Advertisement
Add Comment
Please, Sign In to add comment