if SERVER then
util.AddNetworkString('HitInfo')
hook.Add('EntityTakeDamage', 'DMInfo', function(ent, dmginfo)
if not dmginfo:GetAttacker():IsPlayer() or dmginfo:GetDamage() <= 0 or not dmginfo:GetDamage() or ent:Health() <= 0 or ent == dmginfo:GetAttacker() then
return
end
net.Start('HitInfo')
net.WriteUInt(dmginfo:GetDamage(), 8)
-- net.WriteVector(dmginfo:GetDamagePosition()) -- Send the hit position as well
net.Send(dmginfo:GetAttacker())
end)
end
if CLIENT then
local DamageNumbers = {}
local fontName = 'DMInfo'
surface.CreateFont(fontName, {
font = 'Arial',
size = 20,
weight = 700,
antialias = true
})
net.Receive('HitInfo', function()
local damage = net.ReadUInt(8)
local hitPos = net.ReadVector()
table.insert(DamageNumbers, {
Damage = damage,
Position = hitPos,
Alpha = 200,
StartTime = CurTime()
})
end)
hook.Add('PostDrawTranslucentRenderables', 'DMInfo', function(depth, skybox)
if depth or skybox then
return
end
local eyePos = EyePos()
for i, number in ipairs(DamageNumbers) do
local pos = number.Position
local distance = eyePos:Distance(pos)
if distance <= 1000 then -- Only render numbers within a certain range
local alpha = number.Alpha
if alpha > 0 then
local timePassed = CurTime() - number.StartTime
if timePassed < 1 then
local text = tostring(number.Damage)
local font = fontName
local textColor = Color(255, 255, 255, alpha)
local textPos = pos + Vector(0, 0, 0) -- Adjust the height of the number
cam.Start3D2D(textPos, Angle(0, EyeAngles().y - 90, 90), 0.2) -- Adjust the scale of the number
draw.SimpleTextOutlined(text, font, 0, 0, textColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(0, 0, 0, alpha))
cam.End3D2D()
else
table.remove(DamageNumbers, i)
end
end
else
table.remove(DamageNumbers, i)
end
end
end)
end