• npc_headcrab avoid damage from weapon_crowbar
    5 replies, posted
I just realized that weapon_crowbar damage is un avoidable :( [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 :D
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] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] [quote]Returns boolean Return true to completely block the damage event[/quote]
Sorry, you need to Log In to post a reply to this thread.