I’m trying to use EntityTakeDamage hook.
hook.Add("EntityTakeDamage", "EntityTakeDamage", playerHurtSound ) local function playerHurtSound local health = ent:Health() print(tostring(health)) end
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 print(tostring(health)) end
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