April_The_Sergal

Untitled

Jul 20th, 2025 (edited)
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | Gaming | 0 0
  1. -- CONFIGURATION
  2. local detector = peripheral.wrap("bottom") -- adjust as needed
  3. local outputSide = "back"
  4.  
  5. -- Whitelist of allowed usernames
  6. local whitelist = {
  7.     ["CottonLeSergal"] = true,
  8.     ["CartUniverse"] = true
  9. }
  10.  
  11. -- Bounding box coordinates (inclusive)
  12. local minX, maxX = -26, -24
  13. local minY, maxY = 77, 77
  14. local minZ, maxZ = 24, 27
  15.  
  16. -- Delay between checks (in seconds)
  17. local delay = .1
  18.  
  19. -- Helper: Check if position is inside bounding box
  20. local function isInBounds(pos)
  21.     if not pos or not pos.x or not pos.y or not pos.z then
  22.         return false
  23.     end
  24.     return pos.x >= minX and pos.x <= maxX
  25.        and pos.y >= minY and pos.y <= maxY
  26.        and pos.z >= minZ and pos.z <= maxZ
  27. end
  28.  
  29. -- Helper: Check if any whitelisted player is in range & within bounds
  30. local function validPlayerNearby()
  31.     local players = detector.getOnlinePlayers()
  32.     for _, name in ipairs(players) do
  33.         if whitelist[name] then
  34.             local pos = detector.getPlayerPos(name)
  35.             if isInBounds(pos) then
  36.                 return true
  37.             end
  38.         end
  39.     end
  40.     return false
  41. end
  42.  
  43. -- Main Loop
  44. while true do
  45.     if validPlayerNearby() then
  46.         redstone.setOutput(outputSide, true)
  47.         sleep(5) -- pulse duration
  48.     else
  49.         redstone.setOutput(outputSide, false)
  50.         sleep(delay)
  51.     end
  52. end
  53.  
Tags: lua cc:tweaked
Advertisement
Add Comment
Please, Sign In to add comment