```lua
local font = renderCreateFont('Tahoma', 10, 4)
local nodes = {}
local nodeCount = 255
function main()
    while not isSampAvailable() do
        wait(0)
    end

    sampRegisterChatCommand('get_node_in_stream', function()
        local fx, fy, fz = getCharCoordinates(PLAYER_PED)
        nodes = {}
        for i = 1, nodeCount do
            local nx, ny, nz = getNthClosestCarNode(fx, fy, fz, i)
            table.insert(nodes, {nx, ny, nz})
        end

        local sortedNodes = {}
        local currentNode = {fx, fy, fz}
        while #nodes > 0 do
            local nearestIndex = 1
            local nearestDistance = getDistanceBetweenCoords3d(currentNode[1], currentNode[2], currentNode[3], nodes[1][1], nodes[1][2], nodes[1][3])
            for i = 2, #nodes do
                local distance = getDistanceBetweenCoords3d(currentNode[1], currentNode[2], currentNode[3], nodes[i][1], nodes[i][2], nodes[i][3])
                if distance < nearestDistance then
                    nearestIndex = i
                    nearestDistance = distance
                end
            end

            table.insert(sortedNodes, nodes[nearestIndex])
            currentNode = nodes[nearestIndex]
            table.remove(nodes, nearestIndex)
        end

        nodes = sortedNodes
        lua_thread.create(function()
            while true do
                wait(0)
                for i = 1, #nodes do
                    local result, sx, sy = convert3DCoordsToScreenEx(nodes[i][1], nodes[i][2], nodes[i][3])
                    if result and isPointOnScreen(nodes[i][1], nodes[i][2], nodes[i][3], 5) then renderFontDrawText(font, 'node #' .. i, sx, sy, 0xFFFFFFFF, 0x90000000) end
                end
            end
        end)
    end)

    sampRegisterChatCommand('route', function(params)
        local nodeIndices = {}
        for part in string.gmatch(params, '([^,]+)') do
            if string.find(part, '-') then
                local startIdx, endIdx = part:match('(%d+)-(%d+)')
                startIdx, endIdx = tonumber(startIdx), tonumber(endIdx)
                if startIdx and endIdx then
                    if startIdx < endIdx then
                        for i = startIdx, endIdx do
                            table.insert(nodeIndices, i)
                        end
                    else
                        for i = startIdx, endIdx, -1 do
                            table.insert(nodeIndices, i)
                        end
                    end
                end
            else
                local idx = tonumber(part)
                if idx then table.insert(nodeIndices, idx) end
            end
        end

        local routeNodes = {}
        for _, idx in ipairs(nodeIndices) do
            if nodes[idx] then table.insert(routeNodes, nodes[idx]) end
        end

        if #routeNodes > 0 then
            driveAlongNodes(routeNodes)
        else
            sampAddChatMessage('Перед использованием, соберите информацию о всех нодах: /get_node_in_stream', 0xFFFFFF)
        end
    end)

    while true do
        wait(0)
    end
end

function driveAlongNodes(routeNodes)
    lua_thread.create(function()
        local car = getCarCharIsUsing(PLAYER_PED)
        for i, node in ipairs(routeNodes) do
            local nx, ny, nz = unpack(node)
            taskCarDriveToCoord(PLAYER_PED, car, nx, ny, nz, 20.0, 1, nil, 0)
            local stuckCounter = 0
            local lastDistance = getDistanceBetweenCoords3d(nx, ny, nz, getCarCoordinates(car))
            while true do
                wait(0)
                local currentDistance = getDistanceBetweenCoords3d(nx, ny, nz, getCarCoordinates(car))
                if currentDistance < 5.0 then
                    sampAddChatMessage('Узел #' .. i .. ' достигнут.', 0xFFFFFF)
                    break
                end

                if math.abs(currentDistance - lastDistance) < 0.1 then
                    stuckCounter = stuckCounter + 1
                else
                    stuckCounter = 0
                end

                if stuckCounter > 100 then
                    sampAddChatMessage('Застревание на узле #' .. i .. ', переход к следующему.', 0xFFFFFF)
                    break
                end

                lastDistance = currentDistance
            end
        end

        clearCharTasksImmediately(PLAYER_PED)
        sampAddChatMessage('Маршрут закончен, экспериментально от Tectrex.', 0xFFFFFF)
    end)
end
```
Optimize the code, improve the code, fix possible bugs, errors, glitches