```lua
script_author('fokich, Frolovski')
script_name('autominev1.2')

-- Библиотеки
local imgui = require('mimgui')
require('lib.moonloader')
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local sampev = require("lib.samp.events")
local effil = require('effil') 
local ffi = require('ffi')
local inicfg = require('inicfg')

-- Настройки
local mode = false
local sprint = false
local autojump = false
local stats = false
local renderRadius = 100 -- Начальный радиус

-- Типы руды
local mineStone = true
local mineMetal = false
local mineSilver = false
local mineBronze = false
local mineGold = false

-- Статистика добычи
local totalStone = 0
local totalMetal = 0
local totalSilver = 0
local totalBronze = 0
local totalGold = 0

-- Дополнительные настройки
local stopWithDialog = false
local stopWithSetPlayerPos = false
local stopWithChatMessage = false
local quitgame = false

-- Переменные
local updateid
local font = renderCreateFont("Century Gothic", 12, 5)
local fontonscreen = renderCreateFont("Century Gothic", 18, 5)
local resx, resy = getScreenResolution()
local array = {}

-- Навигационные пути
local waypoints = {
    {x = 491.89, y = 864.09, z = -30.67},
    {x = 488.05, y = 887.62, z = -30.89},
    {x = 492.74, y = 910.78, z = -30.72},
    {x = 506.07, y = 930.31, z = -28.83},
    {x = 520.59, y = 948.26, z = -24.54},
    {x = 542.26, y = 939.62, z = -24.59},
    {x = 564.39, y = 944.78, z = -29.88},
    {x = 587.07, y = 949.63, z = -31.06},
    {x = 610.58, y = 950.06, z = -33.22},
    {x = 634.50, y = 950.55, z = -35.07},
    {x = 658.48, y = 950.16, z = -34.71},
    {x = 679.73, y = 941.98, z = -30.76},
    {x = 697.19, y = 926.34, z = -30.23},
    {x = 706.58, y = 904.65, z = -30.57},
    {x = 716.31, y = 883.63, z = -26.92},
    {x = 719.28, y = 860.64, z = -29.41},
    {x = 719.67, y = 836.77, z = -30.25},
    {x = 713.83, y = 814.09, z = -30.25},
    {x = 700.32, y = 795.06, z = -30.25},
    {x = 678.26, y = 786.33, z = -30.24},
    {x = 654.68, y = 783.72, z = -30.22},
    {x = 630.91, y = 784.24, z = -31.09},
    {x = 607.52, y = 786.38, z = -32.08},
    {x = 591.21, y = 782.86, z = -27.77},
    {x = 573.12, y = 783.32, z = -17.83},
    {x = 580.22, y = 768.93, z = -16.05},
    {x = 558.88, y = 778.72, z = -17.66},
    {x = 540.00, y = 792.78, z = -20.43},
    {x = 523.90, y = 809.50, z = -25.10},
    {x = 512.33, y = 830.15, z = -25.30},
    {x = 502.85, y = 844.49, z = -29.25},
}

-- Текстуры руды
local oreTextures = {
    ['cs_rockdetail2'] = 1, -- Камень
    ['ab_flakeywall'] = 2,  -- Металл
    ['metalic128'] = 3,     -- Серебро
    ['Strip_Gold'] = 4,     -- Бронза
    ['gold128'] = 5         -- Золото
}
local resources = {}

-- ImGui переменные
local WinState = imgui.new.bool()
local WinTg = imgui.new.bool()
local WinStats = imgui.new.bool()
local WinSet = imgui.new.bool()
local tknField = imgui.new.char[256]()
local uIdField = imgui.new.char[256]()
local SliderInt = imgui.new.int(1) -- Цель добычи
local RadiusSlider = imgui.new.int(renderRadius) -- Слайдер радиуса

-- Конфигурация
local mainIni = inicfg.load({
    main = {
        token = '',
        userId = ''
    }
}, 'autominev1.ini')

if not doesFileExist('moonloader/config/autominev1.ini') then
    inicfg.save(mainIni, 'autominev1.ini')
end

-- Функции для работы с Telegram (оставлены без изменений)
function threadHandle(runner, url, args, resolve, reject)
    local t = runner(url, args)
    local r = t:get(0)
    while not r do
        r = t:get(0)
        wait(0)
    end
    local status = t:status()
    if status == 'completed' then
        local ok, result = r[1], r[2]
        if ok then resolve(result) else reject(result) end
    elseif status == 'canceled' then
        reject(status)
    end
    t:cancel(0)
end

function requestRunner()
    return effil.thread(function(u, a)
        local https = require 'ssl.https'
        local ok, result = pcall(https.request, u, a)
        if ok then return {true, result} else return {false, result} end
    end)
end

function async_http_request(url, args, resolve, reject)
    local runner = requestRunner()
    if not reject then reject = function() end end
    lua_thread.create(function()
        threadHandle(runner, url, args, resolve, reject)
    end)
end

function encodeUrl(str)
    str = str:gsub(' ', '%+')
    str = str:gsub('\n', '%%0A')
    return u8:encode(str, 'CP1251')
end

function sendTelegramNotification(msg) 
    msg = msg:gsub('{......}', '') 
    msg = encodeUrl(msg) 
    async_http_request('https://api.telegram.org/bot' .. mainIni.main.token .. '/sendMessage?chat_id=' .. mainIni.main.userId .. '&reply_markup={"keyboard": [["Mode", "Stats"]], "resize_keyboard": true}&text='..msg, '', function(result) end) 
end

function get_telegram_updates() 
    while not updateid do wait(1) end 
    local runner = requestRunner()
    local reject = function() end
    local args = ''
    while true do
        url = 'https://api.telegram.org/bot'..mainIni.main.token..'/getUpdates?chat_id='..mainIni.main.userId..'&offset=-1'
        threadHandle(runner, url, args, processing_telegram_messages, reject)
        wait(0)
    end
end

function processing_telegram_messages(result)
    if result then
        local proc_table = decodeJson(result)
        if proc_table.ok and #proc_table.result > 0 then
            local res_table = proc_table.result[1]
            if res_table and res_table.update_id ~= updateid then
                updateid = res_table.update_id
                local message_from_user = res_table.message.text
                if message_from_user then
                    local text = u8:decode(message_from_user) .. ' '
                    if text:match('^/start') then
                        sendTelegramNotification('Привет! Это бот для шахты. Управляй через кнопки ниже.\nDeveloped by fokich & Frolovski')
                    elseif text:match('^Mode') then
                        mode = not mode
                        sendTelegramNotification(mode and 'Бот включен' or 'Бот выключен')
                    elseif text:match('^Stats') then
                        sendTelegramNotification('Добыто:\nКамень: ' .. totalStone .. '\nМеталл: ' .. totalMetal .. '\nСеребро: ' .. totalSilver .. '\nБронза: ' .. totalBronze .. '\nЗолото: ' .. totalGold .. '\nОсталось: ' .. SliderInt[0] - (totalStone + totalMetal + totalSilver + totalBronze + totalGold))
                    else
                        sendTelegramNotification('Неизвестная команда!')
                    end
                end
            end
        end
    end
end

function getLastUpdate()
    async_http_request('https://api.telegram.org/bot'..mainIni.main.token..'/getUpdates?chat_id='..mainIni.main.userId..'&offset=-1', '', function(result)
        if result then
            local proc_table = decodeJson(result)
            if proc_table.ok and #proc_table.result > 0 then
                local res_table = proc_table.result[1]
                updateid = res_table.update_id
            else
                updateid = 1
            end
        end
    end)
end

-- Новая функция: проверка наличия игроков рядом с рудой
function isPlayerNearOre(x, y, z, radius)
    for i = 0, sampGetMaxPlayerId() do
        if sampIsPlayerConnected(i) then
            local result, ped = sampGetCharHandleBySampPlayerId(i)
            if result and ped ~= PLAYER_PED then -- Исключаем себя
                local px, py, pz = getCharCoordinates(ped)
                if getDistanceBetweenCoords3d(px, py, pz, x, y, z) <= radius then
                    return true
                end
            end
        end
    end
    return false
end

-- Функция поиска ближайшей точки пути
function findNearestWaypoint(px, py, pz)
    local nearest = nil
    local minDist = math.huge
    for i, wp in ipairs(waypoints) do
        local dist = getDistanceBetweenCoords3d(px, py, pz, wp.x, wp.y, wp.z)
        if dist < minDist then
            minDist = dist
            nearest = i
        end
    end
    return nearest
end

-- Функция движения по навигационным путям
function runToPoint(tox, toy, toz)
    local px, py, pz = getCharCoordinates(PLAYER_PED)
    local startIdx = findNearestWaypoint(px, py, pz)
    local endIdx = findNearestWaypoint(tox, toy, toz)

    if startIdx and endIdx then
        local direction = startIdx < endIdx and 1 or -1
        for i = startIdx, endIdx, direction do
            local wp = waypoints[i]
            local x, y, z = getCharCoordinates(PLAYER_PED)
            local angle = getHeadingFromVector2d(wp.x - x, wp.y - y)
            if getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 2 then 
                setCameraPositionUnfixed(0, math.rad(angle - 90)) 
            end
            stopRun = false
            while getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 3 do
                local tx, ty, tz = convert3DCoordsToScreen(wp.x, wp.y, wp.z)
                Draw3DCircle(wp.x, wp.y, wp.z - 0.1, 3, 0xffcc66ff)
                setGameKeyState(1, -255)
                if sprint then setGameKeyState(16, 1) end
                if autojump and getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 18.0 then 
                    local rand = math.random(0, 9999999)
                    if rand >= 9909999 then
                        setGameKeyState(16, 0)
                        setGameKeyState(14, 255)
                    end
                end
                wait(1)
                x, y, z = getCharCoordinates(PLAYER_PED)
                angle = getHeadingFromVector2d(wp.x - x, wp.y - y)
                setCameraPositionUnfixed(0, math.rad(angle - 90))
                if stopRun then
                    stopRun = false
                    return
                end
            end
        end
    end
    
    -- Финальный рывок к руде
    local x, y, z = getCharCoordinates(PLAYER_PED)
    local angle = getHeadingFromVector2d(tox - x, toy - y)
    if getDistanceBetweenCoords2d(x, y, tox, toy) > 2 then 
        setCameraPositionUnfixed(0, math.rad(angle - 90)) 
    end
    stopRun = false
    while getDistanceBetweenCoords2d(x, y, tox, toy) > 3 do
        local tx, ty, tz = convert3DCoordsToScreen(tox, toy, toz)
        Draw3DCircle(tox, toy, toz - 0.1, 3, 0xffcc66ff)
        setGameKeyState(1, -255)
        if sprint then setGameKeyState(16, 1) end
        if autojump and getDistanceBetweenCoords2d(x, y, tox, toy) > 18.0 then 
            local rand = math.random(0, 9999999)
            if rand >= 9909999 then
                setGameKeyState(16, 0)
                setGameKeyState(14, 255)
            end
        end
        wait(1)
        x, y, z = getCharCoordinates(PLAYER_PED)
        angle = getHeadingFromVector2d(tox - x, toy - y)
        setCameraPositionUnfixed(0, math.rad(angle - 90))
        if stopRun then
            stopRun = false
            break
        end
    end
end

-- Основная функция
function main()
    while not isSampAvailable() do wait(0) end
    wait(200)
    sampAddChatMessage('{cc66ff}[auto-mine]: {ffffff}Скрипт загружен! Авторы: fokichevskiy, Frolovski', -1)
    sampRegisterChatCommand('amine', function()
        WinState[0] = not WinState[0]
    end)    
    getLastUpdate()
    lua_thread.create(get_telegram_updates)
    while true do
        wait(0)
        renderRadius = RadiusSlider[0] -- Синхронизация радиуса со слайдером
        local thr1 = lua_thread.create_suspended(lookForMine)
        if mode then
            thr1:run()
            if #array > 0 then
                local res, position, dist = GetNearestCoords(array)
                if res then
                    local x, y, z = position[1], position[2], position[3]
                    local px, py, pz = getCharCoordinates(PLAYER_PED)
                    local totalMined = totalStone + totalMetal + totalSilver + totalBronze + totalGold
                    if totalMined < SliderInt[0] then
                        if not isPlayerNearOre(x, y, z, 5) then -- Проверка на игроков в радиусе 5 метров
                            if getDistanceBetweenCoords3d(px, py, pz, x, y, z) > 2 then
                                runToPoint(x, y, z) -- Используем навигационные пути
                            else
                                array = {}
                                repeat
                                    setGameKeyState(21, -256) -- Добыча
                                    wait(200)
                                    setGameKeyState(21, 0)
                                until true
                            end
                        end
                    else
                        mode = false
                        sampAddChatMessage('{cc66ff}[auto-mine]: {FFFFFF}Бот собрал заданное количество ресурсов!', -1)
                        sendTelegramNotification('Бот собрал заданное количество ресурсов')
                    end
                else
                    renderFontDrawText(fontonscreen, 'Руда не найдена', resx / 2 + 500, resy / 2, -1, false)
                end
            else
                renderFontDrawText(fontonscreen, 'Руда не найдена', resx / 2 + 500, resy / 2, -1, false)
            end
        else
            thr1:terminate()
        end
        if testCheat('amiii') then
            mode = not mode
        end
    end
end

-- Логика поиска руды
function lookForMine()
    array = {} -- Очищаем массив перед поиском
    for i = 0, 2048 do
        if sampIs3dTextDefined(i) then
            local text, color, x, y, z, distance, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(i)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local dist = getDistanceBetweenCoords3d(myX, myY, myZ, x, y, z)
            if text:find('Месторождение ресурсов') and dist <= renderRadius then
                table.insert(array, {['position'] = {x, y, z}, ['distance'] = dist})
            end
        end
    end
    for k, v in pairs(resources) do
        local object = sampGetObjectHandleBySampId(k)
        if doesObjectExist(object) and isObjectOnScreen(object) then
            local _, ox, oy, oz = getObjectCoordinates(object)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local dist = getDistanceBetweenCoords3d(myX, myY, myZ, ox, oy, oz)
            if dist <= renderRadius then
                if (v == 1 and mineStone) or (v == 2 and mineMetal) or (v == 3 and mineSilver) or (v == 4 and mineBronze) or (v == 5 and mineGold) then
                    table.insert(array, {['position'] = {ox, oy, oz}, ['distance'] = dist})
                end
            end
        end
    end
end

function GetNearestCoords(tbl)
    if #tbl > 0 then
        table.sort(tbl, function(a, b) return a.distance < b.distance end)
        return true, tbl[1].position, tbl[1].distance
    end
    return false
end

-- Обработка событий SAMP
function sampev.onSetObjectMaterial(id, data)
    local object = sampGetObjectHandleBySampId(id)
    if doesObjectExist(object) and getObjectModel(object) == 3930 then
        if oreTextures[data.textureName] then
            resources[id] = oreTextures[data.textureName]
        end
    end
end

function sampev.onDestroyObject(id)
    if resources[id] then
        resources[id] = nil
    end
end

function sampev.onDisplayGameText(style, tm, text)
    if text == "stone + 1" then totalStone = totalStone + 1
    elseif text == "metal + 1" then totalMetal = totalMetal + 1
    elseif text == "silver + 1" then totalSilver = totalSilver + 1
    elseif text == "bronze + 1" then totalBronze = totalBronze + 1
    elseif text == "gold + 1" then totalGold = totalGold + 1
    elseif text == "stone + 2" then totalStone = totalStone + 2
    elseif text == "metal + 2" then totalMetal = totalMetal + 2
    elseif text == "silver + 2" then totalSilver = totalSilver + 2
    elseif text == "bronze + 2" then totalBronze = totalBronze + 2
    elseif text == "gold + 2" then totalGold = totalGold + 2
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if stopWithDialog then
        mode = false
        sendTelegramNotification('Администратор ответил вам в /pm: ' .. text)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function sampev.onSetPlayerPos(position)
    if stopWithSetPlayerPos then
        mode = false
        sendTelegramNotification('Сервер/Администратор изменил вашу позицию: ' .. position)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function sampev.onServerMessage(color, text)
    if stopWithChatMessage and text:find("Вы тут?") or text:find("Вы тут") or text:find("Вы здесь") or text:find("Вы здесь?") or text:find("вы тут?") or text:find("вы тут") or text:find("вы здесь") or text:find("вы здесь?") or text:find("в ы з д е с ь?") then
        mode = false
        local allchat = '\n'
        for i = 100-3, 99 do
            local getstr = select(1, sampGetChatString(i))
            allchat = allchat .. getstr .. '\n'
        end
        sendTelegramNotification('Бота спросили: вы тут?' .. allchat)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function Draw3DCircle(x, y, z, radius, color)
    local screen_x_line_old, screen_y_line_old
    for rot = 0, 360 do
        local rot_temp = math.rad(rot)
        local lineX, lineY, lineZ = radius * math.cos(rot_temp) + x, radius * math.sin(rot_temp) + y, z
        local screen_x_line, screen_y_line = convert3DCoordsToScreen(lineX, lineY, lineZ)
        if screen_x_line ~= nil and screen_x_line_old ~= nil and isPointOnScreen(lineX, lineY, lineZ, 1) then
            renderDrawLine(screen_x_line, screen_y_line, screen_x_line_old, screen_y_line_old, 3, color)
        end
        screen_x_line_old, screen_y_line_old = screen_x_line, screen_y_line
    end
end

-- Интерфейс ImGui
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(200, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 320), imgui.Cond.FirstUseEver)
    imgui.Begin('##amine', WinState, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
    imgui.SetCursorPos(imgui.ImVec2(65, 25))
    imgui.PushFont(smal)
    imgui.Text(u8'auto-mine')
    if imgui.BeginChild(u8'Настройки', imgui.ImVec2(190, 200), true) then
        imgui.PushFont(big)
        if imgui.RadioButtonBool(u8'Статус', mode) then mode = not mode end
        if imgui.RadioButtonBool(u8'Бег', sprint) then sprint = not sprint end
        if imgui.RadioButtonBool(u8'Прыжки', autojump) then autojump = not autojump end
        if imgui.RadioButtonBool(u8'Камень', mineStone) then mineStone = not mineStone end
        if imgui.RadioButtonBool(u8'Металл', mineMetal) then mineMetal = not mineMetal end
        if imgui.RadioButtonBool(u8'Серебро', mineSilver) then mineSilver = not mineSilver end
        if imgui.RadioButtonBool(u8'Бронза', mineBronze) then mineBronze = not mineBronze end
        if imgui.RadioButtonBool(u8'Золото', mineGold) then mineGold = not mineGold end
        imgui.SliderInt(u8'Радиус поиска', RadiusSlider, 10, 300) -- Исправленный слайдер
        imgui.SliderInt(u8'Цель добычи', SliderInt, 1, 10000)
        imgui.SetCursorPos(imgui.ImVec2(135, 162))
        if imgui.Button(u8'Сброс') then totalStone, totalMetal, totalSilver, totalBronze, totalGold = 0, 0, 0, 0, 0 end
        imgui.SetCursorPos(imgui.ImVec2(100, 10))
        if imgui.Button('TG') then WinTg[0] = not WinTg[0] end
        imgui.SetCursorPos(imgui.ImVec2(128, 10))
        if imgui.Button('Stats') then WinStats[0] = not WinStats[0] end
        imgui.SetCursorPos(imgui.ImVec2(100, 35))
        if imgui.Button(u8'Настройки') then WinSet[0] = not WinSet[0] end
        imgui.EndChild()
    end
    if imgui.BeginChild(u8'asd', imgui.ImVec2(190, 55), true) then
        imgui.SetCursorPos(imgui.ImVec2(12, 20))
        imgui.Text(u8'Авторы: fokich, Frolovski')
        imgui.SetCursorPos(imgui.ImVec2(122, 10))
        imgui.Text(u8'Телеграм')
        if imgui.IsItemClicked() then os.execute('explorer https://t.me/devfokich') end
        imgui.SetCursorPos(imgui.ImVec2(123, 26))
        imgui.Text(u8'BlastHack')
        if imgui.IsItemClicked() then os.execute('explorer https://www.blast.hk/threads/199063/page-6') end
        imgui.EndChild()
    end
    imgui.End()
end)

imgui.OnFrame(function() return WinSet[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(280, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinSet, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.Text(u8'Выключение')
    if imgui.RadioButtonBool(u8'при диалоге от админа', stopWithDialog) then stopWithDialog = not stopWithDialog end
    if imgui.RadioButtonBool(u8'при изменении позиции сервером', stopWithSetPlayerPos) then stopWithSetPlayerPos = not stopWithSetPlayerPos end
    if imgui.RadioButtonBool(u8'при проверке на бота в чате', stopWithChatMessage) then stopWithChatMessage = not stopWithChatMessage end
    if imgui.RadioButtonBool(u8'Выходить из игры', quitgame) then quitgame = not quitgame end
    imgui.End()
end)

imgui.OnFrame(function() return WinTg[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinTg, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.InputText(u8"Токен", tknField, 256)
    imgui.InputText(u8"User id", uIdField, 256)
    if imgui.Button(u8'Сохранить!') then
        mainIni.main.token = u8:decode(ffi.string(tknField))
        mainIni.main.userId = u8:decode(ffi.string(uIdField))
        inicfg.save(mainIni, 'autominev1.ini')
        getLastUpdate()
    end
    if imgui.Button(u8'Тестовое Сообщение') then
        sampAddChatMessage('[Telegram] Отправляю тестовое сообщение', -1)
        sendTelegramNotification('Тестовое сообщение от '..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))))
    end
    imgui.End()
end)

imgui.OnFrame(function() return WinStats[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 150), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinStats, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.Text(u8'Камень: ' .. totalStone)
    imgui.Text(u8'Металл: ' .. totalMetal)
    imgui.Text(u8'Серебро: ' .. totalSilver)
    imgui.Text(u8'Бронза: ' .. totalBronze)
    imgui.Text(u8'Золото: ' .. totalGold)
    imgui.Text(u8'Осталось: ' .. SliderInt[0] - (totalStone + totalMetal + totalSilver + totalBronze + totalGold))
    imgui.End()
end).HideCursor = true

imgui.OnInitialize(function()
    themeexam()
    imgui.GetIO().IniFilename = nil
    local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
    imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 14.0, nil, glyph_ranges)
    smal = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 17.0, nil, glyph_ranges)
    big = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, glyph_ranges)
end)

function themeexam()
    imgui.SwitchContext()
    local style  = imgui.GetStyle()
    local colors = style.Colors
    local clr    = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2
  
    style.WindowRounding         = 4.0
    style.WindowTitleAlign       = ImVec2(0.5, 0.5)
    style.FrameRounding          = 4.0
    style.ItemSpacing            = ImVec2(10, 5)
    style.ScrollbarSize          = 15
    style.ScrollbarRounding      = 0
    style.GrabMinSize            = 9.6
    style.GrabRounding           = 1.0
    style.WindowPadding          = ImVec2(10, 10)
    style.AntiAliasedLines       = true
    style.FramePadding           = ImVec2(5, 4)
    style.DisplayWindowPadding   = ImVec2(27, 27)
    style.DisplaySafeAreaPadding = ImVec2(5, 5)
    style.ButtonTextAlign        = ImVec2(0.5, 0.5)
    style.IndentSpacing          = 12.0
    style.Alpha                  = 1.0
  
    colors[clr.Text]                 = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]         = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]             = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.PopupBg]              = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border]               = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]         = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]              = ImVec4(0.44, 0.44, 0.44, 0.60)
    colors[clr.FrameBgHovered]       = ImVec4(0.57, 0.57, 0.57, 0.70)
    colors[clr.FrameBgActive]        = ImVec4(0.76, 0.76, 0.76, 0.80)
    colors[clr.TitleBg]              = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]        = ImVec4(0.16, 0.16, 0.16, 1.00)
    colors[clr.TitleBgCollapsed]     = ImVec4(0.00, 0.00, 0.00, 0.60)
    colors[clr.MenuBarBg]            = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]          = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]        = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]  = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]            = ImVec4(0.13, 0.75, 0.55, 0.80)
    colors[clr.SliderGrab]           = ImVec4(0.13, 0.75, 0.75, 0.80)
    colors[clr.SliderGrabActive]     = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Button]               = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.ButtonHovered]        = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.ButtonActive]         = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Header]               = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.HeaderHovered]        = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.HeaderActive]         = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Separator]            = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.SeparatorHovered]     = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.SeparatorActive]      = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.ResizeGrip]           = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.ResizeGripHovered]    = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.ResizeGripActive]     = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.PlotLines]            = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]     = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]        = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg]       = ImVec4(0.26, 0.59, 0.98, 0.35)
end
```
script_author('fokich, Frolovski')
script_name('autominev1.2')

-- Библиотеки
local imgui = require('mimgui')
require('lib.moonloader')
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local sampev = require("lib.samp.events")
local effil = require('effil') 
local ffi = require('ffi')
local inicfg = require('inicfg')

-- Настройки
local mode = false
local sprint = false
local autojump = false
local stats = false
local renderRadius = 100 -- Начальный радиус

-- Типы руды
local mineStone = true
local mineMetal = false
local mineSilver = false
local mineBronze = false
local mineGold = false

-- Статистика добычи
local totalStone = 0
local totalMetal = 0
local totalSilver = 0
local totalBronze = 0
local totalGold = 0

-- Дополнительные настройки
local stopWithDialog = false
local stopWithSetPlayerPos = false
local stopWithChatMessage = false
local quitgame = false

-- Переменные
local updateid
local font = renderCreateFont("Century Gothic", 12, 5)
local fontonscreen = renderCreateFont("Century Gothic", 18, 5)
local resx, resy = getScreenResolution()
local array = {}

-- Навигационные пути
local waypoints = {
    {x = 491.89, y = 864.09, z = -30.67},
    {x = 488.05, y = 887.62, z = -30.89},
    {x = 492.74, y = 910.78, z = -30.72},
    {x = 506.07, y = 930.31, z = -28.83},
    {x = 520.59, y = 948.26, z = -24.54},
    {x = 542.26, y = 939.62, z = -24.59},
    {x = 564.39, y = 944.78, z = -29.88},
    {x = 587.07, y = 949.63, z = -31.06},
    {x = 610.58, y = 950.06, z = -33.22},
    {x = 634.50, y = 950.55, z = -35.07},
    {x = 658.48, y = 950.16, z = -34.71},
    {x = 679.73, y = 941.98, z = -30.76},
    {x = 697.19, y = 926.34, z = -30.23},
    {x = 706.58, y = 904.65, z = -30.57},
    {x = 716.31, y = 883.63, z = -26.92},
    {x = 719.28, y = 860.64, z = -29.41},
    {x = 719.67, y = 836.77, z = -30.25},
    {x = 713.83, y = 814.09, z = -30.25},
    {x = 700.32, y = 795.06, z = -30.25},
    {x = 678.26, y = 786.33, z = -30.24},
    {x = 654.68, y = 783.72, z = -30.22},
    {x = 630.91, y = 784.24, z = -31.09},
    {x = 607.52, y = 786.38, z = -32.08},
    {x = 591.21, y = 782.86, z = -27.77},
    {x = 573.12, y = 783.32, z = -17.83},
    {x = 580.22, y = 768.93, z = -16.05},
    {x = 558.88, y = 778.72, z = -17.66},
    {x = 540.00, y = 792.78, z = -20.43},
    {x = 523.90, y = 809.50, z = -25.10},
    {x = 512.33, y = 830.15, z = -25.30},
    {x = 502.85, y = 844.49, z = -29.25},
}

-- Текстуры руды
local oreTextures = {
    ['cs_rockdetail2'] = 1, -- Камень
    ['ab_flakeywall'] = 2,  -- Металл
    ['metalic128'] = 3,     -- Серебро
    ['Strip_Gold'] = 4,     -- Бронза
    ['gold128'] = 5         -- Золото
}
local resources = {}

-- ImGui переменные
local WinState = imgui.new.bool()
local WinTg = imgui.new.bool()
local WinStats = imgui.new.bool()
local WinSet = imgui.new.bool()
local tknField = imgui.new.char[256]()
local uIdField = imgui.new.char[256]()
local SliderInt = imgui.new.int(1) -- Цель добычи
local RadiusSlider = imgui.new.int(renderRadius) -- Слайдер радиуса

-- Конфигурация
local mainIni = inicfg.load({
    main = {
        token = '',
        userId = ''
    }
}, 'autominev1.ini')

if not doesFileExist('moonloader/config/autominev1.ini') then
    inicfg.save(mainIni, 'autominev1.ini')
end

-- Функции для работы с Telegram (оставлены без изменений)
function threadHandle(runner, url, args, resolve, reject)
    local t = runner(url, args)
    local r = t:get(0)
    while not r do
        r = t:get(0)
        wait(0)
    end
    local status = t:status()
    if status == 'completed' then
        local ok, result = r[1], r[2]
        if ok then resolve(result) else reject(result) end
    elseif status == 'canceled' then
        reject(status)
    end
    t:cancel(0)
end

function requestRunner()
    return effil.thread(function(u, a)
        local https = require 'ssl.https'
        local ok, result = pcall(https.request, u, a)
        if ok then return {true, result} else return {false, result} end
    end)
end

function async_http_request(url, args, resolve, reject)
    local runner = requestRunner()
    if not reject then reject = function() end end
    lua_thread.create(function()
        threadHandle(runner, url, args, resolve, reject)
    end)
end

function encodeUrl(str)
    str = str:gsub(' ', '%+')
    str = str:gsub('\n', '%%0A')
    return u8:encode(str, 'CP1251')
end

function sendTelegramNotification(msg) 
    msg = msg:gsub('{......}', '') 
    msg = encodeUrl(msg) 
    async_http_request('https://api.telegram.org/bot' .. mainIni.main.token .. '/sendMessage?chat_id=' .. mainIni.main.userId .. '&reply_markup={"keyboard": [["Mode", "Stats"]], "resize_keyboard": true}&text='..msg, '', function(result) end) 
end

function get_telegram_updates() 
    while not updateid do wait(1) end 
    local runner = requestRunner()
    local reject = function() end
    local args = ''
    while true do
        url = 'https://api.telegram.org/bot'..mainIni.main.token..'/getUpdates?chat_id='..mainIni.main.userId..'&offset=-1'
        threadHandle(runner, url, args, processing_telegram_messages, reject)
        wait(0)
    end
end

function processing_telegram_messages(result)
    if result then
        local proc_table = decodeJson(result)
        if proc_table.ok and #proc_table.result > 0 then
            local res_table = proc_table.result[1]
            if res_table and res_table.update_id ~= updateid then
                updateid = res_table.update_id
                local message_from_user = res_table.message.text
                if message_from_user then
                    local text = u8:decode(message_from_user) .. ' '
                    if text:match('^/start') then
                        sendTelegramNotification('Привет! Это бот для шахты. Управляй через кнопки ниже.\nDeveloped by fokich & Frolovski')
                    elseif text:match('^Mode') then
                        mode = not mode
                        sendTelegramNotification(mode and 'Бот включен' or 'Бот выключен')
                    elseif text:match('^Stats') then
                        sendTelegramNotification('Добыто:\nКамень: ' .. totalStone .. '\nМеталл: ' .. totalMetal .. '\nСеребро: ' .. totalSilver .. '\nБронза: ' .. totalBronze .. '\nЗолото: ' .. totalGold .. '\nОсталось: ' .. SliderInt[0] - (totalStone + totalMetal + totalSilver + totalBronze + totalGold))
                    else
                        sendTelegramNotification('Неизвестная команда!')
                    end
                end
            end
        end
    end
end

function getLastUpdate()
    async_http_request('https://api.telegram.org/bot'..mainIni.main.token..'/getUpdates?chat_id='..mainIni.main.userId..'&offset=-1', '', function(result)
        if result then
            local proc_table = decodeJson(result)
            if proc_table.ok and #proc_table.result > 0 then
                local res_table = proc_table.result[1]
                updateid = res_table.update_id
            else
                updateid = 1
            end
        end
    end)
