```lua
-- Линейная интерполяция
function lerp(a, b, t) return a + (b - a) * t end

-- Гладкое движение камеры
function smoothCameraMovement(targetX, targetY, targetZ, duration)
    local startTime, camX, camY, camZ = localClock(), getActiveCameraPointAt()
    repeat
        local progress = math.min((localClock() - startTime) / duration, 1.0)
        pointCameraAtPoint(lerp(camX, targetX, progress),
                           lerp(camY, targetY, progress),
                           lerp(camZ, targetZ, progress), 2)
        wait(0)
    until progress >= 1.0
end

-- Перемещение камеры к цели
moveCameraToTarget = function(target, duration)
    smoothCameraMovement(target.x, target.y, target.z, duration)
end

-- Проверка на коллизию по линии (Line of sight)
function testCollision(fromX, fromY, fromZ, distance)
    local heading, toX, toY = math.rad(getCharHeading(PLAYER_PED)), 
                              fromX + math.sin(heading) * distance, 
                              fromY + math.cos(heading) * distance
    return processLineOfSight(fromX, fromY, fromZ, toX, toY, fromZ, true, true, true, true, false, false, false, false)
end

-- Передвижение игрока вперед
function movePlayerForward(customX, customY, customZ)
    while true do
        wait(10)
        if isCharOnFoot(PLAYER_PED) then
            local x, y, z = customX or getCharCoordinates(PLAYER_PED)
            local heading = math.rad(getCharHeading(PLAYER_PED))
            local forwardX, forwardY, cameraTarget = x + math.sin(heading) * 3, y + math.cos(heading) * 3, {x = x + math.sin(heading) * 3, y = y + math.cos(heading) * 3, z = z + 2}
            moveCameraToTarget(cameraTarget, 0.5)
            testCollision(x, y, z, 3) and setCharHeading(PLAYER_PED, getCharHeading(PLAYER_PED) + 45) or taskGoStraightToCoord(PLAYER_PED, forwardX, forwardY, z, 1, 1)
        end
    end
end

-- Получение ближайшего игрока
local function getNearestPlayer()
    local px, py, pz = getCharCoordinates(PLAYER_PED)
    local closestPlayer, minDistance = nil, math.huge
    for i = 0, 1000 do
        if sampIsPlayerConnected(i) and i ~= sampGetPlayerIdByCharHandle(PLAYER_PED) then
            local result, x, y, z = sampGetStreamedOutPlayerPos(i)
            if result then
                local distance = getDistanceBetweenCoords3d(px, py, pz, x, y, z)
                closestPlayer, minDistance = (distance < minDistance) and i or closestPlayer, math.min(distance, minDistance)
            end
        end
    end
    return closestPlayer, minDistance
end

-- Главная функция
function main()
    while not isSampAvailable() do wait(0) end

    sampRegisterChatCommand("follow", function()
        local following = true
        sampAddChatMessage("Следуем за ближайшим игроком. Чтобы отключиться, используйте /stopfollow.", 0x00FF00)
        lua_thread.create(function()
            while following do
                local nearestPlayerId, distance = getNearestPlayer()
                if nearestPlayerId and distance < 100 then
                    local result, x, y, z = sampGetStreamedOutPlayerPos(nearestPlayerId)
                    if result then movePlayerForward(x, y, z) end
                else
                    sampAddChatMessage(nearestPlayerId and "Игрока нет поблизости." or "Слишком далеко.", 0xFF0000)
                    following = false
                end
                wait(500)
            end
        end)
    end)

    sampRegisterChatCommand("stopfollow", function()
        sampAddChatMessage("Прекращаем следовать.", 0xFF0000)
        following = false
    end)

    while true do wait(0) end
end
```
[{
	"resource": "/C:/Users/Admin/AppData/Local/Programs/Arizona Games Launcher/bin/arizona/moonloader/SA-MP Helper.lua",
	"owner": "glua",
	"severity": 8,
	"message": "unexpected \"and\", expecting 'label', if statement, function definition, numeric for loop, generic for loop, variable definition, function call or return statement",
	"startLineNumber": 38,
	"startColumn": 39,
	"endLineNumber": 38,
	"endColumn": 39
},{
	"resource": "/C:/Users/Admin/AppData/Local/Programs/Arizona Games Launcher/bin/arizona/moonloader/SA-MP Helper.lua",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "[Warn type:1], `and` can not start",
	"startLineNumber": 38,
	"startColumn": 39,
	"endLineNumber": 38,
	"endColumn": 42
},{
	"resource": "/C:/Users/Admin/AppData/Local/Programs/Arizona Games Launcher/bin/arizona/moonloader/SA-MP Helper.lua",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "[Warn type:1], `or` can not start",
	"startLineNumber": 38,
	"startColumn": 103,
	"endLineNumber": 38,
	"endColumn": 105
}]