Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. -- the location of the redstone lamp relative to the sensor
  2. local offset = {
  3. X = 1,
  4. Y = 1,
  5. Z = 0
  6. }
  7.  
  8. -- how close a player has to be to activate the lamp
  9. local radius = 5
  10.  
  11. -- find the distance from the player position to the offset
  12. function distance(pos)
  13. local xd = pos.X - offset.X
  14. local yd = pos.Y - offset.Y
  15. local zd = pos.Z - offset.Z
  16. return math.sqrt(xd*xd + yd*yd + zd*zd)
  17. end
  18.  
  19.  
  20. local proximity = peripheral.wrap("left")
  21. while true do
  22. local signal = false
  23. local targets = proximity.getPlayers()
  24. for k, v in pairs(targets) do
  25. if distance(v.Position) < radius then
  26. signal = true
  27. end
  28. end
  29. rs.setOutput("top", signal)
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement