Advertisement
Guest User

startup

a guest
Oct 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. local p = peripheral.wrap("right")
  2. local door = false
  3.  
  4. door = false
  5. redstone.setOutput("left", true)
  6. --i = 1
  7.  
  8. -- The following 3 functions need to be like this
  9. -- to use the return feature. This is done to
  10. -- refresh the information coming in.
  11.  
  12. function getInfo()
  13.   info = p.getPlayers()
  14.   return info
  15. end
  16.  
  17. function getUsername()
  18.   getInfo()
  19.   return username
  20. end
  21.  
  22. function getPos()
  23.   pos = p.getPlayerByName(username).position
  24.   return pos
  25.  
  26. end
  27.  
  28. function chkDoor()
  29.   if door == true then
  30.     redstone.setOutput("left", false)
  31.   else
  32.     redstone.setOutput("left", true)
  33.   end
  34. end
  35.  
  36. --Main Program. A lot of frustration went into this.
  37. --I'm glad it works now.
  38.  
  39. function chkPlayer()
  40.   if #p.getPlayers() ~= 0 then
  41.  print("Somone is online! Who is it?")
  42.     getInfo()
  43.     getUsername()
  44.     getPos()
  45.  print(username.." is at coords: ")
  46.  print(username.."is in the spot. Opening Door.")
  47.       door = true
  48.       redstone.setOutput("left", true)
  49.     else
  50.  print(username.."is not in the spot. Closing Door.")
  51.       door = false
  52.       redstone.setOutput("left", false)
  53.     end
  54.   end
  55.  
  56. while true do
  57. sleep(2)
  58. --print("Iteration: "..i)
  59. --i = i + 1
  60. chkDoor()
  61. chkPlayer()
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement