How to get the hitgroup from a DamageInfo object?

As the title says. I need the hitgroup for the following code; can I get it from the DamageInfo or do I need to use some other method?

function ENT:OnTakeDamage( dmginfo )

local health = self:Health()
local dmg = GAMEMODE:ScaleNPCDamage( self, /*   hitgroup here   */, dmginfo )

health = health - dmg:GetDamage()
self:SetHealth( health )


You can’t get it from the DamageInfo object.

However, you should be able to get the damage group by doing something like this:

[lua]function GetHitGroup(dmg)
local atk = dmg:GetAttacker()
local pos = dmg:GetDamagePosition()
local opos = atk:GetPos()
if atk:IsPlayer() then opos = atk:GetShootPos() end

local tr = util.TraceLine({start=opos,endpos=pos,filter=atk})
return tr.HitGroup

Not perfect, but it’s just a thrown together piece of psuedocode - you get the idea.

For players and NPCs you can use **[Gamemode.ScaleNPCDamage](** and **[Gamemode.ScalePlayerDamage](**.

Managed to get it working after a bit of fiddling, thanks all.

local health = self:Health()
local attacker = dmginfo:GetAttacker()
local hitgroup
if ( attacker:IsPlayer() && dmginfo:IsBulletDamage() ) then
        // hack: get hitgroup
	local trace = {}
	trace.start = attacker:GetShootPos()
	// GetDamagePosition is just outside of the NPC's bounding box so we have to extend it
	trace.endpos = trace.start + ( ( dmginfo:GetDamagePosition() - trace.start ) * 2 )  
	trace.mask = MASK_SHOT
	trace.filter = attacker
	local tr = util.TraceLine( trace )
	hitgroup = tr.HitGroup

	assert( tr.Entity == self, "Invalid trace" )
	GAMEMODE:ScaleNPCDamage( self, hitgroup, dmginfo )