Advertisement
jamawie

Turtle portal

Jul 30th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --Portal turtle
  2.  
  3. mon = peripheral.wrap("right")
  4.  
  5. bnames = {"Computer","Mobfarm","Farm","","","","","","","","","","","","",""}
  6.  
  7. function bdraw(num, str, ison)
  8.     if num > 0 and num < 5 then
  9.         yP = 4
  10.         xp = 12*(num-0)-10
  11.     elseif num > 4 and num < 9 then
  12.         yP = 8
  13.         xp = 12*(num-4)-10
  14.     elseif num > 8 and num < 13 then
  15.         yP = 12
  16.         xp = 12*(num-8)-10
  17.     elseif num > 12 and num < 17 then
  18.         yP = 16
  19.         xp = 12*(num-12)-10
  20.     else
  21.         return
  22.     end
  23.  
  24.     mon.setCursorPos(xp, yP)
  25.     if ison then
  26.         mon.setBackgroundColor(colors.lime)
  27.     else
  28.         mon.setBackgroundColor(colors.red)
  29.     end
  30.  
  31.     for i=1,10 do
  32.         mon.write(" ")
  33.     end
  34.  
  35.     mon.setCursorPos(xp+((10-#str)/2),yP)
  36.     mon.write(str)
  37. end
  38.  
  39. function execute(nmb)
  40.     bdraw(nmb,bnames[nmb],true)
  41.     sleep(1)
  42.     turtle.select(nmb)
  43.     turtle.drop()
  44.     sleep(.5)
  45.     rs.setOutput("back",true)
  46.     sleep(3)
  47.     rs.setOutput("back",false)
  48.     sleep(.5)
  49.     turtle.suck()
  50. end
  51.  
  52. function checkButtons(xPos, yPos)
  53.     if yPos == 4 then
  54.         for num=1,4 do
  55.             if xPos >= (12*(num-0)-10) and xPos <= (12*(num-0)) then
  56.                 execute(num)
  57.             end
  58.         end
  59.     elseif yPos == 8 then
  60.         for num=5,8 do
  61.             if xPos >= (12*(num-4)-10) and xPos <= (12*(num-4)) then
  62.                 execute(num)
  63.             end
  64.         end
  65.     elseif yPos == 12 then
  66.         for num=9,12 do
  67.             if xPos >= (12*(num-8)-10) and xPos <= (12*(num-8)) then
  68.                 execute(num)
  69.             end
  70.         end
  71.     elseif yPos == 16 then
  72.         for num=13,16 do
  73.             if xPos >= (12*(num-12)-10) and xPos <= (12*(num-12)) then
  74.                 execute(num)
  75.             end
  76.         end
  77.     end
  78. end
  79.  
  80. function logo()
  81.     mon.setTextColor(colors.cyan)
  82.     mon.setBackgroundColor(colors.gray)
  83.     mon.setCursorPos((x-16)/2,1)
  84.     mon.write("Jo")
  85.     mon.setTextColor(colors.orange)
  86.     mon.write("Ja")
  87.     mon.setTextColor(colors.lightGray)
  88.     mon.write(" Productions")
  89. end
  90.  
  91. function gui()
  92.     x,y = mon.getSize()
  93.     mon.setTextColor(colors.black)
  94.     mon.setBackgroundColor(colors.white)
  95.     for i=1,y do
  96.         mon.setCursorPos(1,i)
  97.         for j=1,x do
  98.             mon.write(" ")
  99.         end
  100.     end
  101.     logo()
  102.     for i=1,16 do
  103.         bdraw(i,bnames[i],false)
  104.     end
  105. end
  106.  
  107. function gesperrt()
  108.     mon.setBackgroundColor(colors.red)
  109.     mon.setTextColor(colors.gray)
  110.     for i=4,y-4 do
  111.         mon.setCursorPos(1,i)
  112.         for j=1,x do
  113.             mon.write(" ")
  114.         end
  115.     end
  116.     mon.setCursorPos((x-8)/2,y/2)
  117.     mon.write("gesperrt")
  118. end
  119.  
  120. while true do
  121.   gui()
  122.   event,_,xPos,yPos = os.pullEvent()
  123.   if event=="monitor_touch" then
  124.     checkButtons(xPos,yPos)
  125.   elseif event=="redstone" then
  126.     if rs.getInput("top") then
  127.         gesperrt()
  128.     end
  129.   end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement