Advertisement
Guest User

door

a guest
Mar 1st, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. --Wrapping of peripheral (Not sure if neccesary)
  2.  
  3.  
  4. ps = peripheral.wrap("player_detector_0")
  5.  
  6.  
  7. --Table of people alowed to use the door
  8. local allow =
  9. {
  10.  
  11. "TechedZombie"
  12.  
  13. }
  14.  
  15. --Detects a touch and returns the player who touched it
  16. function getTouch()
  17.  
  18.   local event, side, name = os.pullEvent("player")
  19.   print (name)
  20.   return name
  21.  
  22. end
  23. --Compares the name to list of USERS
  24. function checkName(name)
  25.  
  26.   for i = 1, table.getn(allow) do
  27.  
  28.     if name == allow[i] then
  29.    
  30.       return true
  31.      
  32.     end
  33.    
  34.   end
  35.  
  36.   return false
  37.  
  38. end
  39.  
  40. --Opens the door for a few seconds
  41. function door()
  42.  
  43.   redstone.setOutput("right", false)
  44.   sleep(3)
  45.   redstone.setOutput("right", true)
  46.  
  47. end
  48.  
  49.  
  50.  
  51.  
  52. --Main loop
  53. while true do
  54.  
  55.  
  56.   local name = getTouch()
  57.   local boolAllow = checkName(name)
  58.   if boolAllow == true then
  59.    
  60.     door()
  61.    
  62.   end
  63.  
  64.  
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement