Advertisement
Guest User

2

a guest
Oct 20th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 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. local prox = sensor.wrap("top")
  21. while true do
  22.   local signal = false
  23.   local targets = prox.getTargets()
  24.   for k, v in pairs(targets) do
  25.         if distance(v.Position) < radius then
  26.           signal = true  
  27.          print(k)
  28.          sleep(1)
  29.         term.clear()
  30.        --  print(k)
  31.          term.setCursorPos(1,1)
  32.         end
  33.   end
  34.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement