Advertisement
ccgrffdy

Untitled

Jan 27th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. rednet.open("back")
  2. local termWidth, termHeight = term.getSize()
  3. local selectedItem = 1
  4. local onMainMenu = true
  5. Serveur1 = 81
  6. SERV = 83
  7. function GSERV()
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. rednet.send(Serveur1, "DStatut")
  11. i = 1
  12. while i <= 3 do
  13. local senderId, message, protocol = rednet.receive()
  14. if message == "G" then
  15. term.setTextColor(colors.green)
  16. elseif message == "R" then
  17. term.setTextColor(colors.red)
  18. elseif message == "END" then
  19. i = 4
  20. elseif message == "W" then
  21. term.setTextColor(colors.white)
  22. else
  23. print(message)
  24. term.setTextColor(colors.white)
  25. end
  26. end
  27.  
  28. ID = read()
  29. if ID == "5" then
  30. print("Clear Glass ON / OFF ")
  31. ONF = read()
  32. if ONF == "ON" then
  33. print("ON")
  34. rednet.send(SERV, "90")
  35. elseif ONF == "OFF" then
  36. print("OFF")
  37. rednet.send(SERV, "97")
  38. end
  39. elseif ID == "2" then
  40. print("Diamand ON / OFF ")
  41. ONF = read()
  42. if ONF == "ON" then
  43. print("ON")
  44. rednet.send(SERV, "50")
  45. elseif ONF == "OFF" then
  46. print("OFF")
  47. rednet.send(SERV, "7")
  48. end
  49. elseif ID == "1" then
  50. print("Emeraude ON / OFF ")
  51. ONF = read()
  52. if ONF == "ON" then
  53. print("ON")
  54. rednet.send(SERV, "30")
  55. elseif ONF == "OFF" then
  56. print("OFF")
  57. rednet.send(SERV, "37")
  58. end
  59. elseif ID == "4" then
  60. print("Glass ON / OFF ")
  61. ONF = read()
  62. if ONF == "ON" then
  63. print("ON")
  64. rednet.send(SERV, "100")
  65. elseif ONF == "OFF" then
  66. print("OFF")
  67. rednet.send(SERV, "107")
  68. end
  69. elseif ID == "3" then
  70. print("Sable ON / OFF ")
  71. ONF = read()
  72. if ONF == "ON" then
  73. print("ON")
  74. rednet.send(SERV, "50")
  75. elseif ONF == "OFF" then
  76. print("OFF")
  77. rednet.send(SERV, "57")
  78. end
  79. elseif ID == "0" then
  80. print("Stone ON / OFF ")
  81. ONF = read()
  82. if ONF == "ON" then
  83. print("ON")
  84. rednet.send(SERV, "10")
  85. elseif ONF == "OFF" then
  86. print("OFF")
  87. rednet.send(SERV, "17")
  88. end
  89. elseif ID == "E" then
  90. print("Exit")
  91. sleep(1)
  92. elseif ID == "6" then
  93. print("Sugar canes ON / OFF ")
  94. ONF = read()
  95. if ONF == "ON" then
  96. print("ON")
  97. rednet.send(SERV, "60")
  98. elseif ONF == "OFF" then
  99. print("OFF")
  100. rednet.send(SERV, "67")
  101. end
  102. end
  103. sleep(1)
  104. end
  105. function Exit()
  106. onMainMenu = false
  107. end
  108. mainMenu = {
  109. [1] = { text = " Les Services", handler = GSERV },
  110. }
  111. function Retest()
  112. rednet.send(81, "ON")
  113. local senderId, message, protcol = rednet.receive(1)
  114. if message == "OK" then
  115. mainMenu = {
  116. [1] = { text = " Les Services", handler = GSERV },
  117. }
  118. else
  119. mainMenu = {
  120. [1] = { text = "Service non disponible", handler = Retest },
  121. }
  122. end
  123. end
  124. function printMenu( menu )
  125. for i=1,#menu do
  126. if i == selectedItem then
  127. print(">> "..menu[i].text)
  128. else
  129. print(" "..menu[i].text)
  130. end
  131. end
  132. end
  133. function onKeyPressed( key, menu )
  134. if key == keys.enter then
  135. onItemSelected(menu)
  136. elseif key == keys.up then
  137. if selectedItem > 1 then
  138. selectedItem = selectedItem - 1
  139. end
  140. elseif key == keys.down then
  141. if selectedItem < #menu then
  142. selectedItem = selectedItem + 1
  143. end
  144. end
  145. end
  146. function onItemSelected( menu )
  147. menu[selectedItem].handler()
  148. end
  149. function main()
  150. while onMainMenu do
  151. term.clear()
  152. term.setCursorPos(1,1)
  153. printMenu(mainMenu)
  154. event, key = os.pullEvent("key")
  155. onKeyPressed(key,mainMenu)
  156. end
  157. end
  158. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement