Advertisement
savior909

Tekkit Classic Reactor

Apr 15th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. --[[
  2.  
  3. yellow = uranium
  4. gray = empty
  5. blue = ice
  6. green = on/off
  7.  
  8. ]]--
  9.  
  10. function tabRem(tab, item)
  11.  for k,v in pairs(tab) do
  12.   if v == item then
  13.     table.remove(tab, k)
  14.   end
  15.  end
  16. end
  17.  
  18. function notify(text, timeout)
  19.  term.setCursorPos(2, 18)
  20.  term.clearLine()
  21.  term.write(text)
  22.  if tonumber(timeout) then
  23.   sleep(timeout)
  24.  else
  25.   sleep(0.8)
  26.  end
  27. end
  28.  
  29. local users = fs.list("security")
  30.  
  31.  menu = {"Login"}
  32.  
  33.  function tabAdd(n)
  34.  tab = {}
  35.  defined = {"Login", "Logout", "Reactor", "Refuel", "Turn  On", "Turn Off", "Back",}
  36.  for i=1, #n do
  37.    table.insert(tab, defined[n[i]])
  38.  end
  39.   if selected > 1 then
  40.    selected = #tab
  41.   end
  42.  return tab
  43. end
  44.  
  45. local menuFunc = {
  46.  ["Login"] = function()
  47.   term.clear()
  48.   term.setCursorPos(2, 2)
  49.   term.write("User: ")
  50.    user = read()
  51.   if fs.exists("security/"..user) then
  52.    file = fs.open(("security/"..user), "r")
  53.     data = file.readAll()
  54.    file.close()
  55.    notify("Welcome "..user..", please write your password.")
  56.   else
  57.    notify("This user doesn't exist!")
  58.    os.reboot()
  59.   end
  60.  
  61.   term.setCursorPos(2, 4)
  62.   term.write("Password: ")
  63.    pass = read("*")
  64.   if pass == data then
  65.    pass, data = nil, nil
  66.    n = {2, 3}
  67.    menu = tabAdd(n)
  68.    notify("Password is correct! Nice to see you!")
  69.   else
  70.    notify("Wrong password, try again later.")
  71.    os.reboot()
  72.   end  
  73.  end,
  74.  ["Logout"] = function()
  75.   notify("Logged out!")
  76.   n = {1}
  77.   menu = tabAdd(n)
  78.  end,
  79.  ["Reactor"] = function()
  80.   n = {4,5,6,7}
  81.   menu = tabAdd(n)
  82.   notify("Reactor menu shown!")
  83.  end,
  84.  ["Turn  On"] = function()
  85.   rs.setBundledOutput("back", colors.combine(rs.getBundledOutput("back"), colors.green))
  86.   notify("Reactor Turned On!")
  87.  end,
  88.  ["Turn Off"] = function()
  89.   rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"), colors.green))
  90.   notify("Reactor Turned Off!")
  91.  end,
  92.  ["Refuel"] = function()
  93.    rs.setBundledOutput("back", 0)
  94.    notify("Emptying Reactor!")
  95.   for i=1, 54 do
  96.    rs.setBundledOutput("back", colors.combine(rs.getBundledOutput("back"), colors.gray))
  97.    sleep(0.3)
  98.    rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"), colors.gray))
  99.    sleep(0.3)
  100.   end
  101.   sleep(0.1)
  102.   notify("Loading Uranium!")
  103.   for i=1, 45 do
  104.    rs.setBundledOutput("back", colors.combine(rs.getBundledOutput("back"), colors.yellow))
  105.    sleep(0.3)
  106.    rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"), colors.yellow))
  107.    sleep(0.3)
  108.   end
  109.   notify("Waiting 20 sec for the rest of Uranium!")
  110.   sleep(20)
  111.   notify("Pushing antarctica to Reactor!")
  112.   for i=1, 9 do
  113.    rs.setBundledOutput("back", colors.combine(rs.getBundledOutput("back"), colors.blue))
  114.    sleep(0.3)
  115.    rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"), colors.blue))
  116.    sleep(0.3)
  117.   end
  118.   notify("Reactor seems to be stable!")
  119.  end,
  120.  ["Back"] = function()
  121.   notify("Going back!")
  122.   n = {2,3}
  123.   menu = tabAdd(n)
  124.  end,
  125. }
  126.  
  127.  
  128. selected = 1
  129.  
  130. repeat
  131.  
  132.  term.clear()
  133.  
  134.  for k,v in pairs(menu) do
  135.   term.setCursorPos(2, k+1)
  136.   if selected == k then
  137.    term.write(string.char(194,59).." "..v)
  138.   else
  139.    term.write("  "..v)
  140.   end
  141.  end
  142.  
  143.  e, p1 = os.pullEvent()
  144.  
  145.  if p1 == 200 then
  146.   selected = selected - 1
  147.    if selected < 1 then
  148.     selected = #menu
  149.    end
  150.  end
  151.  
  152.  if p1 == 208 then
  153.   selected = selected + 1
  154.    if selected > #menu then
  155.     selected = 1
  156.    end
  157.  end
  158.  
  159.  if p1 == 28 then
  160.   menuFunc[menu[selected]]()
  161.  end
  162.  
  163.  sleep(0)
  164.  
  165.  until nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement