Crash with NPC:TakeDamageInfo()

Does anybody else experience a crash when running NPC:TakeDamageInfo( dmginfo ) ?

Just curious.

Yes, except I get it with Players.

PLAYER:TakeDamageInfo(dmginfo)

[editline]18th July 2013[/editline]

I honestly thought I was doing something wrong, so fell back to TakeDamage()

I have experienced this too, I can’t tell you what exactly causes the crash, but try playing around with the arguments in this function. ( damage, damage type, etc )

It doesn’t make any dmp files my end either.

The reason for the crash (although it should be handled as a lua error rather than bringing everything down!) is not supplying the attacker I think. Luckily you can just set the attacker to itself and you’ll get a generic death message for the NPC.

This should work, replace the numbers with your own:



	if IsValid( ent ) then
		local d = DamageInfo()
		d:SetDamage( 123 )
		d:SetDamageType( DMG_whatever )
		d:SetInflictor( ent )
		d:SetAttacker( ent )
		ent:TakeDamageInfo( d )
	end