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


-- cl_hud.lua
-- Положи в lua/autorun/client/cl_hud.lua

local MAP_SIZE = 200
local MAP_MARGIN = 20
local WORLD_SIZE = 16384
local PANEL_GAP = 10        -- отступ между картой и инфо-панелью

-- ============ Скрытие HUD DarkRP ============
local darkrp_hooks_backup = {}

local function DisableDarkRPHUD()
    if not DarkRP then return end

    local hooks = hook.GetTable()["HUDPaint"]
    if not hooks then return end

    for name, fn in pairs(hooks) do
        if name == "MyCustomHUD" then continue end

        local isDarkRP = false

        if string.find(string.lower(name), "darkrp") then
            isDarkRP = true
        end

        if not isDarkRP and isfunction(fn) then
            local info = debug.getinfo(fn, "S")
            if info and info.short_src and string.find(string.lower(info.short_src), "darkrp") then
                isDarkRP = true
            end
        end

        if isDarkRP then
            darkrp_hooks_backup[name] = fn
            hook.Remove("HUDPaint", name)
        end
    end
end

hook.Add("InitPostEntity", "DisableDarkRPHUD", function()
    timer.Simple(1, DisableDarkRPHUD)
end)

hook.Add("OnGamemodeLoaded", "DisableDarkRPHUD_GM", function()
    timer.Simple(1, DisableDarkRPHUD)
end)

-- ============ Миникарта ============
local function DrawMinimap(x, y, w, h)
    surface.SetDrawColor(0, 0, 0, 180)
    surface.DrawRect(x, y, w, h)

    surface.SetDrawColor(255, 255, 255, 80)
    surface.DrawOutlinedRect(x, y, w, h, 1)

    local scaleX = w / WORLD_SIZE
    local scaleY = h / WORLD_SIZE

    for _, ply in ipairs(player.GetAll()) do
        if not IsValid(ply) then continue end

        local pos = ply:GetPos()
        local px = x + (pos.x + WORLD_SIZE / 2) * scaleX
        local py = y + (WORLD_SIZE / 2 - pos.y) * scaleY

        if px < x or px > x + w or py < y or py > y + h then continue end

        if ply == LocalPlayer() then
            surface.SetDrawColor(0, 255, 0, 255)
        elseif ply:Team() == LocalPlayer():Team() then
            surface.SetDrawColor(100, 150, 255, 255)
        else
            surface.SetDrawColor(255, 60, 60, 255)
        end

        surface.DrawRect(px - 2, py - 2, 4, 4)
    end
end

-- ============ HUD ============
hook.Add("HUDPaint", "MyCustomHUD", function()
    local ply = LocalPlayer()
    if not IsValid(ply) then return end

    -- Общие координаты (левый нижний угол)
    local mapX = MAP_MARGIN
    local mapY = ScrH() - MAP_SIZE - MAP_MARGIN

    -- ---------- Миникарта ----------
    DrawMinimap(mapX, mapY, MAP_SIZE, MAP_SIZE)

    -- ---------- Инфо-панель справа от карты ----------
    local boxX = mapX + MAP_SIZE + PANEL_GAP
    local boxY = mapY
    local boxW = 240
    local boxH = MAP_SIZE                -- такая же высота, как у карты

    -- Фон
    surface.SetDrawColor(0, 0, 0, 180)
    surface.DrawRect(boxX, boxY, boxW, boxH)

    -- Рамка
    surface.SetDrawColor(255, 255, 255, 80)
    surface.DrawOutlinedRect(boxX, boxY, boxW, boxH, 1)

    -- Ник
    draw.SimpleText(
        "Ник:",
        "DermaDefaultBold",
        boxX + 12, boxY + 12,
        Color(180, 180, 180),
        TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP
    )

    draw.SimpleText(
        ply:Nick(),
        "DermaDefaultBold",
        boxX + 12, boxY + 32,
        Color(255, 255, 255),
        TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP
    )

    -- Разделительная линия
    surface.SetDrawColor(255, 255, 255, 40)
    surface.DrawRect(boxX + 10, boxY + 60, boxW - 20, 1)

    -- Убийства
    draw.SimpleText(
        "Убийств:",
        "DermaDefaultBold",
        boxX + 12, boxY + 75,
        Color(180, 180, 180),
        TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP
    )

    draw.SimpleText(
        tostring(ply:GetNWInt("PersistentKills", ply:Frags())),
        "DermaDefaultBold",
        boxX + 12, boxY + 95,
        Color(255, 90, 90),
        TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP
    )
end)