Guest User

test

a guest
Nov 17th, 2019
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("right")
  2. redstone.setOutput("left",false)
  3. modem = peripheral.wrap("right")
  4. modem.open(61)
  5. mon = peripheral.wrap("monitor_8")
  6.  
  7. red = colors.red
  8. yellow = colors.yellow
  9. green = colors.green
  10. black = colors.black
  11. white = colors.white
  12. orange = colors.orange
  13.  
  14. term.redirect(mon)
  15. term.setBackgroundColor(black)
  16. term.clear()
  17. term.setCursorPos(1,1)
  18. mon9 = peripheral.wrap("monitor_9")
  19. acess = false
  20. sto = fs.open("DEFCON", "r")
  21.  
  22. DEFCON = tonumber(sto.readLine())
  23. sto.close()
  24.  
  25.  
  26. function createBox (name, xmin, xmax, ymin, ymax, text, color)
  27. currentY = ymin
  28. while currentY ~= ymax do
  29. term.setCursorPos(xmin, currentY)
  30. for i = 1, xmax do
  31. write(" ")
  32. end
  33. currentY = currentY + 1
  34. end
  35. end
  36.  
  37. function createButton (ymin, ymax, xmin, xmax, text, color)
  38. term.setBackgroundColor(color)
  39. xLoc = xmin + (math.ceil((xmax - string.len(text))/2))
  40. yLoc = math.ceil((ymax + ymin)/2)-1
  41. createBox(name, xmin, xmax, ymin, ymax, text, color)
  42. term.setCursorPos(xLoc,yLoc)
  43. write(text)
  44. end
  45.  
  46.  
  47.  
  48. function digi()
  49. mon9.setBackgroundColor(black)
  50. mon9.clear()
  51. mon9.setBackgroundColor(orange)
  52. mon9.setCursorPos(2,3)
  53. mon9.write("open")
  54. term.setBackgroundColor(black)
  55. term.clear()
  56.  
  57. x1 = 4
  58. x2 = 9
  59. x3 = 14
  60. t1 = 3
  61. y1 = 2
  62. y2 = 5
  63. y3 = 8
  64. yx1 = y1+2
  65. yx2 = y2+2
  66. yx3 = y3+2
  67. createButton(y1,yx1 , x1, t1, "1", orange)
  68. createButton(y1,yx1, x2, t1, "2", orange )
  69. createButton(y1, yx1, x3, t1, "3", orange)
  70. createButton(y2, yx2, x1, t1, "4", orange)
  71. createButton(y2, yx2, x2, t1, "5", orange)
  72. createButton(y2, yx2, x3, t1, "6", orange)
  73. createButton(y3, yx3, x1, t1, "7", orange)
  74. createButton(y3, yx3, x2, t1, "8", orange)
  75. createButton(y3, yx3, x3, t1, "9", orange)
  76. createButton(11, 13, 8, 5, "0", orange)
  77. end
  78.  
  79.  
  80. function click()
  81. event, side, m, d,k = os.pullEvent()
  82. term.setCursorPos(1,1)
  83. print(event)
  84. print(side)
  85. print(m)
  86. print(d)
  87. print(k)
  88. if event == "monitor_touch" then
  89. if side == "monitor_8" then
  90. data = compare(m,d)
  91. return (data)
  92. elseif side == "monitor_9"  then
  93. redstone.setOutput("left",true)
  94. sleep(10)
  95. redstone.setOutput("left",false)
  96. end
  97. elseif event == "modem_message" then
  98. if m == 61 then
  99. if d == 62 then
  100. etat_porte = k
  101. elseif d == 63 then
  102. etat_lux = k
  103. elseif d == 64 then
  104. etat_energy = k
  105. elseif d == 65 then
  106. etat_securite = k
  107. elseif d == 66 then
  108. DEFCON = k
  109. h = fs.open("DEFCON", "w")
  110.  h.write(DEFCON)
  111.  h.close()
  112.  
  113. elseif d == 67 then
  114. --cube2Max = k
  115. elseif d == 68 then
  116. --mfeMax = k
  117. elseif d == 69 then
  118. --mfe2Max = k
  119. end
  120.  
  121. end
  122. end
  123.  
  124. end
  125.  
  126. function compare(x,y)
  127.  
  128. x1 = 4
  129. x2 = 9
  130. x3 = 14
  131. t1 = 3
  132. y1 = 2
  133. y2 = 5
  134. y3 = 8
  135. yx1 = y1+2
  136. yx2 = y2+2
  137. yx3 = y3+2
  138.  
  139. data = 0
  140. if x < 7 and x > 3 and y < 4 and y > 1 then
  141. data = 1
  142. createButton(y1,yx1 , x1, t1, "1", red)
  143. elseif x < 12 and x > 8 and y < 4 and y > 1 then
  144. data = 2
  145. createButton(y1,yx1, x2, t1, "2", red)
  146. elseif x < 17 and x > 13 and y < 4 and y > 1 then
  147. data = 3
  148. createButton(y1, yx1, x3, t1, "3", red)
  149. elseif x < 7 and x > 3 and y < 7 and y > 4 then
  150. data = 4
  151. createButton(y2, yx2, x1, t1, "4", red)
  152. elseif x < 12 and x > 8 and y < 7 and y > 4 then
  153. data = 5
  154. createButton(y2, yx2, x2, t1, "5", red)
  155. elseif x < 17 and x > 13 and y < 7 and y > 4 then
  156. data = 6
  157. createButton(y2, yx2, x3, t1, "6", red)
  158. elseif x < 7 and x > 3 and y < 10 and y > 7 then
  159. data = 7
  160. createButton(y3, yx3, x1, t1, "7", red)
  161. elseif x < 12 and x > 8 and y < 10 and y > 7 then
  162. data = 8
  163. createButton(y3, yx3, x2, t1, "8", red)
  164. elseif x < 17 and x > 13 and y < 10 and y > 7 then
  165. data = 9
  166. createButton(y3, yx3, x3, t1, "9", red)
  167. elseif x < 13 and x > 7 and y < 13 and y > 10 then
  168. data = 0
  169. createButton(11, 13, 8, 5, "0", red)
  170. else
  171. data = nil
  172. end
  173. if data ~= nil then
  174. sleep(1)
  175. return (data)
  176. end
  177. end
  178.  
  179. while (true) do
  180. if acess == true then
  181. --id,msg,dis = rednet.receive()
  182. redstone.setOutput("left", false)
  183. acess = false
  184. end
  185. digi()
  186. acess = false
  187. data1, data2, data3, data4 = nil
  188. while (acess == false) do
  189. digi()
  190. data = click()
  191. if data1 == nil then
  192. data1 = data
  193. elseif data2 == nil then
  194. data2 = data
  195. elseif data3 == nil then
  196. data3 = data
  197. elseif data4 == nil then
  198. data4 = data
  199. else
  200. data1 = data2
  201. data2 = data3
  202. data3 = data4
  203. data4 = data
  204. end
  205. if data1 == 2 and data2 == 0 and data3 == 1 and data4 == 2 and DEFCON >= 1 then
  206. acess = true
  207. elseif data1 == 1 and data2 == 4 and data3 == 1 and data4 == 8 and DEFCON >= 2 then
  208. acess = true
  209. elseif data1 == 3 and data2 == 9 and data3 == 4 and data4 == 5 and DEFCON >= 3 then
  210. acess = true
  211. elseif DEFCON == 4 then
  212. acess = true
  213. end
  214. end
  215. term.setBackgroundColor(black)
  216. term.clear()
  217. term.setCursorPos(1,1)
  218.  
  219. if acess == true then
  220. resultat = "bienvenue ! ^^"
  221. modem.transmit(56,56,"ouverture")
  222. redstone.setOutput("left",true)
  223. --rednet.send (56,msg)
  224. createButton(4, 7, 3, 15, resultat, red)
  225. sleep(10)
  226. term.clear()
  227. end
  228. end
RAW Paste Data