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


script_name("Arizona Hunger & Armor Bar")
script_author("AI Collaborator")
script_version("1.1")

local imgui = require 'imgui'
local sampevents = require 'lib.samp.events'

-- Переменные показателей (0 - 100%)
local hungerPercent = 100 
local armorPercent = 100

local main_window_state = imgui.ImBool(true)

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    while true do
        wait(200) -- частота обновления данных
        
        -- Получаем текущий уровень брони персонажа
        if isCharInAnyCar(PLAYER_PED) then
            local result, ped = statGetAttribute(PLAYER_PED)
        end
        local result, armor = sampGetPlayerArmor(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
        if result then
            armorPercent = armor
        else
            -- Запасной метод получения брони прямо из педа
            armorPercent = getCharArmour(PLAYER_PED)
        end
        
        -- При необходимости здесь можно обновлять hungerPercent
    end
end

imgui.OnFrame(function() return main_window_state.v end, function()
    -- Начальное положение на экране (можно перетаскивать мышкой)
    imgui.SetNextWindowPos(imgui.ImVec2(300, 50), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(220, 80), imgui.Cond.Always)
    
    imgui.Begin("HudOverlayWindow", main_window_state, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoScrollbar + imgui.WindowFlags.NoBackground)
    
    local drawList = imgui.GetWindowDrawList()
    local pos = imgui.GetCursorScreenPos()
    
    -- Размеры индикаторов
    local width = 200
    local height = 22
    local spacing = 8 -- расстояние между полосками
    
    --------------------------------------------------------
    -- 1. ИНДИКАТОР ГОЛОДА (Желтый)
    --------------------------------------------------------
    local hungerFactor = math.max(0, math.min(100, hungerPercent)) / 100.0
    
    -- Фон / Черная обводка
    drawList:AddRectFilled(pos, imgui.ImVec2(pos.x + width, pos.y + height), imgui.GetColorU32(imgui.ImVec4(0, 0, 0, 1.0)), 4.0)
    
    -- Заполнение (Желтый цвет)
    local fillHungerWidth = (width - 4) * hungerFactor
    if fillHungerWidth > 0 then
        drawList:AddRectFilled(
            imgui.ImVec2(pos.x + 2, pos.y + 2), 
            imgui.ImVec2(pos.x + 2 + fillHungerWidth, pos.y + height - 2), 
            imgui.GetColorU32(imgui.ImVec4(0.95, 0.75, 0.0, 1.0)), 
            3.0
        )
    end
    
    -- Текст голода
    local hungerText = string.format("Голод: %d%%", hungerPercent)
    local textSize1 = imgui.CalcTextSize(hungerText)
    local textX1 = pos.x + (width - textSize1.x) * 0.5
    local textY1 = pos.y + (height - textSize1.y) * 0.5
    
    -- Тень текста и сам белый текст
    drawList:AddText(imgui.ImVec2(textX1 + 1, textY1 + 1), imgui.GetColorU32(imgui.ImVec4(0, 0, 0, 0.9)), hungerText)
    drawList:AddText(imgui.ImVec2(textX1, textY1), imgui.GetColorU32(imgui.ImVec4(1, 1, 1, 1.0)), hungerText)

    --------------------------------------------------------
    -- 2. ИНДИКАТОР БРОНИ (Синий/Голубой)
    --------------------------------------------------------
    local armorPosY = pos.y + height + spacing
    local armorFactor = math.max(0, math.min(100, armorPercent)) / 100.0
    
    -- Фон / Черная обводка
    drawList:AddRectFilled(imgui.ImVec2(pos.x, armorPosY), imgui.ImVec2(pos.x + width, armorPosY + height), imgui.GetColorU32(imgui.ImVec4(0, 0, 0, 1.0)), 4.0)
    
    -- Заполнение (Сине-голубой цвет брони)
    local fillArmorWidth = (width - 4) * armorFactor
    if fillArmorWidth > 0 then
        drawList:AddRectFilled(
            imgui.ImVec2(pos.x + 2, armorPosY + 2), 
            imgui.ImVec2(pos.x + 2 + fillArmorWidth, armorPosY + height - 2), 
            imgui.GetColorU32(imgui.ImVec4(0.2, 0.6, 0.95, 1.0)), 
            3.0
        )
    end
    
    -- Текст брони
    local armorText = string.format("Броня: %d%%", armorPercent)
    local textSize2 = imgui.CalcTextSize(armorText)
    local textX2 = pos.x + (width - textSize2.x) * 0.5
    local textY2 = armorPosY + (height - textSize2.y) * 0.5
    
    -- Тень текста и сам белый текст
    drawList:AddText(imgui.ImVec2(textX2 + 1, textY2 + 1), imgui.GetColorU32(imgui.ImVec4(0, 0, 0, 0.9)), armorText)
    drawList:AddText(imgui.ImVec2(textX2, textY2), imgui.GetColorU32(imgui.ImVec4(1, 1, 1, 1.0)), armorText)

    imgui.End()
end)