I found a problem with the one I posted earlier. Here is a fix, I’ve also changed the font size and colour.
[lua]if SERVER then
hook.Add(“EntityTakeDamage”, “FloatingDamage”, function(ent, inflictor, attacker, amount, dmginfo)
if attacker:IsPlayer() then
umsg.Start(“Floating Damage”, attacker);
umsg.Short(amount);
umsg.Vector(ent:LocalToWorld(ent:OBBCenter()));
umsg.End();
end
end);
else
local Floats = {};
usermessage.Hook(“Floating Damage”, function(um)
local dmg = um:ReadShort();
local pos = um:ReadVector();
local off = {x=math.random(-50, 50), y=math.random(-50, 50)};
local time = math.random(1, 3);
table.insert(Floats, {Damage = dmg, Position = pos, Offset = off, Time = time, StartTime = CurTime()});
end);
hook.Add("Initialize", "CreateFont", function()
surface.CreateFont("coolvetica", ScreenScale(12), 400, true, false, "CV12Scaled");
end);
hook.Add("HUDPaint", "DrawFloatingDamage", function()
for i, fl in ipairs(Floats) do
local frac = (CurTime() - fl.StartTime) / fl.Time;
local alpha = frac * 255;
local pos = fl.Position:ToScreen();
pos.x = pos.x + fl.Offset.x;
pos.y = pos.y + fl.Offset.y;
draw.SimpleText("-"..fl.Damage, "CV12Scaled", pos.x, pos.y - frac*100, Color(255, 0, 0, 255 - alpha), 1, 1);
if CurTime() >= fl.StartTime + fl.Time - 0.05 then
table.remove(Floats, i);
end
end
end);
end[/lua]
[editline]02:46PM[/editline]
I thought I would make a video for it: