konadeluxe

Player sensor /AUTO Door

Oct 14th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 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 = 1,
  7.   Z = 0
  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("top", signal)
  32. end
Add Comment
Please, Sign In to add comment