Advertisement
Goettervater

versuch

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