Advertisement
Guest User

Untitled

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