Advertisement
MagmaLP

Mobfarm_Automatic_Door

May 7th, 2022 (edited)
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. -- the location of the redstone lamp relative to the sensor
  4. local offset = {
  5.     X = 0,
  6.     Y = -2,
  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. function zu()
  22.     for i = 1,5 do
  23.         rs.setOutput("right", true)
  24.         sleep(0.5)
  25.         rs.setOutput("right", false)
  26.         sleep(0.5)
  27.     end
  28. end
  29.  
  30. function auf()
  31.     for i = 1,5 do
  32.         rs.setOutput("left", true)
  33.         sleep(0.5)
  34.         rs.setOutput("left", false)
  35.         sleep(0.5)
  36.     end
  37. end
  38.  
  39. local proximity = sensor.wrap("top")
  40. while true do
  41.     local signal = false
  42.     local targets = proximity.getTargets()
  43.     for k, v in pairs(targets) do
  44.         if not rs.getInput("bottom", true) then
  45.             if k ~= "MagmaLP" then
  46.                 zu()
  47.             end
  48.         end
  49.         if distance(v.Position) < radius then
  50.             if k == "MagmaLP" then
  51.                 auf()
  52.             end
  53.         end
  54.     end
  55.  
  56.     if not rs.getInput("front", true) then
  57.         zu()
  58.     end
  59.  
  60.     sleep(1)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement