Advertisement
MuChT007

Player Detector

Apr 22nd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. --Variables
  2. players = {"MuChT", "Maitretoxik"}
  3. open = false
  4. x, y = term.getSize()
  5. os.pullEvent = os.pullEventRaw
  6.  
  7. --Functions
  8. function drawAcross(line, char)
  9.  term.setCursorPos(1, line)
  10.  for i = 1,  x do
  11.   term.write(char)
  12.  end
  13. end
  14.  
  15. function drawCentered(line, text)
  16.  term.setCursorPos((x - string.len(text))/ 2, line)
  17.  term.write(text)
  18. end
  19.  
  20. function openDoor()
  21.  rs.setOutput("bottom", true)
  22.  sleep(3.0)
  23.  rs.setOutput("bottom", false)
  24.  sleep(0.1)
  25. end
  26.  
  27. function soundAlarm()
  28.  rs.setOutput("top", true)
  29.  sleep(5.0)
  30.  rs.setOutput("top", false)
  31.  sleep(0.1)
  32. end
  33.  
  34. --Body code
  35. term.clear()
  36. drawAcross(1, "-")
  37. drawCentered(2, "Model:MPW54C2PL")
  38. drawCentered(3, "Write by Whiptail84")
  39. drawCentered(4,"https://www.youtube.com/user/Whiptail84")
  40. drawCentered(5, "MuChT Security Company")
  41. drawAcross(6,"-")
  42. while true do
  43.  event, p1 = os.pullEvent()
  44.  
  45.  if event == "player" then
  46.   for i = 1, #players do
  47.    if players[i] == p1 then
  48.     openDoor()
  49.     open = true
  50.     end
  51.   end
  52.  
  53.   if not open then
  54.    soundAlarm()
  55.   end
  56.    
  57.  end
  58.  
  59.  if event == "redstone" then
  60.   openDoor()
  61.  end
  62.    
  63.  if (event == "key") and (p1 == 16) then
  64.   break
  65.  end
  66.  
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement