Advertisement
blackraven99

proximity detector door

Apr 28th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. -- load the API
  2. os.loadAPI("ocs/apis/sensor")
  3.  
  4. -- the location of the door relative to the sensor
  5. local offset = {
  6.   X = 1,
  7.   Y = 1,
  8.   Z = 0
  9. }
  10.  
  11. local radius = 3
  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. -- wrap the sensor
  22. prox = sensor.wrap("left")
  23.  
  24. -- get the targets
  25. while true do
  26. local signal = true
  27. local targets = prox.getTargets()
  28.  
  29. -- loop through them
  30.  for name, v in pairs(targets) do
  31.  
  32.   -- get more details about them
  33.   local moreDetails = prox.getTargetDetails(name)
  34.  
  35.   if distance(v.Position) < radius and name == "Yourname" then signal = false
  36.   end
  37.   end
  38.   rs.setOutput("top", signal)
  39.  
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement