Code:
local function _IsValid(v)
return (v != LocalPlayer() && IsValid(v) && v:Alive() && v:Health() > 0 && !v:IsDormant());
end
local function Get2DBounds(v)
local min,max = v:OBBMins(),v:OBBMaxs()
local corners = {
Vector(min.x,min.y,min.z),
Vector(min.x,min.y,max.z),
Vector(min.x,max.y,min.z),
Vector(min.x,max.y,max.z),
Vector(max.x,min.y,min.z),
Vector(max.x,min.y,max.z),
Vector(max.x,max.y,min.z),
Vector(max.x,max.y,max.z)
}
local minx,miny,maxx,maxy = math.huge, math.huge, -math.huge, -math.huge;
for _, corner in next, corners do
local screen = v:LocalToWorld(corner):ToScreen();
minx,miny = math.min(minx,screen.x),math.min(miny,screen.y);
maxx,maxy = math.max(maxx,screen.x),math.max(maxy,screen.y);
end
return minx,miny,maxx,maxy;
end
local function FamiHealthbar()
for k,v in next, player.GetAll() do
if (_IsValid(v)) then
local x1,y1,x2,y2 = Get2DBounds(v);
local color = team.GetColor(v:Team());
local diff = math.abs(x2 - x1);
local diff2 = math.abs(y2 - y1);
/*
FILLED BOX
*/
surface.SetDrawColor(Color(color.r,color.g,color.b,50))
surface.DrawRect(x1,y1,diff,diff2)
/*
BOX
*/
surface.SetDrawColor(5,5,5)
surface.DrawOutlinedRect(x1-1,y1-1,diff+2,diff2+2)
surface.DrawOutlinedRect(x1+1,y1+1,diff-2,diff2-2)
surface.SetDrawColor(color)
surface.DrawOutlinedRect(x1,y1,diff,diff2)
/*
HEALTHBAR
*/
surface.SetDrawColor(color)
surface.DrawRect(x1-5, y1,3,diff2-2)
surface.SetDrawColor(5,5,5)
surface.DrawLine(x1-4, y1+1,x1-4,y2-1)
surface.SetDrawColor(255 - 2.55 * v:Health(), 2.55 * v:Health(),0)
surface.DrawRect(x1-5, y2-(diff2/100 * v:Health()),3,diff2/100*(v:Health()))
surface.SetDrawColor(5,5,5)
surface.DrawOutlinedRect(x1-6, y1-1,5,diff2+2)
end
end
end
GAMEMODE["HUDPaint"] = function()
FamiHealthbar()
end