Advertisement
Darking560

SpawnerSelecter

Dec 8th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. --Requires advanced monitors and computers!!!
  2.  
  3. local rsSide = "back"
  4. local monitorSide = "top"
  5.  
  6. function toggle(n)
  7.   if not n then
  8.     return
  9.   end
  10.   button[n].state = true
  11. end
  12.  
  13. function sayState(n)
  14.   if not n then
  15.     return
  16.   end
  17.   x = button[n].x - 1
  18.   y = button[n].y
  19.   term.setCursorPos(x,y)
  20.   if button[n].active == true then
  21.   if button[n].state == true then
  22.     term.setTextColor(colors.lime)
  23.     write("on ")
  24.     term.setTextColor(colors.white)
  25.   else
  26.     term.setTextColor(colors.red)
  27.     write("off")
  28.     term.setTextColor(colors.white)
  29.   end
  30.   else
  31.     term.setTextColor(colors.gray)
  32.     write("---")
  33.     term.setTextColor(colors.white)
  34.   end
  35. end
  36.  
  37. function getButton(xPos,yPos)
  38.   for i=1,12 do
  39.     bxPos = button[i].x
  40.     byPos = button[i].y
  41.     xMax = bxPos + 2
  42.     xMin = bxPos - 2
  43.     yMax = byPos + 1
  44.     yMin = byPos - 1
  45.     if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
  46.       return i
  47.     end
  48.   end
  49. end
  50.  
  51. function mPrint(w)
  52.   write(w)
  53.   x,y=term.getCursorPos()
  54.   term.setCursorPos(1, y+1)
  55. end
  56.  
  57. function stateWriter()
  58.   mPrint("  _____     _____     _____     _____")
  59.   write("  ")
  60.   for i = 1,4 do
  61.     write("|")
  62.     term.setTextColor(colors.red)
  63.     write("off")
  64.     term.setTextColor(colors.white)
  65.     if i<4 then
  66.       write("|     ")
  67.     else
  68.       mPrint("|")
  69.     end
  70.   end
  71.   mPrint("  ~~~~~     ~~~~~     ~~~~~     ~~~~~")
  72. end
  73.  
  74. function mobTypeWrite(_line,_time)
  75.   term.setCursorPos(1,_line)
  76.   write("  ")
  77.   local additive = (_time - 1) * 4
  78.   local currentx = 3
  79.   for i = 1,4 do
  80.     local buttonNumber = additive + i
  81.     write(button[buttonNumber].mob)
  82.     if i == 4 then
  83.      
  84.     else
  85.       currentx = currentx + 10
  86.       term.setCursorPos(currentx,_line)
  87.     end
  88.   end
  89.   term.setCursorPos(1, _line + 1)
  90. end
  91.    
  92.  
  93. function startText()
  94.   term.setCursorPos(1,1)
  95.   mPrint("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
  96.   mPrint(" Welcome to spawn select! Control mob")
  97.   mPrint(" spawn choice by right click on screen")
  98.   mPrint(" ")
  99.   mobTypeWrite(5,1)
  100.   stateWriter()
  101.   mPrint(" ")
  102.   mobTypeWrite(10,2)
  103.   stateWriter()
  104.   mPrint(" ")
  105.   mobTypeWrite(15,3)
  106.   stateWriter()
  107.   mPrint("_______________________________________")
  108. end
  109.  
  110. function refresh(button)
  111.   modem.transmit(301,300,button)
  112. end
  113.  
  114. display = peripheral.wrap(monitorSide)
  115. modem = peripheral.wrap(rsSide)
  116. term.redirect(display)
  117. term.clear()
  118. term.setCursorPos(1,1)
  119.  
  120. --This is the table that controls everything. Don't touch unless you know what you are doing.
  121.  
  122. button = {
  123.   [1] = {x = 5; y = 7; state = false; active = false; mob = "Skele"},
  124.   [2] = {x = 15; y = 7; state = false; active = false; mob = "Wither"},
  125.   [3] = {x = 25; y = 7; state = false; active = false; mob = "Ender"},
  126.   [4] = {x = 35; y = 7; state = false; active = true; mob = "Zombie"},
  127.  
  128.   [5] = {x = 5; y = 12; state = false; active = true; mob = "Spider"},
  129.   [6] = {x = 15; y = 12; state = false; active = true; mob = "Witch"},
  130.   [7] = {x = 25; y = 12; state = false; active = false; mob = "Pigman"},
  131.   [8] = {x = 35; y = 12; state = false; active = false; mob = "Cow"},
  132.  
  133.   [9] = {x = 5; y = 17; state = false; active = true; mob = "Blaze"},
  134.   [10] = {x = 15; y = 17; state = false; active = false; mob = "Slime"},
  135.   [11] = {x = 25; y = 17; state = false; active = false; mob = "Creep"},
  136.   [12] = {x = 35; y = 17; state = false; active = true; mob = "All"}
  137.  
  138. }
  139.  
  140. local resume = true
  141. startText()
  142. for i = 1,12 do
  143.   sayState(i)
  144. end
  145.  
  146. while resume == true do
  147.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  148.   local selectedButton = getButton(xPos,yPos)
  149.   if button[selectedButton].active == true then
  150.   for i=1,11 do
  151.      button[i].state = false
  152.   end
  153.  
  154.    if selectedButton == 12 then
  155.       for i=1,11 do
  156.         button[i].state = false
  157.       end
  158.    else  
  159.       toggle(selectedButton)
  160.    end
  161.   for i=1,12 do
  162.     sayState(i)
  163.   end
  164.   refresh(selectedButton)
  165.   end
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement