Luke_Arwolf

sentry

Apr 11th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. local RAIO_BUSCA = 50
  2. local LIMITE_CIMA = 10
  3. local LIMITE_BAIXO = 5
  4.  
  5. local whitelist = {
  6. ["SeuNickAqui"] = true,
  7. ["NickDoAmigo"] = true
  8. }
  9.  
  10. local detector = peripheral.find("playerDetector")
  11. local modem = peripheral.find("modem")
  12.  
  13. if not detector then print("Erro: Player Detector faltando!") return end
  14. if not modem then print("Erro: Wireless Modem faltando!") return end
  15.  
  16. rednet.open(peripheral.getName(modem))
  17.  
  18. local function prepararCombustivel()
  19. print("Verificando tanque de combustivel...")
  20. if turtle.getFuelLevel() == "unlimited" then return end
  21.  
  22. if turtle.getFuelLevel() < 1000 then
  23. print("Nivel baixo. Puxando carvao do bau inferior...")
  24. turtle.select(1)
  25.  
  26. if turtle.suckDown(64) then
  27. turtle.refuel()
  28. print("Reabastecido! Nivel atual: " .. turtle.getFuelLevel())
  29. else
  30. print("AVISO: Bau vazio ou sem acesso por baixo!")
  31. end
  32. else
  33. print("Combustivel ok! Nivel: " .. turtle.getFuelLevel())
  34. end
  35. end
  36.  
  37. prepararCombustivel()
  38.  
  39. local tX, tY, tZ = gps.locate(2)
  40. if not tY then
  41. print("AVISO: Sem sinal de rede GPS no servidor!")
  42. print("Para calibrar o sensor de altura, digite a coordenada Y (altura) atual da Turtle:")
  43. tY = tonumber(io.read())
  44. end
  45. local startY = tY
  46. local alvo_atual = nil
  47.  
  48. print("Sentry Armada! Monitorando perimetro...")
  49.  
  50. while true do
  51. if not alvo_atual then
  52. local players = detector.getPlayersInRange(RAIO_BUSCA)
  53.  
  54. for _, nick in ipairs(players) do
  55. if not whitelist[nick] then
  56. local dados = detector.getPlayer(nick)
  57. if dados then
  58. if dados.y >= (startY - LIMITE_BAIXO) and dados.y <= (startY + LIMITE_CIMA) then
  59. alvo_atual = nick
  60. rednet.broadcast("ALERTA: Invasor '" .. nick .. "' detectado!", "sentry_net")
  61. break
  62. end
  63. end
  64. end
  65. end
  66. sleep(1)
  67. else
  68. local dados = detector.getPlayer(alvo_atual)
  69.  
  70. if not dados or not detector.isPlayerInRange(RAIO_BUSCA * 1.5, alvo_atual) then
  71. rednet.broadcast("INVASOR PERDIDO: " .. alvo_atual .. " escapou do radar.", "sentry_net")
  72. alvo_atual = nil
  73. prepararCombustivel()
  74. else
  75. local pX = math.floor(dados.x)
  76. local pY = math.floor(dados.y)
  77. local pZ = math.floor(dados.z)
  78.  
  79. rednet.broadcast("RASTREANDO " .. alvo_atual .. " -> X:" .. pX .. " Y:" .. pY .. " Z:" .. pZ, "sentry_net")
  80.  
  81. local _, my, _ = gps.locate(1)
  82.  
  83. if my then
  84. if my < pY and not turtle.detectUp() then
  85. turtle.up()
  86. elseif my > pY and not turtle.detectDown() then
  87. turtle.down()
  88. end
  89. end
  90.  
  91. if not turtle.forward() then
  92. local bloqueio_frente, _ = turtle.inspect()
  93. if bloqueio_frente then
  94. if turtle.up() then
  95. turtle.forward()
  96. else
  97. turtle.turnRight()
  98. turtle.forward()
  99. turtle.turnLeft()
  100. end
  101. end
  102. end
  103. end
  104. sleep(0.5)
  105. end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment