Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RAIO_BUSCA = 50
- local LIMITE_CIMA = 10
- local LIMITE_BAIXO = 5
- local whitelist = {
- ["SeuNickAqui"] = true,
- ["NickDoAmigo"] = true
- }
- local detector = peripheral.find("playerDetector")
- local modem = peripheral.find("modem")
- if not detector then print("Erro: Player Detector faltando!") return end
- if not modem then print("Erro: Wireless Modem faltando!") return end
- rednet.open(peripheral.getName(modem))
- local function prepararCombustivel()
- print("Verificando tanque de combustivel...")
- if turtle.getFuelLevel() == "unlimited" then return end
- if turtle.getFuelLevel() < 1000 then
- print("Nivel baixo. Puxando carvao do bau inferior...")
- turtle.select(1)
- if turtle.suckDown(64) then
- turtle.refuel()
- print("Reabastecido! Nivel atual: " .. turtle.getFuelLevel())
- else
- print("AVISO: Bau vazio ou sem acesso por baixo!")
- end
- else
- print("Combustivel ok! Nivel: " .. turtle.getFuelLevel())
- end
- end
- prepararCombustivel()
- local tX, tY, tZ = gps.locate(2)
- if not tY then
- print("AVISO: Sem sinal de rede GPS no servidor!")
- print("Para calibrar o sensor de altura, digite a coordenada Y (altura) atual da Turtle:")
- tY = tonumber(io.read())
- end
- local startY = tY
- local alvo_atual = nil
- print("Sentry Armada! Monitorando perimetro...")
- while true do
- if not alvo_atual then
- local players = detector.getPlayersInRange(RAIO_BUSCA)
- for _, nick in ipairs(players) do
- if not whitelist[nick] then
- local dados = detector.getPlayer(nick)
- if dados then
- if dados.y >= (startY - LIMITE_BAIXO) and dados.y <= (startY + LIMITE_CIMA) then
- alvo_atual = nick
- rednet.broadcast("ALERTA: Invasor '" .. nick .. "' detectado!", "sentry_net")
- break
- end
- end
- end
- end
- sleep(1)
- else
- local dados = detector.getPlayer(alvo_atual)
- if not dados or not detector.isPlayerInRange(RAIO_BUSCA * 1.5, alvo_atual) then
- rednet.broadcast("INVASOR PERDIDO: " .. alvo_atual .. " escapou do radar.", "sentry_net")
- alvo_atual = nil
- prepararCombustivel()
- else
- local pX = math.floor(dados.x)
- local pY = math.floor(dados.y)
- local pZ = math.floor(dados.z)
- rednet.broadcast("RASTREANDO " .. alvo_atual .. " -> X:" .. pX .. " Y:" .. pY .. " Z:" .. pZ, "sentry_net")
- local _, my, _ = gps.locate(1)
- if my then
- if my < pY and not turtle.detectUp() then
- turtle.up()
- elseif my > pY and not turtle.detectDown() then
- turtle.down()
- end
- end
- if not turtle.forward() then
- local bloqueio_frente, _ = turtle.inspect()
- if bloqueio_frente then
- if turtle.up() then
- turtle.forward()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- end
- sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment