Загрузка данных


--[[
    MM2 WALL BYPASS FARM - XENO EXECUTOR
    ОБХОДИТ СТЕНЫ ЧЕРЕЗ PathfindingService С ПРАВИЛЬНЫМИ НАСТРОЙКАМИ
    НЕ ЗАСТРЕВАЕТ, НЕ ВХОДИТ В СТЕНЫ, БЫСТРОЕ ДВИЖЕНИЕ
]]

repeat task.wait() until game:IsLoaded()
task.wait(3)

local Players = game:GetService("Players")
local LP = Players.LocalPlayer
local RunService = game:GetService("RunService")
local PathfindingService = game:GetService("PathfindingService")
local UIS = game:GetService("UserInputService")
local VU = game:GetService("VirtualUser")
local WS = game:GetService("Workspace")
local Cam = WS.CurrentCamera

local Farming = false
local TargetCoin = nil
local LastCoinCheck = 0
local StuckData = {pos = Vector3.zero, time = 0, jumps = 0}
local PathCache = {}

-- НАСТРОЙКИ PathfindingService ДЛЯ ОБХОДА СТЕН
local PATH_OPTIONS = {
    AgentRadius = 2.0,        -- РАДИУС ПЕРСОНАЖА (МЕНЬШЕ = БЛИЖЕ К СТЕНАМ НО НЕ ЗАСТРЕВАЕТ)
    AgentHeight = 5.0,        -- ВЫСОТА ПЕРСОНАЖА
    AgentCanJump = true,      -- МОЖЕТ ПРЫГАТЬ ЧЕРЕЗ ПРЕПЯТСТВИЯ
    AgentMaxSlope = 45,       -- МАКС УГОЛ ПОДЪЁМА
    WaypointSpacing = 3,      -- РАССТОЯНИЕ МЕЖДУ ТОЧКАМИ (ЧАЩЕ = ТОЧНЕЕ ОБХОД)
    Costs = {
        Water = 9999,         -- НЕ ИДЁМ В ВОДУ
        Plastic = 1,
        Wood = 1,
        Brick = 1,
        Metal = 1,
        Concrete = 1,
        Air = 9999             -- НЕ ПРЫГАЕМ В ПУСТОТУ
    }
}

-- ФУНКЦИЯ ПОЛУЧЕНИЯ ВСЕХ МОНЕТ (КЭШИРУЕТСЯ НА 0.3 СЕК)
local coinCache = {}
local lastCoinScan = 0
local function GetAllCoins()
    if tick() - lastCoinScan < 0.3 and #coinCache > 0 then
        return coinCache
    end
    lastCoinScan = tick()
    coinCache = {}
    
    -- ПОИСК В ПАПКЕ COINS
    local coinFolder = WS:FindFirstChild("Coins")
    if coinFolder then
        for _, obj in ipairs(coinFolder:GetDescendants()) do
            if obj:IsA("BasePart") and obj:FindFirstChild("TouchInterest") then
                if obj.Position.Y > -100 then
                    table.insert(coinCache, obj)
                end
            end
        end
    end
    
    -- ПОИСК ПО ВСЕМУ WORKSPACE (ЗАПАСНОЙ)
    if #coinCache == 0 then
        for _, obj in ipairs(WS:GetDescendants()) do
            if obj:IsA("BasePart") and not obj.CanCollide and obj.Name:lower():find("coin") then
                if obj:FindFirstChild("TouchInterest") and obj.Position.Y > -100 then
                    table.insert(coinCache, obj)
                end
            end
        end
    end
    
    return coinCache
end

-- ПРОВЕРКА НА ЗАСТРЕВАНИЕ И ВЫХОД ИЗ СТЕНЫ
local function Unstuck()
    local char = LP.Character
    if not char then return end
    local root = char:FindFirstChild("HumanoidRootPart")
    local hum = char:FindFirstChild("Humanoid")
    if not root or not hum then return end
    
    local currentPos = root.Position
    
    -- ЕСЛИ НЕ ДВИГАЕМСЯ БОЛЬШЕ 0.8 СЕК - ЗАСТРЯЛИ
    if (currentPos - StuckData.pos).Magnitude < 1.5 and tick() - StuckData.time > 0.8 then
        StuckData.jumps = StuckData.jumps + 1
        
        if StuckData.jumps == 1 then
            -- ПРЫЖОК НАЗАД
            hum.Jump = true
            local backDir = (root.CFrame.LookVector * -1).Unit * 5
            root.CFrame = root.CFrame + backDir
        elseif StuckData.jumps == 2 then
            -- ПРЫЖОК ВПРАВО
            hum.Jump = true
            local rightDir = root.CFrame.RightVector * 5
            root.CFrame = root.CFrame + rightDir
        elseif StuckData.jumps == 3 then
            -- ПРЫЖОК ВЛЕВО
            hum.Jump = true
            local leftDir = root.CFrame.RightVector * -5
            root.CFrame = root.CFrame + leftDir
        else
            -- СБРОС ПОЗИЦИИ - ТЕЛЕПОРТ НА БЛИЖАЙШИЙ СПАВН
            StuckData.jumps = 0
            local spawns = WS:FindFirstChild("SpawnLocation")
            if spawns then
                root.CFrame = spawns.CFrame + Vector3.new(0, 5, 0)
            end
        end
    else
        StuckData.jumps = 0
    end
    
    StuckData.pos = currentPos
    StuckData.time = tick()
end

-- ПОСТРОЕНИЕ ПУТИ С ОБХОДОМ СТЕН
local function BuildPath(targetPos)
    local char = LP.Character
    if not char then return nil end
    local root = char:FindFirstChild("HumanoidRootPart")
    if not root then return nil end
    
    local path = PathfindingService:CreatePath(PATH_OPTIONS)
    
    local success = pcall(function()
        path:ComputeAsync(root.Position, targetPos)
    end)
    
    if success and path.Status == Enum.PathStatus.Success then
        return path
    end
    
    return nil
end

-- ДВИЖЕНИЕ ПО ПОСТРОЕННОМУ ПУТИ
local function FollowPath(path, targetPos)
    local char = LP.Character
    if not char then return false end
    local root = char:FindFirstChild("HumanoidRootPart")
    local hum = char:FindFirstChild("Humanoid")
    if not root or not hum then return false end
    
    local waypoints = path:GetWaypoints()
    if #waypoints == 0 then return false end
    
    for i, wp in ipairs(waypoints) do
        if not Farming or not LP.Character then return false end
        
        -- ПРОВЕРЯЕМ ЖИВА ЛИ МОНЕТА
        if TargetCoin and (not TargetCoin.Parent or not TargetCoin:IsDescendantOf(WS)) then
            return true
        end
        
        -- ПРЫЖОК ЕСЛИ НУЖНО
        if wp.Action == Enum.PathWaypointAction.Jump then
            hum.Jump = true
        end
        
        -- ПОВОРАЧИВАЕМ ПЕРСОНАЖА К ТОЧКЕ
        local lookDir = (wp.Position - root.Position).Unit
        if lookDir.Magnitude > 0 then
            root.CFrame = CFrame.lookAt(root.Position, root.Position + lookDir * 10)
        end
        
        -- ДВИГАЕМСЯ К ТОЧКЕ
        hum:MoveTo(wp.Position)
        
        -- ЖДЁМ ДОСТИЖЕНИЯ ТОЧКИ
        local dist = (root.Position - wp.Position).Magnitude
        local timeout = tick() + (dist / 24) + 2 -- МАКС ВРЕМЯ НА ТОЧКУ
        
        while tick() < timeout do
            if not Farming or not LP.Character then return false end
            if TargetCoin and not TargetCoin:IsDescendantOf(WS) then return true end
            
            local currentDist = (root.Position - wp.Position).Magnitude
            if currentDist < 3 then break end -- ДОСТИГЛИ ТОЧКИ
            
            -- АНТИ-СТАК ПРОВЕРКА
            Unstuck()
            
            -- ПРОВЕРЯЕМ ФИНАЛЬНУЮ ЦЕЛЬ
            if (root.Position - targetPos).Magnitude < 5 then
                return true
            end
            
            RunService.Heartbeat:Wait()
        end
    end
    
    return (root.Position - targetPos).Magnitude < 6
end

-- ОСНОВНАЯ ФУНКЦИЯ ДВИЖЕНИЯ К МОНЕТЕ
local function MoveToCoin(coin)
    local char = LP.Character
    if not char then return false end
    local hum = char:FindFirstChild("Humanoid")
    if not hum then return false end
    
    hum.WalkSpeed = 24 -- БЫСТРАЯ ХОДЬБА
    
    local coinPos = coin.Position
    local path = BuildPath(coinPos)
    
    if path then
        return FollowPath(path, coinPos)
    else
        -- ЗАПАСНОЙ ВАРИАНТ: ПРЯМОЕ ДВИЖЕНИЕ
        hum:MoveTo(coinPos)
        local startTime = tick()
        while tick() - startTime < 5 do
            if not Farming or not LP.Character then return false end
            if not coin:IsDescendantOf(WS) then return true end
            if (LP.Character.HumanoidRootPart.Position - coinPos).Magnitude < 5 then return true end
            Unstuck()
            RunService.Heartbeat:Wait()
        end
    end
    return false
end

