Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. local tChoices = {}
  2. tChoices[0] = 'Squelette'
  3. tChoices[1] = 'Golem de fer'
  4. tChoices[2] = 'Blaze'
  5. tChoices[3] = 'Spider'
  6. tChoices[4] = 'Pigmen'
  7. tChoices[5] = 'Enderman'
  8. tChoices[6] = 'Zombie'
  9. tChoices[7] = 'Mouton'
  10.  
  11.  
  12. table.insert(tChoices, 'Shutdown')
  13. local nTermX, nTermY = term.getSize()
  14. local sSeperator = ("-"):rep(nTermX)
  15.  
  16. local tActions = {}
  17.  
  18.  
  19.  
  20. tActions[0] = function()
  21. term.clear()
  22. term.setCursorPos(1, 1)
  23. print(sSeperator)
  24. print("| Terminal Password |")
  25. print(sSeperator)
  26. print("Attention")
  27. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  28. write(" [appuyez sur entrer]")
  29. read()
  30. end
  31.  
  32. tActions[1] = function()
  33. term.clear()
  34. term.setCursorPos(1, 1)
  35. print(sSeperator)
  36. print("| Terminal Password |")
  37. print(sSeperator)
  38. print("Attention")
  39. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  40. write(" [appuyez sur entrer]")
  41. read()
  42. end
  43.  
  44. tActions[2] = function()
  45. term.clear()
  46. term.setCursorPos(1, 1)
  47. print(sSeperator)
  48. print("| Terminal Password |")
  49. print(sSeperator)
  50. print("Attention")
  51. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  52. write(" [appuyez sur entrer]")
  53. read()
  54. end
  55.  
  56. tActions[3] = function()
  57. term.clear()
  58. term.setCursorPos(1, 1)
  59. print(sSeperator)
  60. print("| Terminal Password |")
  61. print(sSeperator)
  62. print("Attention")
  63. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  64. write(" [appuyez sur entrer]")
  65. read()
  66.  
  67. end
  68.  
  69. tActions[4] = function()
  70. term.clear()
  71. term.setCursorPos(1, 1)
  72. print(sSeperator)
  73. print("| Terminal Password |")
  74. print(sSeperator)
  75. print("Attention")
  76. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  77. write(" [appuyez sur entrer]")
  78. read()
  79.  
  80. end
  81.  
  82. tActions[5] = function()
  83. term.clear()
  84. term.setCursorPos(1, 1)
  85. print(sSeperator)
  86. print("| Terminal Password |")
  87. print(sSeperator)
  88. print("Attention")
  89. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  90. write(" [appuyez sur entrer]")
  91. read()
  92.  
  93. end
  94.  
  95. tActions[6] = function()
  96. term.clear()
  97. term.setCursorPos(1, 1)
  98. print(sSeperator)
  99. print("| Terminal Password |")
  100. print(sSeperator)
  101. print("Attention")
  102. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  103. write(" [appuyez sur entrer]")
  104. read()
  105.  
  106. end
  107.  
  108. tActions[7] = function()
  109. term.clear()
  110. term.setCursorPos(1, 1)
  111. print(sSeperator)
  112. print("| Terminal Password |")
  113. print(sSeperator)
  114. print("Attention")
  115. term.setCursorPos(1, nTermY) -- Move the cursor to the bottom
  116. write(" [appuyez sur entrer]")
  117. read()
  118.  
  119. end
  120.  
  121. table.insert(tActions, os.shutdown) -- Insert the shutdown function at the end to compliment the "Shutdown" menu item :)
  122.  
  123. -- Do the above for the remaining
  124.  
  125. local nSelection = 0 -- The current selection defaults at 0
  126. repeat
  127. term.setCursorPos(1, 1)
  128. term.clear()
  129. print(sSeperator)
  130. print("| FantomQc pour vous servir! |")
  131. print(sSeperator)
  132.  
  133. for nLine = 0, #tChoices do -- Iterate through the possible potions, and print them, marking the chosen one
  134. local sLine = " "
  135. if nSelection == nLine then
  136. sLine = ">"
  137. end
  138. local sLineNum = tostring(nLine)
  139. if #sLineNum < 2 then
  140. sLineNum = "0" .. sLineNum -- Prepend a 0 if it's too short
  141. end
  142. sLine = sLine .. "[" .. sLineNum .. "]" .. " " .. tChoices[nLine] -- Construct the string we're printing
  143. print(sLine) -- Print it
  144. end
  145. -- os.pullEvent keys: up - 200, down - 208, enter - 28
  146. local sEvent, nKey = os.pullEvent("key") -- Using the 1.3 filtering; this will mean only "key" events will pass
  147.  
  148. if nKey == 200 or nKey == 17 then -- Up/w key: move up the menu
  149. if tChoices[nSelection - 1] then -- Check if we can move up
  150. nSelection = nSelection - 1
  151. end
  152. -- Ignore it otherwise
  153. elseif nKey == 208 or nKey == 31 then -- Down/s key: move down the menu
  154. if tChoices[nSelection + 1] then -- Check if we can move down
  155. nSelection = nSelection + 1
  156. end
  157. elseif nKey == 28 then -- Enter key: Selecting a choice
  158. if tActions[nSelection] then
  159. tActions[nSelection]() -- Run the function associated with the action.
  160. else
  161. print("Error: Selection out of bounds: ", nSelection)
  162. read() -- This error is recoverable.
  163. end
  164. end
  165. until false -- Run this loop forever :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement