Entity Takes Damage

I am scripting an entity and I want it to so some things when it takes damage. The data I need to get is the Weapon of the attacker, the attacker and the damage given.
Help appreciated :slight_smile:

For a gamemode, you can use
[lua]function GM:EntityTakeDamage(ent, wep, attacker, dmg, dmginfo)

Otherwise, [lua]hook.Add(“EntityTakeDamage”,“SomeHookNameHere”, function(ent, wep, attacker, dmg, dmginfo)

Hmm well, i’m putting it in a scripted entity.
If i put it inside init.lua, will it work or will there be like 50 of the same hook
I need to make it so that it only affects that certain entity.
(its a tree you chop down)
I used your code but if i tried to chop down a tree all the trees would be chopped down.
Im sure im using it wrong can someone help?

Oh, if it’s just one sent, try:
[lua]function ENT:OnTakeDamage( dmginfo )
local dmg = dmginfo:GetDamage()
local wep = dmginfo:GetInflictor()
local attacker = dmginfo:GetAttacker()

Thanks :slight_smile:

[editline]8th February 2012[/editline]

The GetInflictor deosnt work, i did this:
and it said
Bad argument expected string got player

Im trying to print the weapon used.


Used SendLua because GetPrintName is clientside.

Yes but I need to use it in a serverside script as well.