Guest User

startup

a guest
Aug 13th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. peripheral.wrap("back")
  2. rednet.open("back")
  3.  
  4. logged = false
  5. user = " "
  6. pass = " "
  7.  
  8. function printList()
  9. print(" ")
  10. print("logout")
  11. print("toggle lift tb")
  12. print("toggle main gate")
  13. print("toggle main portcullis")
  14. print("toggle tower drawbridge")
  15.  
  16. os.pullEvent("key")
  17. end
  18.  
  19. function unlog()
  20.   logged = false
  21.   user = " "
  22.   pass = " "
  23. end
  24.  
  25. function home()
  26.   term.clear()
  27.   term.setTextColor(colors.yellow)
  28.   term.setCursorPos(1,1)
  29.   print("Stendarr OS - TEXT ENABLED")
  30.   print("")
  31.   term.setTextColor(colors.white)
  32.   if logged == false then
  33.     logIn()
  34.   else
  35.     enterCommand()
  36.   end
  37. end
  38.  
  39. function logIn()
  40.  print("=====================")
  41.  print("| Enter Credentials |")
  42.  print("| Username:         |")
  43.  print("| Access Code:      |")
  44.  print("|                   |")
  45.  print("| Access:           |")
  46.  print("=====================")
  47.  term.setCursorPos(12, 5)
  48.  username = io.read()
  49.  term.setCursorPos(15, 6)
  50.  code = io.read()
  51.  if username == "WSearle" then
  52.    if code == "9465" then
  53.      user = "Will"
  54.      pass = "9465"
  55.      logged = true
  56.    end
  57.  elseif username == "RDucker" then
  58.    if code == "7245" then
  59.      user = "Rowan"
  60.      logged = true
  61.      pass = "7245"
  62.    end
  63.  elseif username == "BHorncastle" then
  64.    if code == "7326" then  
  65.      user = "Brandon"
  66.      logged = true
  67.      pass = "7326"
  68.    end
  69.  end
  70.  term.setCursorPos(10, 8)
  71.  if logged == true then
  72.    term.setTextColor(colors.green)
  73.    term.write("Granted")  
  74.  else
  75.    term.setTextColor(colors.red)
  76.    term.write("Denied")
  77.  end
  78.  sleep(3)
  79. end
  80.  
  81. function enterCommand()
  82.   print("Welcome, " .. user)
  83.   print("Type 'list' for commands.")
  84.   print(" ")
  85.   command = io.read()
  86.   if command == "list" then
  87.     printList()
  88.   elseif command == "toggle lift tb" then
  89.     toggleLiftTB()
  90.   elseif command == "logout" then
  91.     unlog()
  92.   elseif command == "toggle main gate" then
  93.     toggleMainGate()
  94.   elseif command == "toggle main portcullis" then
  95.     toggleMainPortcullis()
  96.   elseif command == "toggle tower drawbridge" then
  97.     toggleTowerDrawbridge()
  98.   end    
  99. end
  100.  
  101. function toggleMainGate()
  102.   toggleSystem(6)
  103. end
  104.  
  105. function toggleMainPortcullis()
  106.   toggleSystem(5)
  107. end
  108.  
  109. function toggleTowerDrawbridge()
  110.   toggleSystem(7)
  111. end
  112.  
  113. function toggleLiftTB()
  114.   toggleSystem(2)
  115. end
  116.  
  117. function toggleSystem(rID)
  118.  print(" ")
  119.  print("Establishing connection...")
  120.  print("connect - " .. pass)
  121.  rednet.send(rID,pass)
  122.  
  123.  local myTimer = os.startTimer(5)
  124.  
  125.    while true do
  126.      event,id,msg = os.pullEvent()
  127.      if event == "timer" then
  128.        print("Failed to Connect")
  129.        break    
  130.      
  131.      elseif event == "rednet_message" then
  132.        print("Confirmed")
  133.        rednet.send(rID,"toggle")
  134.        break
  135.        
  136.      end      
  137.    end
  138.  os.pullEvent("key")
  139. end
  140.  
  141. while true do
  142.   home()
  143. end
Add Comment
Please, Sign In to add comment