You are on page 1of 1

function DrawPlayerInfo(ply)

if not ply:Alive() then return end

local pos = ply:EyePos()


pos.z = pos.z + 10

local ang = ply:EyeAngles()


ang.p = 0
ang.y = ang.y + 90
ang.r = 90

local health = ply:Health()


local max_health = ply:GetMaxHealth()
local health_percent = health / max_health

local health_color = Color(0, 255, 0) -- default color is green


if health_percent < 0.3 then
health_color = Color(255, 0, 0) -- health is low, change color to red
end

cam.Start3D2D(pos, ang, 0.1)


draw.DrawText(ply:Nick(), "TargetID", 2, -45, Color(255, 255, 255, 255),
TEXT_ALIGN_CENTER)
draw.DrawText("Health: " .. health, "TargetID", 2, -30, health_color,
TEXT_ALIGN_CENTER)
cam.End3D2D()
end

hook.Add("PostDrawOpaqueRenderables", "DrawPlayerInfo", function()


for _, ply in ipairs(player.GetAll()) do
if ply ~= LocalPlayer() then
DrawPlayerInfo(ply)
end
end
end)

You might also like