end

-- Новая функция: проверка наличия игроков рядом с рудой
function isPlayerNearOre(x, y, z, radius)
    for i = 0, sampGetMaxPlayerId() do
        if sampIsPlayerConnected(i) then
            local result, ped = sampGetCharHandleBySampPlayerId(i)
            if result and ped ~= PLAYER_PED then -- Исключаем себя
                local px, py, pz = getCharCoordinates(ped)
                if getDistanceBetweenCoords3d(px, py, pz, x, y, z) <= radius then
                    return true
                end
            end
        end
    end
    return false
end

-- Функция поиска ближайшей точки пути
function findNearestWaypoint(px, py, pz)
    local nearest = nil
    local minDist = math.huge
    for i, wp in ipairs(waypoints) do
        local dist = getDistanceBetweenCoords3d(px, py, pz, wp.x, wp.y, wp.z)
        if dist < minDist then
            minDist = dist
            nearest = i
        end
    end
    return nearest
end

-- Функция движения по навигационным путям
function runToPoint(tox, toy, toz)
    local px, py, pz = getCharCoordinates(PLAYER_PED)
    local startIdx = findNearestWaypoint(px, py, pz)
    local endIdx = findNearestWaypoint(tox, toy, toz)

    if startIdx and endIdx then
        local direction = startIdx < endIdx and 1 or -1
        for i = startIdx, endIdx, direction do
            local wp = waypoints[i]
            local x, y, z = getCharCoordinates(PLAYER_PED)
            local angle = getHeadingFromVector2d(wp.x - x, wp.y - y)
            if getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 2 then 
                setCameraPositionUnfixed(0, math.rad(angle - 90)) 
            end
            stopRun = false
            while getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 3 do
                local tx, ty, tz = convert3DCoordsToScreen(wp.x, wp.y, wp.z)
                Draw3DCircle(wp.x, wp.y, wp.z - 0.1, 3, 0xffcc66ff)
                setGameKeyState(1, -255)
                if sprint then setGameKeyState(16, 1) end
                if autojump and getDistanceBetweenCoords2d(x, y, wp.x, wp.y) > 18.0 then 
                    local rand = math.random(0, 9999999)
                    if rand >= 9909999 then
                        setGameKeyState(16, 0)
                        setGameKeyState(14, 255)
                    end
                end
                wait(1)
                x, y, z = getCharCoordinates(PLAYER_PED)
                angle = getHeadingFromVector2d(wp.x - x, wp.y - y)
                setCameraPositionUnfixed(0, math.rad(angle - 90))
                if stopRun then
                    stopRun = false
                    return
                end
            end
        end
    end
    
    -- Финальный рывок к руде
    local x, y, z = getCharCoordinates(PLAYER_PED)
    local angle = getHeadingFromVector2d(tox - x, toy - y)
    if getDistanceBetweenCoords2d(x, y, tox, toy) > 2 then 
        setCameraPositionUnfixed(0, math.rad(angle - 90)) 
    end
    stopRun = false
    while getDistanceBetweenCoords2d(x, y, tox, toy) > 3 do
        local tx, ty, tz = convert3DCoordsToScreen(tox, toy, toz)
        Draw3DCircle(tox, toy, toz - 0.1, 3, 0xffcc66ff)
        setGameKeyState(1, -255)
        if sprint then setGameKeyState(16, 1) end
        if autojump and getDistanceBetweenCoords2d(x, y, tox, toy) > 18.0 then 
            local rand = math.random(0, 9999999)
            if rand >= 9909999 then
                setGameKeyState(16, 0)
                setGameKeyState(14, 255)
            end
        end
        wait(1)
        x, y, z = getCharCoordinates(PLAYER_PED)
        angle = getHeadingFromVector2d(tox - x, toy - y)
        setCameraPositionUnfixed(0, math.rad(angle - 90))
        if stopRun then
            stopRun = false
            break
        end
    end
end

-- Основная функция
function main()
    while not isSampAvailable() do wait(0) end
    wait(200)
    sampAddChatMessage('{cc66ff}[auto-mine]: {ffffff}Скрипт загружен! Авторы: fokichevskiy, Frolovski', -1)
    sampRegisterChatCommand('amine', function()
        WinState[0] = not WinState[0]
    end)    
    getLastUpdate()
    lua_thread.create(get_telegram_updates)
    while true do
        wait(0)
        renderRadius = RadiusSlider[0] -- Синхронизация радиуса со слайдером
        local thr1 = lua_thread.create_suspended(lookForMine)
        if mode then
            thr1:run()
            if #array > 0 then
                local res, position, dist = GetNearestCoords(array)
                if res then
                    local x, y, z = position[1], position[2], position[3]
                    local px, py, pz = getCharCoordinates(PLAYER_PED)
                    local totalMined = totalStone + totalMetal + totalSilver + totalBronze + totalGold
                    if totalMined < SliderInt[0] then
                        if not isPlayerNearOre(x, y, z, 5) then -- Проверка на игроков в радиусе 5 метров
                            if getDistanceBetweenCoords3d(px, py, pz, x, y, z) > 2 then
                                runToPoint(x, y, z) -- Используем навигационные пути
                            else
                                array = {}
                                repeat
                                    setGameKeyState(21, -256) -- Добыча
                                    wait(200)
                                    setGameKeyState(21, 0)
                                until true
                            end
                        end
                    else
                        mode = false
                        sampAddChatMessage('{cc66ff}[auto-mine]: {FFFFFF}Бот собрал заданное количество ресурсов!', -1)
                        sendTelegramNotification('Бот собрал заданное количество ресурсов')
                    end
                else
                    renderFontDrawText(fontonscreen, 'Руда не найдена', resx / 2 + 500, resy / 2, -1, false)
                end
            else
                renderFontDrawText(fontonscreen, 'Руда не найдена', resx / 2 + 500, resy / 2, -1, false)
            end
        else
            thr1:terminate()
        end
        if testCheat('amiii') then
            mode = not mode
        end
    end
