Advertisement
R167

Computercraft: Spawner controller

Feb 16th, 2013
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. --Requires advanced monitors and computers!!!
  2.  
  3. function toggle(n)
  4.   if not n then
  5.     return
  6.   end
  7.   local state=lightState[n]
  8.   if state then
  9.     state = false
  10.   else
  11.     state = true
  12.   end
  13.   lightState[n] = state
  14.   return state
  15. end
  16.  
  17. function sayState(n)
  18.   if not n then
  19.     return
  20.   end
  21.   x = buttonX[n]-1
  22.   y = buttonY[n]
  23.   term.setCursorPos(x,y)
  24.   if lightState[n] then
  25.     term.setTextColor(colors.lime)
  26.     write("on ")
  27.     term.setTextColor(colors.white)
  28.   else
  29.     term.setTextColor(colors.red)
  30.     write("off")
  31.     term.setTextColor(colors.white)
  32.   end
  33. end
  34.  
  35. function getButton(xPos,yPos)
  36.   for i=1,12 do
  37.     bxPos=buttonX[i]
  38.     byPos=buttonY[i]
  39.     xMax=bxPos+2
  40.     xMin=bxPos-2
  41.     yMax=byPos+1
  42.     yMin=byPos-1
  43.     if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
  44.       return i
  45.     end
  46.   end
  47. end
  48.  
  49. function mPrint(w)
  50.   write(w)
  51.   x,y=term.getCursorPos()
  52.   term.setCursorPos(1,y+1)
  53. end
  54.  
  55. function allTheSame()
  56.   local state = lightState[1]
  57.   for i=2,10 do
  58.     if state==lightState[i] then
  59.     else return false
  60.     end
  61.   end
  62.   return true
  63. end
  64.  
  65. function stateWriter()
  66.   mPrint("  _____     _____     _____     _____")
  67.   write("  ")
  68.   for i=1,4 do
  69.     write("|")
  70.     term.setTextColor(colors.red)
  71.     write("off")
  72.     term.setTextColor(colors.white)
  73.     if i<4 then
  74.       write("|     ")
  75.     else
  76.       mPrint("|")
  77.     end
  78.   end
  79.   mPrint("  ~~~~~     ~~~~~     ~~~~~     ~~~~~")
  80. end
  81.  
  82. function startText()
  83.   term.setCursorPos(1,1)
  84.   mPrint("_______________________________________")
  85.   mPrint(" Welcome to spawn select! Control mob")
  86.   mPrint(" spawn choice by right click on screen")
  87.   mPrint(" ")
  88.   mPrint("  Skele     Wither    Ender     Zombie")
  89.   stateWriter()
  90.   mPrint(" ")
  91.   mPrint("  Creep     Witch     Pigman    Cow")
  92.   stateWriter()
  93.   mPrint(" ")
  94.   mPrint("  Blaze     Slime     Toggle    Master")
  95.   stateWriter()
  96.   mPrint("_______________________________________")
  97. end
  98.  
  99. function bundleState()
  100.  
  101. end
  102.  
  103. display = peripheral.wrap("right")
  104. term.redirect(display)
  105. term.clear()
  106. term.setCursorPos(1,1)
  107. buttonX = {
  108. 5,15,25,35,
  109. 5,15,25,35,
  110. 5,15,25,35
  111. }
  112.  
  113. buttonY = {
  114. 7,7,7,7,
  115. 12,12,12,12,
  116. 17,17,17,17
  117. }
  118.  
  119. lightState = {false,false,false,false,false,false,false,false,false,false,false,false}
  120.  
  121. spawnerColor = {
  122. colors.white, colors.orange, colors.magenta, colors.lightBlue,
  123. colors.yellow, colors.lime, colors.pink, colors.gray,
  124. colors.lightGray, colors.cyan, colors.purple, colors.blue
  125. }
  126.  
  127. local resume=true
  128. startText()
  129. for i=1,10 do
  130.   sayState(i)
  131. end
  132. term.setCursorPos(buttonX[12]-1,buttonY[12])
  133. term.setTextColor(colors.red)
  134. write("off")
  135. term.setTextColor(colors.white)
  136. term.setCursorPos(buttonX[11]-1,buttonY[11])
  137. term.setTextColor(colors.cyan)
  138. write("TGL")
  139. term.setTextColor(colors.white)
  140. while resume == true do
  141.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  142.   local button = getButton(xPos,yPos)
  143.   if button==11 then
  144.     for i=1,10 do
  145.       toggle(i)
  146.     end
  147.   elseif button==12 then
  148.     toggle(12)
  149.     for i=1,10 do
  150.       lightState[i]=lightState[12]
  151.     end
  152.     sayState(12)
  153.     allSame=true
  154.   else
  155.     term.setCursorPos(buttonX[12]-1,buttonY[12])
  156.     term.setTextColor(colors.lightGray)
  157.     write("---")
  158.     term.setTextColor(colors.white)
  159.     toggle(button)
  160.   end
  161.   for i=1,10 do
  162.     sayState(i)
  163.   end
  164.   if allTheSame() then
  165.     lightState[12]=lightState[1]
  166.     sayState(12)
  167.   else
  168.     term.setCursorPos(buttonX[12]-1,buttonY[12])
  169.     term.setTextColor(colors.lightGray)
  170.     write("---")
  171.     term.setTextColor(colors.white)
  172.   end
  173. end
  174.  
  175.  
  176. --[==[Tables are used to quite an extent throughout this program.
  177. The order of said tables is important as these must remain consistent in order for the script to execute.]==]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement