npc_headcrab avoid damage from weapon_crowbar

I just realized that weapon_crowbar damage is un avoidable :frowning:

[LUA]
function GM:EntityTakeDamage(ent,dmg) --inflictor, attacker, amount, dmgInfo)
dmgtype = dmg:GetDamageType()
attacker = dmg:GetAttacker()
inflictor = dmg:GetInflictor()

if IsValid(ent) and
IsValid(attacker) and
attacker:IsPlayer() and
ent:IsPet()
then
	print("NO DAMAGE TAKE TO PET BY PLAYER")
	--print("SET DAMAGE TO 10")
	dmg:SetDamage(0)
end

end
[/LUA]

my ent:IsPet() function just check out if the pet is a pet like check in the entity metatable. If the entity has an owner then it is a pet. Then it will be return true.

Does it print?

if not I would not post that :smiley:

So wait, why arenโ€™t you returning true?

as I said it print in console so it is working. But npc_headcrab still get one shooted by weapon_crowbar. But my npc_headcrab is IsPet(). So it returns as true. Problem is dunno what the hell kill my headcrab.

[LUA]
function GM:EntityTakeDamage(ent,dmg) --inflictor, attacker, amount, dmgInfo)
dmgtype = dmg:GetDamageType()
attacker = dmg:GetAttacker()
inflictor = dmg:GetInflictor()

if IsValid(ent) and
IsValid(attacker) and
attacker:IsPlayer() and
ent:IsPet()
then
	print("NO DAMAGE TAKE TO PET BY PLAYER")

	-- tried doing this?
	return true	-- <------------------------------------------------------------------
end

end
[/LUA]

GM:EntityTakeDamage