I’m trying to use EntityTakeDamage hook.

hook.Add("EntityTakeDamage", "EntityTakeDamage",  playerHurtSound )

local function playerHurtSound

     local health = ent:Health()


Lets say I have 100 health, and I get damaged for 10, the above would print 100. Then if I get damaged again for 10 health, it would print 90. It seems to print the health before you get damaged.

So I tried doing

hook.Add("EntityTakeDamage", "EntityTakeDamage",  playerHurtSound )

local function playerHurtSound( ent, inflictor, attacker, amount )

     local damage = amount 
     local health = ent:Health() - damage


But I get the error:

[ERROR] addons/sgn_hurtsound/lua/autorun/server/sv_hurt.lua:19: attempt to perform arithmetic on local 'damage' (a nil value)
  1. v - addons/sgn_hurtsound/lua/autorun/server/sv_hurt.lua:19
   2. unknown - lua/includes/modules/hook.lua:84

Am I using amount from there and if so how?

The wiki says:

GM:EntityTakeDamage( Entity Target, Entity Inflictor(usually a weapon), Entity Attacker, Number amount of damage done, Ctakedamageinfo Damage Info )

Target = entity
Inflictor = entity
Amount = number

Couldn’t you check the wiki for arguments?

It has only two arguments.

Oh damn, sorry. That’s the first time the old wiki has ever failed me. I didn’t even think to check.

Thanks :confused:

[editline]7th June 2014[/editline]

Thank you

local function playerHurtSound( ent, dmginfo )

	local damage = dmginfo:GetDamage()

	local health = ent:Health() - damage