Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 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.   username = info[1].name
  20.   return username
  21. end
  22.  
  23. function getPos()
  24.   pos = p.getPlayerByName(username).position
  25.   return pos
  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: "..pos.x.."x, "..pos.y.."y, "..pos.z.."z, ")
  46.     if pos.x >= -5 and pos.x <= 5
  47.     and pos.y >= -5 and pos.y <= 0
  48.     and pos.z >= -5 and pos.z <= 5 then
  49. --      print(username.."is in the spot. Opening Door.")
  50.       door = true
  51.     else
  52. --      print(username.."is not in the spot. Closing Door.")
  53.       door = false
  54.     end
  55.   end
  56. end
  57.  
  58. while true do
  59. sleep(0.5)
  60. --print("Iteration: "..i)
  61. --i = i + 1
  62. chkDoor()
  63. chkPlayer()
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement