Advertisement
jamawie

Wither-Spawner

Mar 13th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. local mon = peripheral.wrap("back")
  2. rednet.open("right")
  3. local x,y = mon.getSize()
  4.  
  5. auto = false
  6.  
  7. function gui()
  8.     mon.setTextColor(colors.white)
  9.     mon.setBackgroundColor(colors.gray)
  10.    
  11.     for i=1,y do
  12.         mon.setCursorPos(1,y)
  13.         for j=1,x do
  14.             mon.write(" ")
  15.         end
  16.     end
  17.    
  18.     mon.setCursorPos(1,1)
  19.     mon.setBackgroundColor(colors.lightGray)
  20.     for i=0,x do
  21.         mon.write(" ")
  22.     end
  23.     mon.setCursorPos(math.floor(x/2)-6,1)
  24.     mon.setTextColor(colors.orange)
  25.     mon.setTextColor(colors.gray)
  26.     mon.write("Wither-Spawner")
  27.    
  28.     bdraw(5,3,x-5,y-7,"Start",colors.lime)
  29.     if auto==true then color=colors.green else color=colors.red end
  30.     bdraw(x-6,y-2,x,y,"AUTO",color)
  31.    
  32.     mon.setBackgroundColor(colors.gray)
  33. end
  34.  
  35. function eventlistener()
  36.     event,side,xPos,yPos = os.pullEvent("monitor_touch")
  37.    
  38.     if button(5,3,x-5,y-7) then
  39.         start()
  40.         auto = false
  41.     end
  42.    
  43.     if button(x-6,y-2,x,y) then
  44.         if auto then
  45.             auto = false
  46.         else
  47.             auto = true
  48.         end
  49.     end
  50.    
  51.     if auto==true then color=colors.green else color=colors.red end
  52.     bdraw(x-6,y-2,x,y,"AUTO",color)
  53. end
  54.  
  55. function start()
  56.     rednet.send(55, "bau")
  57.     rednet.send(58, "bau")
  58.     rednet.send(60, "bau")
  59.     rednet.send(61, "bau")
  60.     sleep(1)
  61.     rednet.send(59, "bau")
  62.     sleep(1)
  63.     rednet.send(57, "bau")
  64.     sleep(1)
  65.     rednet.send(56, "bau")
  66. end
  67.  
  68.  
  69. function button(x1,y1,x2,y2)
  70.  if xPos<=x2 and xPos>=x1 and yPos<=y2 and yPos>=y1 then
  71.  print("button pressed")
  72.  return true
  73.  else
  74.  print("button not pressed")
  75.  return false
  76.  end
  77. end
  78.  
  79. function bdraw(xp1,yp1,xp2,yp2,txt,col)
  80.  if col==nil then
  81.  mon.setBackgroundColor(colors.lime)
  82.  else
  83.  mon.setBackgroundColor(col)
  84.  end
  85.  mon.setCursorPos(xp1,yp1)
  86.  for i=1,(xp2-xp1) do
  87.   mon.write("-")
  88.  end
  89.  mon.setCursorPos(xp1,yp2)
  90.  for i=1,(xp2-xp1) do
  91.   mon.write("-")
  92.  end
  93.  for i=yp1,yp2 do
  94.   mon.setCursorPos(xp1,i)
  95.   mon.write("|")
  96.   mon.setCursorPos(xp2,i)
  97.   mon.write("|")
  98.  end
  99.  for i=(yp1+1),(yp2-1) do
  100.   mon.setCursorPos((xp1+1),i)
  101.   for j=(xp1+1),(xp2-1) do
  102.    mon.write(" ")
  103.    j = j+1
  104.   end
  105.   i = i+1
  106.  end
  107.  if math.floor(((xp2-xp1)-#txt)/2)==0 then
  108.   xp1 = xp1+1
  109.  end
  110.  mon.setCursorPos(math.floor(((xp2-xp1)-#txt)/2)+xp1,math.floor((yp2-yp1)/2)+yp1)
  111.  print(math.floor(((xp2-xp1)-#txt)/2))
  112.  mon.write(txt)
  113. end
  114.  
  115. function drawText(x,y,txt,tcol,bcol)
  116.     mon.setCursorPos(x,y)
  117.     mon.setTextColor(tcol)
  118.     mon.setBackgroundColor(bcol)
  119.     mon.write(txt)
  120. end
  121.  
  122.  
  123. function main()
  124.     mon.clear()
  125.     gui()
  126.    
  127.     eventlistener()
  128. end
  129.  
  130. function autoS()
  131.     for i=1,5 do
  132.         if auto==true then
  133.             bdraw(5,3,x-5,y-7,"Start",colors.red)
  134.             if auto==true then start() end
  135.             for j=1,60 do
  136.                 if j>51 then
  137.                     drawText(x-6,y-3,"in " .. "0" .. 61-j .. " s",colors.red,colors.gray)
  138.                 else
  139.                     drawText(x-6,y-3,"in " .. 61-j .. " s",colors.red,colors.gray)
  140.                 end
  141.                 sleep(1)
  142.             end
  143.         end
  144.     end
  145.    
  146.     gui()
  147. end
  148.  
  149.  
  150. parallel.waitForAll(main(), autoS())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement