Всем привет! Я недавно начал изучать GLUA и хочу услышать ваше мнение. Пытаюсь сделать что-то своё, пока что получается только простое, и хотел бы услышать оценочное суждение.
--[[-------------------------------------------------------------------------
Основные настройки HUD
---------------------------------------------------------------------------]]
local CONFIG = {
FONTS = {
TITLE = {
name = "ServerTitle",
size = 32,
weight = 800
},
HUD_LARGE = {
name = "HUD_Large",
size = 26,
weight = 600
},
HUD_NORMAL = {
name = "HUD_Normal",
size = 22,
weight = 500
},
HUD_SMALL = {
name = "HUD_Small",
size = 18,
weight = 400
},
PLAYER_INFO = {
name = "PlayerInfo",
size = 46,
weight = 500
},
PLAYER_WANTED = {
name = "PlayerWanted",
size = 24,
weight = 700
},
LOCKDOWN = {
name = "LockdownFont",
size = 36,
weight = 800
}
},
ICONS = {
HEALTH = Material("icon16/heart.png"),
ARMOR = Material("icon16/shield.png"),
MONEY = Material("icon16/money.png"),
JOB = Material("icon16/user_suit.png"),
AMMO = Material("icon16/bullet_black.png"),
HUNGER = Material("icon16/cake.png")
},
COLORS = {
HEALTH = {Color(220, 50, 50), Color(255, 100, 100)},
ARMOR = {Color(50, 100, 220), Color(100, 150, 255)},
HUNGER = {Color(255, 165, 0), Color(255, 200, 0)},
WANTED = Color(255, 50, 50),
MONEY = Color(100, 255, 100)
}
}
--[[-------------------------------------------------------------------------
Инициализация шрифтов
---------------------------------------------------------------------------]]
local function InitializeFonts()
for _, fontData in pairs(CONFIG.FONTS) do
surface.CreateFont(fontData.name, {
font = "Roboto",
size = fontData.size,
weight = fontData.weight,
antialias = true,
shadow = true,
blursize = fontData.blursize or 0
})
end
end
InitializeFonts()
--[[-------------------------------------------------------------------------
Отключение стандартного HUD
---------------------------------------------------------------------------]]
hook.Add("HUDShouldDraw", "HideDefaultHUD", function(name)
local hide = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true,
["DarkRP_HUD"] = true,
["DarkRP_EntityDisplay"] = true,
["DarkRP_LocalPlayerHUD"] = true,
["DarkRP_Hungermod"] = true,
["DarkRP_Agenda"] = true
}
if hide[name] then return false end
end)
hook.Add("InitPostEntity", "DisableDarkRPHUD", function()
if DarkRP then
DarkRP.disabledDefaults = DarkRP.disabledDefaults or {}
DarkRP.disabledDefaults["HUD"] = true
DarkRP.disabledDefaults["localPlayerHUD"] = true
end
end)
--[[-------------------------------------------------------------------------
Вспомогательные функции
---------------------------------------------------------------------------]]
-- Анимированные значения
local smoothValues = {
health = 100,
armor = 0,
money = 0,
hunger = 100
}
-- Радужный цвет
local function RainbowColor(offset)
local time = CurTime() * 50
local hue = (time + (offset or 0)) % 360
return HSVToColor(hue, 1, 1)
end
-- Полоска
local function DrawBar(x, y, w, h, value, maxValue, colors, icon, text, glow)
local progress = math.Clamp(value / maxValue, 0, 1)
local barWidth = w * progress
-- Фон
surface.SetDrawColor(0, 0, 0, 100)
surface.DrawRect(x, y, w, h)
-- Градиент полоски
local segments = 10
local segmentWidth = barWidth / segments
for i = 0, segments - 1 do
local alpha = 155 + (100 * (i / segments))
local segX = x + (i * segmentWidth)
surface.SetDrawColor(colors[1].r, colors[1].g, colors[1].b, alpha)
surface.DrawRect(segX, y, segmentWidth, h)
end
-- Блик
surface.SetDrawColor(255, 255, 255, 20)
surface.DrawRect(x, y, barWidth, h/2)
if glow and value < 30 then
local pulse = math.abs(math.sin(CurTime() * 4))
surface.SetDrawColor(colors[1].r, colors[1].g, colors[1].b, 20 + (20 * pulse))
surface.DrawRect(x - 2, y - 2, w + 4, h + 4)
end
-- Иконка
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(icon)
surface.DrawTexturedRect(x - 20, y + (h/2) - 8, 16, 16)
-- Текст
draw.SimpleText(text, CONFIG.FONTS.HUD_NORMAL.name, x + w + 10, y + (h/2), Color(255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end
local function DrawIconText(x, y, icon, text, color)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetMaterial(icon)
surface.DrawTexturedRect(x, y + 2, 16, 16)
draw.SimpleText(text, CONFIG.FONTS.HUD_NORMAL.name, x + 24, y, color or Color(255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end
--[[-------------------------------------------------------------------------
Основной HUD
---------------------------------------------------------------------------]]
hook.Add("HUDPaint", "DrawCustomHUD", function()
local ply = LocalPlayer()
if not IsValid(ply) then return end
local screenW, screenH = ScrW(), ScrH()
-- Название сервера
local titleX, titleY = 20, 20
local serverName, serverNumber = "TestRP", "#1"
-- Тень названия
draw.SimpleText(serverName, CONFIG.FONTS.TITLE.name, titleX + 2, titleY + 2, Color(0, 0, 0, 100), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText(serverNumber, CONFIG.FONTS.TITLE.name, titleX + 2 + surface.GetTextSize(serverName .. " "), titleY + 2, Color(0, 0, 0, 100), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
-- Градиент
local color1 = RainbowColor(0)
local color2 = RainbowColor(180)
draw.SimpleText(serverName, CONFIG.FONTS.TITLE.name, titleX, titleY, color1, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
draw.SimpleText(serverNumber, CONFIG.FONTS.TITLE.name, titleX + surface.GetTextSize(serverName .. " "), titleY, color2, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
-- Комендантский час
if GetGlobalBool("DarkRP_LockDown") then
local reason = GetGlobalString("DarkRP_LockdownReason", "Не указана")
local text = "ИДЕТ КОМЕНДАНТСКИЙ ЧАС!!!"
-- Радужный текст
local textW = surface.GetTextSize(text)
local chars = string.ToTable(text)
local x = screenW/2 - textW/2
for i, char in ipairs(chars) do
local color = RainbowColor(i * 10)
draw.SimpleText(char, CONFIG.FONTS.LOCKDOWN.name, x, 50, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
x = x + surface.GetTextSize(char)
end
-- Причина
draw.SimpleText("ПРИЧИНА: " .. reason, CONFIG.FONTS.HUD_LARGE.name, screenW/2, 100, Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
end
-- Параметры HUD
local mainX = 20
local baseY = screenH - 120
local barW = 200
local barH = 8
local spacing = 30
local currentY = baseY
-- Розыск
if ply:getDarkRPVar("wanted") then
local wantedReason = ply:getDarkRPVar("wantedReason") or "Не указана"
-- Тень
draw.SimpleText("ВЫ В РОЗЫСКЕ", CONFIG.FONTS.HUD_LARGE.name, mainX + 24, currentY - 50, Color(0, 0, 0, 100), TEXT_ALIGN_LEFT)
draw.SimpleText("Причина: " .. wantedReason, CONFIG.FONTS.HUD_NORMAL.name, mainX + 24, currentY - 25, Color(0, 0, 0, 100), TEXT_ALIGN_LEFT)
-- Текст
local pulse = math.abs(math.sin(CurTime() * 3)) * 55 + 200
draw.SimpleText("ВЫ В РОЗЫСКЕ", CONFIG.FONTS.HUD_LARGE.name, mainX + 24, currentY - 50, Color(255, pulse, pulse), TEXT_ALIGN_LEFT)
draw.SimpleText("Причина: " .. wantedReason, CONFIG.FONTS.HUD_NORMAL.name, mainX + 24, currentY - 25, Color(255, 100, 100), TEXT_ALIGN_LEFT)
end
-- Здоровье
smoothValues.health = Lerp(FrameTime() * 5, smoothValues.health, ply:Health())
DrawBar(mainX + 24, currentY, barW, barH, smoothValues.health, 100, CONFIG.COLORS.HEALTH, CONFIG.ICONS.HEALTH, math.Round(smoothValues.health) .. "HP", true)
currentY = currentY + spacing
-- Броня
local armor = ply:Armor()
if armor > 0 then
smoothValues.armor = Lerp(FrameTime() * 5, smoothValues.armor, armor)
DrawBar(mainX + 24, currentY, barW, barH, smoothValues.armor, 100, CONFIG.COLORS.ARMOR, CONFIG.ICONS.ARMOR, math.Round(smoothValues.armor) .. "%", false)
currentY = currentY + spacing
end
if DarkRP then
-- Деньги
local money = ply:getDarkRPVar("money") or 0
smoothValues.money = Lerp(FrameTime() * 3, smoothValues.money, money)
DrawIconText(mainX + 4, currentY, CONFIG.ICONS.MONEY, DarkRP.formatMoney(math.Round(smoothValues.money)), CONFIG.COLORS.MONEY)
currentY = currentY + spacing
-- Профессия
DrawIconText(mainX + 4, currentY, CONFIG.ICONS.JOB, team.GetName(ply:Team()), team.GetColor(ply:Team()))
currentY = currentY + spacing
-- Голод
local hunger = ply:getDarkRPVar("Energy") or 100
smoothValues.hunger = Lerp(FrameTime() * 3, smoothValues.hunger, hunger)
DrawBar(mainX + 24, currentY, barW, barH, smoothValues.hunger, 100, CONFIG.COLORS.HUNGER, CONFIG.ICONS.HUNGER, math.Round(smoothValues.hunger) .. "%", true)
end
-- Патроны
local weapon = ply:GetActiveWeapon()
if IsValid(weapon) then
local clip1 = weapon:Clip1()
local ammo1 = ply:GetAmmoCount(weapon:GetPrimaryAmmoType())
if clip1 > -1 then
DrawIconText(screenW - 120, screenH - 40, CONFIG.ICONS.AMMO, clip1 .. " / " .. ammo1, Color(255, 255, 255))
end
end
end)
--[[-------------------------------------------------------------------------
Отображение информации над головами игроков
---------------------------------------------------------------------------]]
hook.Add("PostDrawTranslucentRenderables", "DrawPlayerInfo", function()
local ply = LocalPlayer()
for _, target in pairs(player.GetAll()) do
if not IsValid(target) or not target:Alive() or target == ply then continue end
local pos = target:GetPos() + Vector(0, 0, target:OBBMaxs().z + 10)
local ang = EyeAngles()
ang:RotateAroundAxis(ang:Up(), -90)
ang:RotateAroundAxis(ang:Forward(), 90)
local distance = ply:GetPos():Distance(target:GetPos())
if distance > 1000 then continue end
local alpha = math.Clamp(255 - (distance / 1000) * 255, 0, 255)
cam.Start3D2D(pos, ang, 0.1)
local totalHeight = -20
local spacing = 40
-- Розыск
if target:getDarkRPVar("wanted") then
draw.SimpleText("РОЗЫСК", CONFIG.FONTS.PLAYER_WANTED.name, 0, totalHeight, CONFIG.COLORS.WANTED, TEXT_ALIGN_CENTER)
totalHeight = totalHeight + spacing
end
-- Ник
draw.SimpleText(target:Nick(), CONFIG.FONTS.PLAYER_INFO.name, 0, totalHeight, Color(255, 255, 255, alpha), TEXT_ALIGN_CENTER)
totalHeight = totalHeight + spacing
-- Профессия
local jobColor = table.Copy(team.GetColor(target:Team()))
jobColor.a = alpha
draw.SimpleText(team.GetName(target:Team()), CONFIG.FONTS.PLAYER_INFO.name, 0, totalHeight, jobColor, TEXT_ALIGN_CENTER)
cam.End3D2D()
end
end)