Advertisement
ccgrffdy

df

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