end

-- Логика поиска руды
function lookForMine()
    array = {} -- Очищаем массив перед поиском
    for i = 0, 2048 do
        if sampIs3dTextDefined(i) then
            local text, color, x, y, z, distance, ignoreWalls, playerId, vehicleId = sampGet3dTextInfoById(i)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local dist = getDistanceBetweenCoords3d(myX, myY, myZ, x, y, z)
            if text:find('Месторождение ресурсов') and dist <= renderRadius then
                table.insert(array, {['position'] = {x, y, z}, ['distance'] = dist})
            end
        end
    end
    for k, v in pairs(resources) do
        local object = sampGetObjectHandleBySampId(k)
        if doesObjectExist(object) and isObjectOnScreen(object) then
            local _, ox, oy, oz = getObjectCoordinates(object)
            local myX, myY, myZ = getCharCoordinates(PLAYER_PED)
            local dist = getDistanceBetweenCoords3d(myX, myY, myZ, ox, oy, oz)
            if dist <= renderRadius then
                if (v == 1 and mineStone) or (v == 2 and mineMetal) or (v == 3 and mineSilver) or (v == 4 and mineBronze) or (v == 5 and mineGold) then
                    table.insert(array, {['position'] = {ox, oy, oz}, ['distance'] = dist})
                end
            end
        end
    end
end

function GetNearestCoords(tbl)
    if #tbl > 0 then
        table.sort(tbl, function(a, b) return a.distance < b.distance end)
        return true, tbl[1].position, tbl[1].distance
    end
    return false
end

-- Обработка событий SAMP
function sampev.onSetObjectMaterial(id, data)
    local object = sampGetObjectHandleBySampId(id)
    if doesObjectExist(object) and getObjectModel(object) == 3930 then
        if oreTextures[data.textureName] then
            resources[id] = oreTextures[data.textureName]
        end
    end
end

function sampev.onDestroyObject(id)
    if resources[id] then
        resources[id] = nil
    end
end

function sampev.onDisplayGameText(style, tm, text)
    if text == "stone + 1" then totalStone = totalStone + 1
    elseif text == "metal + 1" then totalMetal = totalMetal + 1
    elseif text == "silver + 1" then totalSilver = totalSilver + 1
    elseif text == "bronze + 1" then totalBronze = totalBronze + 1
    elseif text == "gold + 1" then totalGold = totalGold + 1
    elseif text == "stone + 2" then totalStone = totalStone + 2
    elseif text == "metal + 2" then totalMetal = totalMetal + 2
    elseif text == "silver + 2" then totalSilver = totalSilver + 2
    elseif text == "bronze + 2" then totalBronze = totalBronze + 2
    elseif text == "gold + 2" then totalGold = totalGold + 2
    end
end

function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
    if stopWithDialog then
        mode = false
        sendTelegramNotification('Администратор ответил вам в /pm: ' .. text)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function sampev.onSetPlayerPos(position)
    if stopWithSetPlayerPos then
        mode = false
        sendTelegramNotification('Сервер/Администратор изменил вашу позицию: ' .. position)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function sampev.onServerMessage(color, text)
    if stopWithChatMessage and text:find("Вы тут?") or text:find("Вы тут") or text:find("Вы здесь") or text:find("Вы здесь?") or text:find("вы тут?") or text:find("вы тут") or text:find("вы здесь") or text:find("вы здесь?") or text:find("в ы з д е с ь?") then
        mode = false
        local allchat = '\n'
        for i = 100-3, 99 do
            local getstr = select(1, sampGetChatString(i))
            allchat = allchat .. getstr .. '\n'
        end
        sendTelegramNotification('Бота спросили: вы тут?' .. allchat)
        if quitgame then os.execute('taskkill /IM gta_sa.exe /F') end
    end
end

function Draw3DCircle(x, y, z, radius, color)
    local screen_x_line_old, screen_y_line_old
    for rot = 0, 360 do
        local rot_temp = math.rad(rot)
        local lineX, lineY, lineZ = radius * math.cos(rot_temp) + x, radius * math.sin(rot_temp) + y, z
        local screen_x_line, screen_y_line = convert3DCoordsToScreen(lineX, lineY, lineZ)
        if screen_x_line ~= nil and screen_x_line_old ~= nil and isPointOnScreen(lineX, lineY, lineZ, 1) then
            renderDrawLine(screen_x_line, screen_y_line, screen_x_line_old, screen_y_line_old, 3, color)
        end
        screen_x_line_old, screen_y_line_old = screen_x_line, screen_y_line
    end
end

-- Интерфейс ImGui
imgui.OnFrame(function() return WinState[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(200, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 320), imgui.Cond.FirstUseEver)
    imgui.Begin('##amine', WinState, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse)
    imgui.SetCursorPos(imgui.ImVec2(65, 25))
    imgui.PushFont(smal)
    imgui.Text(u8'auto-mine')
    if imgui.BeginChild(u8'Настройки', imgui.ImVec2(190, 200), true) then
        imgui.PushFont(big)
        if imgui.RadioButtonBool(u8'Статус', mode) then mode = not mode end
        if imgui.RadioButtonBool(u8'Бег', sprint) then sprint = not sprint end
        if imgui.RadioButtonBool(u8'Прыжки', autojump) then autojump = not autojump end
        if imgui.RadioButtonBool(u8'Камень', mineStone) then mineStone = not mineStone end
        if imgui.RadioButtonBool(u8'Металл', mineMetal) then mineMetal = not mineMetal end
        if imgui.RadioButtonBool(u8'Серебро', mineSilver) then mineSilver = not mineSilver end
        if imgui.RadioButtonBool(u8'Бронза', mineBronze) then mineBronze = not mineBronze end
        if imgui.RadioButtonBool(u8'Золото', mineGold) then mineGold = not mineGold end
        imgui.SliderInt(u8'Радиус поиска', RadiusSlider, 10, 300) -- Исправленный слайдер
        imgui.SliderInt(u8'Цель добычи', SliderInt, 1, 10000)
        imgui.SetCursorPos(imgui.ImVec2(135, 162))
        if imgui.Button(u8'Сброс') then totalStone, totalMetal, totalSilver, totalBronze, totalGold = 0, 0, 0, 0, 0 end
        imgui.SetCursorPos(imgui.ImVec2(100, 10))
        if imgui.Button('TG') then WinTg[0] = not WinTg[0] end
        imgui.SetCursorPos(imgui.ImVec2(128, 10))
        if imgui.Button('Stats') then WinStats[0] = not WinStats[0] end
        imgui.SetCursorPos(imgui.ImVec2(100, 35))
        if imgui.Button(u8'Настройки') then WinSet[0] = not WinSet[0] end
        imgui.EndChild()
    end
    if imgui.BeginChild(u8'asd', imgui.ImVec2(190, 55), true) then
        imgui.SetCursorPos(imgui.ImVec2(12, 20))
        imgui.Text(u8'Авторы: fokich, Frolovski')
        imgui.SetCursorPos(imgui.ImVec2(122, 10))
        imgui.Text(u8'Телеграм')
        if imgui.IsItemClicked() then os.execute('explorer https://t.me/devfokich') end
        imgui.SetCursorPos(imgui.ImVec2(123, 26))
        imgui.Text(u8'BlastHack')
        if imgui.IsItemClicked() then os.execute('explorer https://www.blast.hk/threads/199063/page-6') end
        imgui.EndChild()
    end
    imgui.End()
end)

