TakeDamage() in EntityTakeDamage hook crashes game



hook.Add( "EntityTakeDamage", "BR:RarityScaling", function(victim,dmginfo)
local attacker = dmginfo:GetAttacker()

	if victim:IsPlayer() and attacker:IsPlayer() and attacker:GetActiveWeapon():IsValid() then
		local rarity = attacker:GetActiveWeapon():GetRarity()
	
			dmginfo:ScaleDamage( LootspawnWeaponRarities[rarity].Multipliers.Damage )
			
			attacker:ChatPrint("Default: ".. dmginfo:GetDamage() .."")
			attacker:ChatPrint("Rarity: ".. dmginfo:GetDamage()*LootspawnWeaponRarities[rarity].Multipliers.Damage .."")
			
			victim:TakeDamage(dmginfo:GetDamage()*LootspawnWeaponRarities[rarity].Multipliers.Damage,attacker)

		return true
	end

end)


This code shuts down my game instantly and the only thing I know is that its the victim:TakeDamage() that is causing it. The reason why im trying to run TakeDamage in there is because ScaleDamage is doing absolutely nothing at all for some reason even if the “LootspawnWeaponRarities[rarity].Multipliers.Damage” is 10.

Any ideas on what I should/could do about this? I tried using ScalePlayerDamage but the ScaleDamage didnt work there either and it overwrote the default hitgroup scaling.

That’s because the loop is running infinitely. Calling TakeDamage will re-call EntityTakeDamage and will crash from the C-stack overflowing.

[editline]27th September 2017[/editline]

ScaleDamage should work fine if you don’t return true.

Ah, that makes alot of sense.

Also it doesn’t, I have tried.

Make sure your scale number actually has a value.
if you scale by a non-number it will break your dmginfo, but i think that would also throw an error somewhere.

i guess you could try dmginfo:SetDamage( dmginfo:GetDamage() * scale ) and see if that works?

…ScaleDamage is doing absolutely nothing at all for some reason even if the “LootspawnWeaponRarities[rarity].Multipliers.Damage” is 10…

Also, just like all my other problems, restarting the game fixes it.

So restarting the game fixes ScaleDamage? Check your addons to see if it overrides CTakeDamageInfo.ScaleDamage.