lego11

ACC Staz. Salekhard

Oct 16th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. print("APPARATO CENTRALE COMPUTERIZZATO - SALEKHARD")
  2. print("")
  3. print("Engine running:")print(redstone.getInput("back"))
  4.  
  5.  
  6. local tOptions = {"Deviato", "Corr. Tracc.", "TLBCA PB11"} -- Add menu options here.
  7. local selection = 1
  8.  
  9. while true do
  10. term.clear()
  11. x,y = term.getSize()
  12. y = (y - #tOptions)/2
  13. term.setCursorPos(x,y)
  14. for i = 1, #tOptions do
  15.   if i == selection then
  16.    scrap,y = term.getCursorPos()
  17.    x, scrap = term.getSize()
  18.    x = (x-#tOptions[i])/2 - 3
  19.    term.setCursorPos(x,y)
  20.    print(">> "..tOptions[i].." <<")
  21.   else
  22.    scrap,y = term.getCursorPos()
  23.    x, scrap = term.getSize()
  24.    x = (x-#tOptions[i])/2
  25.    term.setCursorPos(x,y)
  26.    print(tOptions[i])
  27.   end
  28. end
  29. event, key = os.pullEvent("key")
  30. if key == 208 or key == 31 then
  31.   selection = selection + 1
  32. end
  33. if key == 200 or key == 17 then
  34.   selection = selection - 1
  35. end
  36. if selection > #tOptions then
  37.   selection = 1
  38. end
  39. if selection < 1 then
  40.   selection = #tOptions
  41. end
  42. end
  43.  
  44. local function menu(...)
  45.         local sel = 1
  46.         local list = {...}
  47.         local offX,offY = term.getCursorPos()
  48.         local curX,curY = term.getCursorPos()
  49.         while true do
  50.                 if sel > #list then sel = 1 end
  51.                 if sel < 1 then sel = #list end
  52.                 for i = 1,#list do
  53.                         term.setCursorPos(offX,offY+i-1)
  54.                         if sel == i then
  55.                                 print("["..list[i].."]") -- very customisible example print(">"..list[i])
  56.                         else
  57.                                 print(" "..list[i].." ") -- very customisible
  58.                         end
  59.                 end
  60.                 while true do
  61.                         local e,e1,e2,e3,e4,e5 = os.pullEvent()
  62.                         if e == "key" then
  63.                                 if e1 == 200 then -- up key
  64.                                         sel = sel-1
  65.                                                 break
  66.                                 end
  67.                                 if e1 == 208 then -- down key
  68.                                         sel = sel+1
  69.                                                 break
  70.                                 end
  71.                                 if e1 == 28 then
  72.                                         term.setCursorPos(curX,curY)
  73.                                         return list[sel],sel
  74.                                 end
  75.                         end
  76.                 end
  77.         end
  78. end
  79.  
  80. function Option1()
  81.   redstone.setOutput("back", true)
  82.     print("Starting engine...")
  83.   sleep(2)
  84. end
  85.  
  86. function Option2()
  87. redstone.setOutput("back", false)  
  88. print("Stopping engine...")
  89.   sleep(2)
  90. end
  91.  
  92. function Option3()
  93. redstone.setOutput("left", true)
  94.   print("Door opened")
  95.   sleep(5)
  96. redstone.setOutput("left", false)
  97. end
  98.  
  99. while true do
  100.         local selection = menu(
  101.         "Option 1",
  102.         "Option 2",
  103.         "Option 3")
  104.         if selection == "Option 1" then
  105.          Option1()
  106.         elseif selection == "Option 2" then
  107.          Option2()
  108.         elseif selection == "Option 3" then
  109.          Option3()
  110.         end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment