Advertisement
Guest User

toto

a guest
Apr 1st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. players = {"Edowa43"}
  2.  
  3. minY = -1
  4. maxY = 5
  5.  
  6. maxDistance = 10
  7.  
  8. sensor = peripheral.wrap("right")
  9.  
  10. loop = true
  11. while loop==true do
  12.  
  13.   if (redstone.getInput("top") == true) then
  14.     loop = false
  15.   end
  16.  
  17.   open = false
  18.  
  19.   p = sensor.getPlayers()
  20.  
  21.   for j=1,#p do
  22.    
  23.     name = p[j].name
  24.    
  25.     found = false
  26.    
  27.     for i=1,#players do
  28.       if (players[i] == name) then
  29.         found = true
  30.       end
  31.     end
  32.    
  33.     if (found == true) then
  34.       coord = sensor.getPlayerByName(name).all().position
  35.    
  36.       distance = coord.x*coord.x+coord.z*coord.z
  37.       distance = math.sqrt(distance)
  38.  
  39.       if (distance < maxDistance) then
  40.         print("distance OK"..coord.y)
  41.         if (coord.y > minY) then
  42.           print("Y test")
  43.           if (coord.y < maxY) then
  44.              print("Y ok")
  45.              open = true
  46.           end
  47.         end
  48.       end
  49.     end
  50.   end
  51.  
  52.   redstone.setOutput("back", open)
  53.  
  54.   sleep(0.2)
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement