Advertisement
appollon41

Spawners Manager v2

Feb 19th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. mon = peripheral.wrap("top")
  3. mon.setBackgroundColor(colors.lightGray)
  4. mon.clear()
  5. mon.setTextScale(2)
  6. x,y = mon.getSize()
  7.  
  8. spawners_on = {}
  9.  
  10. --Fonctions
  11.  
  12. function create_button(xmin, xmax, ymin, ymax, color, text, tcolor)
  13.  
  14. local aire = 0
  15. local xtemp, ytemp = xmin, ymin
  16.  
  17. while aire < (((xmax-xmin)+1)*((ymax-ymin)+1)) do
  18. mon.setBackgroundColor(color)
  19. mon.setCursorPos(xtemp,ytemp)
  20. mon.write(" ")
  21.  
  22. if xtemp == xmax then
  23. xtemp = xmin
  24. ytemp = ytemp + 1
  25. else
  26. xtemp = xtemp + 1
  27. end
  28. aire = aire + 1
  29. end
  30.  
  31. mon.setTextColor(tcolor)
  32. mon.setCursorPos((xmin+xmax)/2 - (string.len(text)/2) + 1, (ymax+ymin)/2)
  33. mon.write(text)
  34. mon.setBackgroundColor(colors.blue)
  35.  
  36. end
  37.  
  38. function setup()
  39. --boutons
  40. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Witch", colors.black)
  41. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Golem", colors.black)
  42. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Wither", colors.black)
  43. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Blaze", colors.black)
  44.  
  45. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Squid", colors.black)
  46. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Pigman", colors.black)
  47. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Enderman", colors.black)
  48. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Spider", colors.black)
  49.  
  50. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Sheep", colors.black)
  51. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Blizz", colors.black)
  52. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Creeper", colors.black)
  53. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Test", colors.black)
  54.  
  55. end
  56.  
  57. function check_tab(tab,color)
  58. if tab[1] ~= nil then
  59. for i,v in ipairs(tab) do
  60. if v == color then
  61. table.remove(tab,i)
  62. return true
  63. end
  64. end
  65. return false
  66. else
  67. return false
  68. end
  69. end
  70.  
  71. function add_spawner(channelcolor)
  72. if table.getn(spawners_on) <3 then
  73. table.insert(spawners_on,1,channelcolor)
  74.  
  75. else table.insert(spawners_on, 1,channelcolor)
  76. --check_tab(spawners_on,spawners_on[4])
  77. table.remove(spawners_on)
  78. end
  79. end
  80.  
  81. function detection()
  82. local tevent, cote, xn, yn = os.pullEvent("monitor_touch")
  83.  
  84. if yn >= math.floor(0.2*y) and yn<=math.floor(0.3*y) then
  85.  
  86. if xn >= math.floor(0.08*x) and xn<= math.floor(0.25*x) then
  87. if check_tab(spawners_on,colors.orange) == false then
  88. add_spawner(colors.orange)
  89. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.2*y), math.floor(0.3*y), colors.lime, "Witch", colors.black)
  90. else
  91. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Witch", colors.black)
  92. end
  93.  
  94. elseif xn>= math.floor(0.32*x) and xn<= math.floor(0.48*x) then
  95. if check_tab(spawners_on,colors.yellow) == false then
  96. add_spawner(colors.yellow)
  97. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.2*y), math.floor(0.3*y), colors.lime, "Golem", colors.black)
  98. else
  99. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Golem", colors.black)
  100. end
  101.  
  102. elseif xn>= math.floor(0.55*x) and xn<= math.floor(0.73*x) then
  103. if check_tab(spawners_on,colors.red) == false then
  104. add_spawner(colors.red)
  105. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.2*y), math.floor(0.3*y), colors.lime, "Wither", colors.black)
  106. else
  107. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Wither", colors.black)
  108. end
  109.  
  110. elseif xn>= math.floor(0.8*x)and xn<= math.floor(0.99*x) then
  111. if check_tab(spawners_on,colors.magenta) == false then
  112. add_spawner(colors.magenta)
  113. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.2*y), math.floor(0.3*y), colors.lime, "Blaze", colors.black)
  114. else
  115. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.2*y), math.floor(0.3*y), colors.gray, "Blaze", colors.black)
  116. end
  117.  
  118. end
  119.  
  120. elseif yn>= math.floor(0.52*y) and yn<=math.floor(0.6*y) then
  121. if xn >= math.floor(0.08*x) and xn<= math.floor(0.25*x) then
  122. if check_tab(spawners_on,colors.purple) == false then
  123. add_spawner(colors.purple)
  124. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.52*y), math.floor(0.6*y), colors.lime, "Squid", colors.black)
  125. else
  126. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Squid", colors.black)
  127. end
  128.  
  129. elseif xn>= math.floor(0.32*x) and xn<= math.floor(0.48*x) then
  130. if check_tab(spawners_on,colors.pink) == false then
  131. add_spawner(colors.pink)
  132. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.52*y), math.floor(0.6*y), colors.lime, "Pigman", colors.black)
  133. else
  134. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Pigman", colors.black)
  135. end
  136.  
  137. elseif xn>= math.floor(0.55*x) and xn<= math.floor(0.73*x) then
  138. if check_tab(spawners_on,colors.gray) == false then
  139. add_spawner(colors.gray)
  140. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.52*y), math.floor(0.6*y), colors.lime, "Enderman", colors.black)
  141. else
  142. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Enderman", colors.black)
  143. end
  144.  
  145. elseif xn>= math.floor(0.8*x)and xn<= math.floor(0.99*x) then
  146. if check_tab(spawners_on,colors.lightGray) == false then
  147. add_spawner(colors.lightGray)
  148. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.52*y), math.floor(0.6*y), colors.lime, "Spider", colors.black)
  149. else
  150. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.52*y), math.floor(0.6*y), colors.gray, "Spider", colors.black)
  151. end
  152. end
  153. elseif yn>= math.floor(0.8*y) and yn<= math.floor(0.9*y) then
  154. if xn >= math.floor(0.08*x) and xn<= math.floor(0.25*x) then
  155. if check_tab(spawners_on,colors.black) == false then
  156. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.8*y), math.floor(0.9*y), colors.lime, "Sheep", colors.black)
  157. add_spawner(colors.black)
  158. else
  159. create_button(math.floor(0.08*x),math.floor(0.25*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Sheep", colors.black)
  160. end
  161. elseif xn>= math.floor(0.32*x) and xn<= math.floor(0.48*x) then
  162. if check_tab(spawners_on,colors.green) == false then
  163. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.8*y), math.floor(0.9*y), colors.lime, "Blizz", colors.black)
  164. add_spawner(colors.green)
  165. else
  166. create_button(math.floor(0.32*x),math.floor(0.48*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Blizz", colors.black)
  167. end
  168.  
  169. elseif xn>= math.floor(0.55*x) and xn<= math.floor(0.73*x) then
  170. if check_tab(spawners_on,colors.lime) == false then
  171. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.8*y), math.floor(0.9*y), colors.lime, "Creeper", colors.black)
  172. add_spawner(colors.lime)
  173. else
  174. create_button(math.floor(0.55*x),math.floor(0.73*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Creeper", colors.black)
  175. end
  176.  
  177. elseif xn>= math.floor(0.8*x)and xn<= math.floor(0.99*x) then
  178. if check_tab(spawners_on,colors.cyan) == false then
  179. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.8*y), math.floor(0.9*y), colors.lime, "Test", colors.black)
  180. add_spawner(colors.cyan)
  181. else
  182. create_button(math.floor(0.8*x),math.floor(0.99*x),math.floor(0.8*y), math.floor(0.9*y), colors.gray, "Test", colors.black)
  183. end
  184. end
  185. else
  186. return false
  187. end
  188. end
  189.  
  190. function update(tab)
  191. tampon = 0
  192. if tab.getn ~= 0 then
  193. for i,v in ipairs(tab) do
  194. tampon = tampon + v
  195. end
  196. rs.setBundledOutput("bottom", tampon)
  197. end
  198. end
  199. --Main
  200.  
  201. setup()
  202. while true do
  203. if rs.getAnalogInput("right") == 15 then
  204. detection()
  205. update(spawners_on)
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. os.sleep(0.1)
  214. else
  215. term.setCursorPos(1,1)
  216. print("Joueur absent, spawners eteints.")
  217. rs.setBundledOutput("bottom",0)
  218. os.sleep(60)
  219. term.setCursorPos(1,1)
  220. term.clear()
  221. end
  222. os.sleep(1)
  223. end
  224.  
  225. --OpenSource, utilisez le comme vous le voulez chez vous.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement