--Requires advanced monitors and computers!!!


SUBMITTED BY: Guest

DATE: Nov. 19, 2013, 3:17 a.m.

FORMAT: Text only

SIZE: 7.4 kB

HITS: 715

  1. --Requires advanced monitors and computers!!!
  2. local rsSide = "back"
  3. local monitorSide = "right"
  4. function testForMonitor(_side)
  5. if peripheral.getType(_side) then
  6. if peripheral.getType(_side) == "monitor" then
  7. return true
  8. else return false end
  9. else return false end
  10. end
  11. Args = { ... }
  12. if #Args < 1 then
  13. print("Usage: "..fs.getName(shell.getRunningProgram()).." <monitor side> [cable side]")
  14. return
  15. elseif #Args > 1 then
  16. monitorSide = Args[1]
  17. rsSide = Args[2]
  18. if not testForMonitor(monitorSide) then
  19. print("There is no valid monitor on that side.")
  20. return
  21. end
  22. elseif #Args == 1 then
  23. monitorSide = Args[1]
  24. if not testForMonitor(monitorSide) then
  25. print("There is no valid monitor on that side.")
  26. return
  27. end
  28. else
  29. print("Error!!!")
  30. return
  31. end
  32. function toggle(n)
  33. if not n then
  34. return
  35. end
  36. local state = button[n].state
  37. if state then
  38. state = false
  39. else
  40. state = true
  41. end
  42. button[n].state = state
  43. return state
  44. end
  45. function sayState(n)
  46. if not n then
  47. return
  48. end
  49. x = button[n].x - 1
  50. y = button[n].y
  51. term.setCursorPos(x,y)
  52. if button[n].state then
  53. term.setTextColor(colors.lime)
  54. write("on ")
  55. term.setTextColor(colors.white)
  56. else
  57. term.setTextColor(colors.red)
  58. write("off")
  59. term.setTextColor(colors.white)
  60. end
  61. end
  62. function getButton(xPos,yPos)
  63. for i=1,12 do
  64. bxPos = button[i].x
  65. byPos = button[i].y
  66. xMax = bxPos + 2
  67. xMin = bxPos - 2
  68. yMax = byPos + 1
  69. yMin = byPos - 1
  70. if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
  71. return i
  72. end
  73. end
  74. end
  75. function mPrint(w)
  76. write(w)
  77. x,y=term.getCursorPos()
  78. term.setCursorPos(1, y+1)
  79. end
  80. function allTheSame()
  81. local state = button[1].state
  82. for i = 2,10 do
  83. if state == button[i].state then
  84. else return false
  85. end
  86. end
  87. return true
  88. end
  89. function stateWriter()
  90. mPrint(" _____ _____ _____ _____")
  91. write(" ")
  92. for i = 1,4 do
  93. write("|")
  94. term.setTextColor(colors.red)
  95. write("off")
  96. term.setTextColor(colors.white)
  97. if i<4 then
  98. write("| ")
  99. else
  100. mPrint("|")
  101. end
  102. end
  103. mPrint(" ~~~~~ ~~~~~ ~~~~~ ~~~~~")
  104. end
  105. function mobTypeWrite(_line,_time)
  106. term.setCursorPos(1,_line)
  107. write(" ")
  108. local additive = (_time - 1) * 4
  109. local currentx = 3
  110. for i = 1,4 do
  111. local buttonNumber = additive + i
  112. write(button[buttonNumber].mob)
  113. if i == 4 then
  114. else
  115. currentx = currentx + 10
  116. term.setCursorPos(currentx,_line)
  117. end
  118. end
  119. term.setCursorPos(1, _line + 1)
  120. end
  121. function startText()
  122. term.setCursorPos(1,1)
  123. mPrint("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
  124. mPrint(" Welcome to AI Control!")
  125. mPrint(" Right Click to Choose")
  126. mPrint(" ")
  127. mobTypeWrite(5,1)
  128. stateWriter()
  129. mPrint(" ")
  130. mobTypeWrite(10,2)
  131. stateWriter()
  132. mPrint(" ")
  133. mobTypeWrite(15,3)
  134. stateWriter()
  135. mPrint("_______________________________________")
  136. end
  137. function bundleState()
  138. running = 0
  139. for light = 1, 10 do
  140. if button[light].state == true then
  141. running = running + button[light].color
  142. end
  143. end
  144. return running
  145. end
  146. function refresh()
  147. redstone.setBundledOutput(rsSide, bundleState())
  148. end
  149. display = peripheral.wrap(monitorSide)
  150. term.redirect(display)
  151. term.clear()
  152. term.setCursorPos(1,1)
  153. --This is the table that controls everything. Don't touch unless you know what you are doing.
  154. button = {
  155. [1] = {x = 5; y = 7; state = false; color = colors.white; mob = "N/A"},
  156. [2] = {x = 15; y = 7; state = false; color = colors.orange; mob = "Maint"},
  157. [3] = {x = 25; y = 7; state = false; color = colors.magenta; mob = "Armoury"},
  158. [4] = {x = 35; y = 7; state = false; color = colors.lightBlue; mob = "Items"},
  159. [5] = {x = 5; y = 12; state = false; color = colors.yellow; mob = "Creep"},
  160. [6] = {x = 15; y = 12; state = false; color = colors.lime; mob = "Witch"},
  161. [7] = {x = 25; y = 12; state = false; color = colors.pink; mob = "Pigman"},
  162. [8] = {x = 35; y = 12; state = false; color = colors.gray; mob = "Cow"},
  163. [9] = {x = 5; y = 17; state = false; color = colors.lightGray; mob = "Blaze"},
  164. [10] = {x = 15; y = 17; state = false; color = colors.cyan; mob = "Slime"},
  165. [11] = {x = 25; y = 17; state = false; color = colors.purple; mob = "Toggle"},
  166. [12] = {x = 35; y = 17; state = false; color = colors.blue; mob = "Master"}
  167. }
  168. local resume = true
  169. startText()
  170. for i = 1,10 do
  171. sayState(i)
  172. end
  173. term.setCursorPos(button[12].x-1,button[12].y)
  174. term.setTextColor(colors.red)
  175. write("off")
  176. term.setTextColor(colors.white)
  177. term.setCursorPos(button[11].x-1,button[11].y)
  178. term.setTextColor(colors.cyan)
  179. write("TGL")
  180. term.setTextColor(colors.white)
  181. refresh()
  182. while resume == true do
  183. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  184. local selectedButton = getButton(xPos,yPos)
  185. if selectedButton == 11 then
  186. for i = 1,10 do
  187. toggle(i)
  188. end
  189. elseif selectedButton == 12 then
  190. toggle(12)
  191. for i=1,10 do
  192. button[i].state = button[12].state
  193. end
  194. sayState(12)
  195. allSame=true
  196. else
  197. term.setCursorPos(button[12].x - 1, button[12].y)
  198. term.setTextColor(colors.lightGray)
  199. write("---")
  200. term.setTextColor(colors.white)
  201. toggle(selectedButton)
  202. end
  203. for i=1,10 do
  204. sayState(i)
  205. end
  206. if allTheSame() then
  207. button[12].state = button[1].state
  208. sayState(12)
  209. else
  210. term.setCursorPos(button[12].x - 1, button[12].y)
  211. term.setTextColor(colors.lightGray)
  212. write("---")
  213. term.setTextColor(colors.white)
  214. end
  215. refresh()
  216. end
  217. -- optional, more color appropriate colors
  218. --[==[ button = {
  219. [1] = {x = 5; y = 7; state = false; color = colors.lightGray; mob = "Skele"},
  220. [2] = {x = 15; y = 7; state = false; color = colors.gray; mob = "Wither"},
  221. [3] = {x = 25; y = 7; state = false; color = colors.purple; mob = "Ender"},
  222. [4] = {x = 35; y = 7; state = false; color = colors.cyan; mob = "Zombie"},
  223. [5] = {x = 5; y = 12; state = false; color = colors.green; mob = "Creep"},
  224. [6] = {x = 15; y = 12; state = false; color = colors.magenta; mob = "Witch"},
  225. [7] = {x = 25; y = 12; state = false; color = colors.pink; mob = "Pigman"},
  226. [8] = {x = 35; y = 12; state = false; color = colors.brown; mob = "Cow"},
  227. [9] = {x = 5; y = 17; state = false; color = colors.yellow; mob = "Blaze"},
  228. [10] = {x = 15; y = 17; state = false; color = colors.lime; mob = "Slime"},
  229. [11] = {x = 25; y = 17; state = false; color = colors.purple; mob = "Toggle"},
  230. [12] = {x = 35; y = 17; state = false; color = colors.blue; mob = "Master"}
  231. } ]==]

comments powered by Disqus