imgui.OnFrame(function() return WinSet[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(280, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinSet, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.Text(u8'Выключение')
    if imgui.RadioButtonBool(u8'при диалоге от админа', stopWithDialog) then stopWithDialog = not stopWithDialog end
    if imgui.RadioButtonBool(u8'при изменении позиции сервером', stopWithSetPlayerPos) then stopWithSetPlayerPos = not stopWithSetPlayerPos end
    if imgui.RadioButtonBool(u8'при проверке на бота в чате', stopWithChatMessage) then stopWithChatMessage = not stopWithChatMessage end
    if imgui.RadioButtonBool(u8'Выходить из игры', quitgame) then quitgame = not quitgame end
    imgui.End()
end)

imgui.OnFrame(function() return WinTg[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 200), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinTg, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.InputText(u8"Токен", tknField, 256)
    imgui.InputText(u8"User id", uIdField, 256)
    if imgui.Button(u8'Сохранить!') then
        mainIni.main.token = u8:decode(ffi.string(tknField))
        mainIni.main.userId = u8:decode(ffi.string(uIdField))
        inicfg.save(mainIni, 'autominev1.ini')
        getLastUpdate()
    end
    if imgui.Button(u8'Тестовое Сообщение') then
        sampAddChatMessage('[Telegram] Отправляю тестовое сообщение', -1)
        sendTelegramNotification('Тестовое сообщение от '..sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))))
    end
    imgui.End()
end)

imgui.OnFrame(function() return WinStats[0] end, function(player)
    imgui.SetNextWindowPos(imgui.ImVec2(500, 480), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(210, 150), imgui.Cond.FirstUseEver)
    imgui.Begin('##Window', WinStats, imgui.WindowFlags.NoResize)
    imgui.PushFont(big)
    imgui.Text(u8'Камень: ' .. totalStone)
    imgui.Text(u8'Металл: ' .. totalMetal)
    imgui.Text(u8'Серебро: ' .. totalSilver)
    imgui.Text(u8'Бронза: ' .. totalBronze)
    imgui.Text(u8'Золото: ' .. totalGold)
    imgui.Text(u8'Осталось: ' .. SliderInt[0] - (totalStone + totalMetal + totalSilver + totalBronze + totalGold))
    imgui.End()
end).HideCursor = true

imgui.OnInitialize(function()
    themeexam()
    imgui.GetIO().IniFilename = nil
    local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
    imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 14.0, nil, glyph_ranges)
    smal = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 17.0, nil, glyph_ranges)
    big = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, glyph_ranges)
end)

function themeexam()
    imgui.SwitchContext()
    local style  = imgui.GetStyle()
    local colors = style.Colors
    local clr    = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2
  
    style.WindowRounding         = 4.0
    style.WindowTitleAlign       = ImVec2(0.5, 0.5)
    style.FrameRounding          = 4.0
    style.ItemSpacing            = ImVec2(10, 5)
    style.ScrollbarSize          = 15
    style.ScrollbarRounding      = 0
    style.GrabMinSize            = 9.6
    style.GrabRounding           = 1.0
    style.WindowPadding          = ImVec2(10, 10)
    style.AntiAliasedLines       = true
    style.FramePadding           = ImVec2(5, 4)
    style.DisplayWindowPadding   = ImVec2(27, 27)
    style.DisplaySafeAreaPadding = ImVec2(5, 5)
    style.ButtonTextAlign        = ImVec2(0.5, 0.5)
    style.IndentSpacing          = 12.0
    style.Alpha                  = 1.0
  
    colors[clr.Text]                 = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]         = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]             = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.PopupBg]              = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border]               = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]         = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]              = ImVec4(0.44, 0.44, 0.44, 0.60)
    colors[clr.FrameBgHovered]       = ImVec4(0.57, 0.57, 0.57, 0.70)
    colors[clr.FrameBgActive]        = ImVec4(0.76, 0.76, 0.76, 0.80)
    colors[clr.TitleBg]              = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]        = ImVec4(0.16, 0.16, 0.16, 1.00)
    colors[clr.TitleBgCollapsed]     = ImVec4(0.00, 0.00, 0.00, 0.60)
    colors[clr.MenuBarBg]            = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]          = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]        = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]  = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]            = ImVec4(0.13, 0.75, 0.55, 0.80)
    colors[clr.SliderGrab]           = ImVec4(0.13, 0.75, 0.75, 0.80)
    colors[clr.SliderGrabActive]     = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Button]               = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.ButtonHovered]        = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.ButtonActive]         = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Header]               = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.HeaderHovered]        = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.HeaderActive]         = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.Separator]            = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.SeparatorHovered]     = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.SeparatorActive]      = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.ResizeGrip]           = ImVec4(0.13, 0.75, 0.55, 0.40)
    colors[clr.ResizeGripHovered]    = ImVec4(0.13, 0.75, 0.75, 0.60)
    colors[clr.ResizeGripActive]     = ImVec4(0.13, 0.75, 1.00, 0.80)
    colors[clr.PlotLines]            = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]     = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]        = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg]       = ImVec4(0.26, 0.59, 0.98, 0.35)
end