-- ГЛАВНЫЙ ЦИКЛ ФАРМА
local function FarmLoop()
    while Farming do
        if LP.Character then
            local root = LP.Character:FindFirstChild("HumanoidRootPart")
            if root then
                local coins = GetAllCoins()
                
                if #coins > 0 then
                    -- СОРТИРУЕМ ПО ДИСТАНЦИИ
                    table.sort(coins, function(a, b)
                        return (root.Position - a.Position).Magnitude < (root.Position - b.Position).Magnitude
                    end)
                    
                    -- БЕРЁМ БЛИЖАЙШУЮ СУЩЕСТВУЮЩУЮ
                    for _, coin in ipairs(coins) do
                        if coin and coin.Parent and coin:IsDescendantOf(WS) then
                            TargetCoin = coin
                            MoveToCoin(coin)
                            break
                        end
                    end
                end
            end
        end
        RunService.Heartbeat:Wait()
    end
end

-- ЗАПУСК/ОСТАНОВКА
local function StartFarm()
    if Farming then return end
    Farming = true
    StuckData = {pos = Vector3.zero, time = 0, jumps = 0}
    TargetCoin = nil
    task.spawn(FarmLoop)
end

local function StopFarm()
    Farming = false
    TargetCoin = nil
    if LP.Character then
        local hum = LP.Character:FindFirstChild("Humanoid")
        if hum then
            hum:Move(Vector3.zero)
            hum.WalkSpeed = 16
        end
    end
end

-- АНТИ-АФК
LP.Idled:Connect(function()
    VU:CaptureController()
    VU:ClickButton2(Vector2.new())
end)

-- РЕСПАВН
LP.CharacterAdded:Connect(function()
    if Farming then
        local wasFarming = Farming
        StopFarm()
        task.wait(1.5)
        if wasFarming then StartFarm() end
    end
end)

-- GUI КНОПКА
task.spawn(function()
    task.wait(3)
    
    local pg = LP:WaitForChild("PlayerGui")
    if not pg then return end
    if pg:FindFirstChild("WallFarm") then pg.WallFarm:Destroy() end
    
    local sg = Instance.new("ScreenGui")
    sg.Name = "WallFarm"
    sg.Parent = pg
    sg.ResetOnSpawn = false
    
    local frame = Instance.new("Frame")
    frame.Size = UDim2.new(0, 175, 0, 50)
    frame.Position = UDim2.new(0.01, 10, 0.01, 10)
    frame.BackgroundColor3 = Color3.fromRGB(12, 12, 12)
    frame.BackgroundTransparency = 0.1
    frame.BorderSizePixel = 0
    frame.Parent = sg
    
    local corner = Instance.new("UICorner")
    corner.CornerRadius = UDim.new(0, 10)
    corner.Parent = frame
    
    local stroke = Instance.new("UIStroke")
    stroke.Color = Color3.fromRGB(0, 200, 255)
    stroke.Thickness = 2
    stroke.Parent = frame
    
    local btn = Instance.new("TextButton")
    btn.Size = UDim2.new(1, -12, 1, -12)
    btn.Position = UDim2.new(0, 6, 0, 6)
    btn.BackgroundColor3 = Color3.fromRGB(180, 25, 25)
    btn.TextColor3 = Color3.fromRGB(255, 255, 255)
    btn.Font = Enum.Font.GothamBlack
    btn.TextSize = 14
    btn.Text = "START FARM"
    btn.BorderSizePixel = 0
    btn.AutoButtonColor = false
    btn.Parent = frame
    
    local btnCorner = Instance.new("UICorner")
    btnCorner.CornerRadius = UDim.new(0, 7)
    btnCorner.Parent = btn
    
    -- ДРАГ
    local drag, ds, sp = false, nil, nil
    frame.InputBegan:Connect(function(i)
        if i.UserInputType == Enum.UserInputType.MouseButton1 then
            drag = true; ds = i.Position; sp = frame.Position
        end
    end)
    UIS.InputEnded:Connect(function(i)
        if i.UserInputType == Enum.UserInputType.MouseButton1 then drag = false end
    end)
    UIS.InputChanged:Connect(function(i)
        if drag and i.UserInputType == Enum.UserInputType.MouseMovement then
            local d = i.Position - ds
            frame.Position = UDim2.new(sp.X.Scale, sp.X.Offset + d.X, sp.Y.Scale, sp.Y.Offset + d.Y)
        end
    end)
    
    -- КЛИК
    btn.MouseButton1Click:Connect(function()
        if Farming then
            StopFarm()
            btn.Text = "START FARM"
            btn.BackgroundColor3 = Color3.fromRGB(180, 25, 25)
            stroke.Color = Color3.fromRGB(0, 200, 255)
        else
            StartFarm()
            btn.Text = "STOP FARM"
            btn.BackgroundColor3 = Color3.fromRGB(25, 170, 25)
            stroke.Color = Color3.fromRGB(0, 255, 150)
        end
    end)
end)

print("WALL BYPASS FARM LOADED - GUI TOP LEFT")
print("USES REAL PATHFINDING - WALKS AROUND WALLS - ANTI STUCK")