Guest User

startup

a guest
May 7th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 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 = 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.  
  22. local proximity = sensor.wrap("right")
  23. while true do
  24.   local signal = false
  25.   local targets = proximity.getTargets()
  26.   for k, v in pairs(targets) do
  27.         if distance(v.Position) < radius then
  28.           if k == "MagmaLP" or k == "D0me05" or k == "JeremysWorkshop" then
  29.             signal = true
  30.           end
  31.         end
  32.   end
  33.   rs.setOutput("bottom", signal)
  34.   sleep(1)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment