Damage Text

Damage text addon, if anyone could make.

:effort:

Here you go, I made this a while ago.

[lua]if SERVER then

AddCSLuaFile("autorun/damage.lua");

hook.Add("EntityTakeDamage", "FloatingDamage", function(ent, inflictor, attacker, amount, dmginfo)
	if attacker:IsPlayer() then
		umsg.Start("Floating Damage", attacker);
			umsg.Short(amount);
			umsg.Vector(dmginfo:GetDamagePosition());
		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]

Yea I know, but he could have put a little more effort into the thread, imo…

OP = You heard the title, cough up the code.

Thank you for the code. But where do you put it? I can’t seem to make it work

garrysmod/lua/autorun/damage.lua

Sorry I should have said that before.

What do you mean by Damage Text?
Explain please, I want to see what it is and not add some random thing to my garrysmod.

Why not try reading the thread?

The code I posted does this:

The box around the entities is something else.

[editline]10:24AM[/editline]

I have updated the code since that video, the text now comes from where the bullet hit, not the center of the entity.

Borderlands style :stuck_out_tongue:

or TF2

Definitely TF2

Sorry for the Necro bump, but I have become interested in this code and there would be no point in making a new one. :stuck_out_tongue:

Anyways, I don’t think this particular code works for Gmod anymore. It gives errors stating that there is a ‘)’ missing near “highlight”. Have there been some internal changes in gmod that would cause this to happen? Or am I just stupid? XD

I dont see any highlight in that code

Looks like someone ninja-fixed the code since I bumped this back up. TY btw, code works wonderfully.

I really hope you don’t mind me adding onto this.




if SERVER then

    AddCSLuaFile("autorun/damage.lua");

    function DefineHitGroup(ent, hitgroup, dmginfo)
local GroupNames = {"Head", "Chest", "Stomach", "Left Arm", "Right Arm", "Left Leg", "Right Leg", "Gear", "General Body"};
local AmHitHere = "";
    if(hitgroup == 8) or (hitgroup == 9) then return; end
        if(hitgroup == 0) then
            AmHitHere = GroupNames[9];
            ent:SetNWString("hitgroup", AmHitHere);
            return;
        end
    AmHitHere = GroupNames[hitgroup];
    ent:SetNWString("hitgroup", AmHitHere);
end
hook.Add("ScaleNPCDamage", "HitGroupGet_NPC", DefineHitGroup);
hook.Add("ScalePlayerDamage", "HitGroupGet_Ply", DefineHitGroup);

    hook.Add("EntityTakeDamage", "FloatingDamage", function(ent, inflictor, attacker, amount, dmginfo)
        if attacker:IsPlayer() then
            umsg.Start("Floating Damage", attacker);
                umsg.Short(amount);
                umsg.Vector(dmginfo:GetDamagePosition());
                umsg.String(ent:GetNWString("hitgroup"));
            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);
        local str = um:ReadString();
        table.insert(Floats, { Damage = dmg, Position = pos, Offset = off, Time = time, StartTime = CurTime(), HitPos = str } );
    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.. " " fl.HitGroup, "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