Загрузка данных
-- chat.lua
-- Кастомный HUD чата для kdm1eHvH
-- ============================================================
-- Скрываем стандартный чат GMod
-- ============================================================
hook.Add("HUDShouldDraw", "HideDefaultChat", function(name)
if name == "CHudChat" then return false end
end)
-- ============================================================
-- Настройки
-- ============================================================
local MAX_MESSAGES = 9
local FADE_TIME = 5
local FADE_OUT = 1
local LINE_HEIGHT = 26
local BOX_WIDTH = 560
local MARGIN_X = 20
local MARGIN_Y = 20
local ACCENT = Color(220, 40, 40)
local BG = Color(10, 10, 15, 220)
local TEXT = Color(235, 235, 235)
local RANK_LIST = {
["user"] = { color = Color(180, 180, 180), name = "User" },
["beta_tester"] = { color = Color(80, 220, 220), name = "Beta Tester" },
["vip"] = { color = Color(255, 200, 50), name = "VIP" },
["moderator"] = { color = Color(80, 150, 255), name = "Moderator" },
["admin"] = { color = Color(255, 70, 70), name = "Admin" },
["senior_admin"] = { color = Color(200, 30, 30), name = "Senior Admin" },
["manager"] = { color = Color(180, 80, 255), name = "Manager" },
["superadmin"] = { color = Color(255, 130, 0), name = "Superadmin" },
}
surface.CreateFont("chat_hud_text", { font = "Montserrat", size = 17, weight = 500, extended = true })
surface.CreateFont("chat_hud_bold", { font = "Montserrat", size = 17, weight = 800, extended = true })
-- ============================================================
-- Хранилище
-- ============================================================
local messages = {}
local lastMessageTime = 0
local function AddMessage(data)
table.insert(messages, data)
while #messages > MAX_MESSAGES do
table.remove(messages, 1)
end
lastMessageTime = CurTime()
end
-- ============================================================
-- Перехват чата игроков
-- ============================================================
hook.Add("OnPlayerChat", "ChatHUD_kdm1eHvH", function(ply, text, team, dead)
if not IsValid(ply) then return end
if string.sub(text, 1, 1) == "/" or string.sub(text, 1, 1) == "!" then return end
local rank = ply:GetNWString("kdm1e_Rank", "user")
local rankData = RANK_LIST[rank] or RANK_LIST["user"]
AddMessage({
type = "player",
nick = ply:Nick(),
text = text,
rankName = (rank ~= "user") and rankData.name or nil,
rankColor = rankData.color,
})
return true
end)
-- ============================================================
-- Отрисовка
-- ============================================================
local function DrawChat()
if #messages == 0 then return end
local now = CurTime()
local since = now - lastMessageTime
if since > FADE_TIME + FADE_OUT then
messages = {}
return
end
local alpha = 255
if since > FADE_TIME then
alpha = 255 * (1 - (since - FADE_TIME) / FADE_OUT)
end
local count = #messages
local totalH = count * LINE_HEIGHT + 16
local startY = ScrH() - MARGIN_Y - totalH
local startX = MARGIN_X
surface.SetDrawColor(BG.r, BG.g, BG.b, BG.a * (alpha / 255))
surface.DrawRect(startX, startY, BOX_WIDTH, totalH)
surface.SetDrawColor(ACCENT.r, ACCENT.g, ACCENT.b, alpha)
surface.DrawRect(startX, startY, 3, totalH)
for i, msg in ipairs(messages) do
local y = startY + 8 + (i - 1) * LINE_HEIGHT
if msg.type == "player" then
local x = startX + 14
if msg.rankName then
local prefix = "[" .. msg.rankName .. "] "
local pc = Color(msg.rankColor.r, msg.rankColor.g, msg.rankColor.b, alpha)
surface.SetFont("chat_hud_bold")
draw.SimpleText(prefix, "chat_hud_bold", x, y, pc, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
x = x + surface.GetTextSize(prefix)
end
local nickText = msg.nick .. ": "
surface.SetFont("chat_hud_bold")
draw.SimpleText(nickText, "chat_hud_bold", x, y, Color(255, 255, 255, alpha), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
x = x + surface.GetTextSize(nickText)
surface.SetFont("chat_hud_text")
draw.SimpleText(msg.text, "chat_hud_text", x, y, Color(TEXT.r, TEXT.g, TEXT.b, alpha), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end
end
end
hook.Add("HUDPaint", "ChatHUD_kdm1eHvH_Draw", DrawChat)
print("[ChatHUD] Кастомный чат загружен")