Advertisement
HPWebcamAble

Simple Door Program - Wireless Detection

May 10th, 2014
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. --[[
  2. This is a program I wrote to open/close a door depending on whether or not
  3. a player is near. It isn't that great. I just works. Note: Uses the
  4. openperipheral sensor block
  5.  
  6. You can give it arguments as follows:
  7. <progname> <sideofsensor> <sideofredstone>
  8.  
  9. if you don't give it anything it just uses right and left respectively.
  10. ]]
  11.  
  12. args = {...}
  13.  
  14. local side = {"right","left"}
  15.  
  16. if args[1] then side[1] = args[1] end
  17. if args[2] then side[2] = args[2] end
  18.  
  19. m = peripheral.wrap(side[1])
  20.  
  21. while true do
  22.   players = m.getPlayerNames()
  23.   if players[1] then
  24.     rs.setOutput(side[2],true)
  25.   else
  26.     rs.setOutput(side[2],false)
  27.   end
  28.   for a,b in pairs(players) do
  29.     term.write(math.floor(a))
  30.     term.write(":")
  31.     print(b)
  32.   end
  33.   sleep(2)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement