Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. local tChoices = {}
  2. tChoices[0] = 'Squelette'
  3. tChoices[0] = 'Golem de fer'
  4. tChoices[0] = 'Blaze'
  5. tChoices[0] = 'Spider'
  6. tChoices[0] = 'Pigmen'
  7. tChoices[0] = 'Enderman'
  8. tChoices[0] = 'Zombie'
  9. tChoices[0] = '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) -- envoi le curseur en haut
  28. write(" [appuyez sur entrer pour une autre selection]")
  29. read()
  30. end
  31.  
  32.  
  33. table.insert(tActions, os.shutdown) -- Insert the shutdown function at the end to compliment the "Shutdown" menu item :)
  34.  
  35. -- Do the above for the remaining
  36.  
  37. local nSelection = 0 -- The current selection defaults at 0
  38. repeat
  39. term.setCursorPos(1, 1)
  40. term.clear()
  41. print(sSeperator)
  42. print("| FantomQc pour vous servir! |")
  43. print(sSeperator)
  44.  
  45. for nLine = 0, #tChoices do -- Iterate through the possible potions, and print them, marking the chosen one
  46. local sLine = " "
  47. if nSelection == nLine then
  48. sLine = ">"
  49. end
  50. local sLineNum = tostring(nLine)
  51. if #sLineNum < 2 then
  52. sLineNum = "0" .. sLineNum -- Prepend a 0 if it's too short
  53. end
  54. sLine = sLine .. "[" .. sLineNum .. "]" .. " " .. tChoices[nLine] -- Construct the string we're printing
  55. print(sLine) -- Print it
  56. end
  57. -- os.pullEvent keys: up - 200, down - 208, enter - 28
  58. local sEvent, nKey = os.pullEvent("key") -- Using the 1.3 filtering; this will mean only "key" events will pass
  59.  
  60. if nKey == 200 or nKey == 17 then -- Up/w key: move up the menu
  61. if tChoices[nSelection - 1] then -- Check if we can move up
  62. nSelection = nSelection - 1
  63. end
  64. -- Ignore it otherwise
  65. elseif nKey == 208 or nKey == 31 then -- Down/s key: move down the menu
  66. if tChoices[nSelection + 1] then -- Check if we can move down
  67. nSelection = nSelection + 1
  68. end
  69. elseif nKey == 28 then -- Enter key: Selecting a choice
  70. if tActions[nSelection] then
  71. tActions[nSelection]() -- Run the function associated with the action.
  72. else
  73. print("Error: Selection out of bounds: ", nSelection)
  74. read() -- This error is recoverable.
  75. end
  76. end
  77. until false -- Run this loop forever :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement