How can you make text appear (to indicate dmg)

It’s hard to explain, but it’s basically this: Player one shoots player two and hurts him for 24 damage. The number 24 appears above player two’s head and slowly fades away. I’m not asking for code, so much as a point in the right direction. All I could use for this is, if it exists, a function to draw it. Not even necessarily a function. I understand that draw probably wont work, but I’m a bit limited on thoughts at the moment.

Can someone assist? Thank you. - Dan

Look at ply:GetEyeTrace() and draw.SimpleTextOutlined as well at ToScreen

I know you said you didn’t want the code written for you, but I made this a while a go and it does what you want.

[lua]if SERVER then

hook.Add("EntityTakeDamage", "FloatingDamage", function(ent, inflictor, attacker, amount, dmginfo)
	if attacker:IsPlayer() then
		umsg.Start("Floating Damage", attacker);


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() } );

hook.Add("Initialize", "CreateFont", function()
	surface.CreateFont("coolvetica", ScreenScale(12), 400, true, false, "CV12Scaled");

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);


Put it garrysmod/lua/autorun/damage.lua

Thank you guys, I’ll post back if I have any problems. It’s not that that code isn’t welcome, I thank you for it, I just didn’t want to sound … as if I was asking for too much. If you know what I mean. Thank you, again.