I'm trying to use EntityTakeDamage hook.
[CODE]hook.Add("EntityTakeDamage", "EntityTakeDamage", playerHurtSound )
local function playerHurtSound
local health = ent:Health()
print(tostring(health))
end[/CODE]
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
[CODE]hook.Add("EntityTakeDamage", "EntityTakeDamage", playerHurtSound )
local function playerHurtSound( ent, inflictor, attacker, amount )
local damage = amount
local health = ent:Health() - damage
print(tostring(health))
end[/CODE]
But I get the error:
[CODE][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
[/CODE]
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?
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url]
It has only two arguments.
[QUOTE=Robotboy655;45024218]Couldn't you check the wiki for arguments?
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url]
It has only two arguments.[/QUOTE]
Oh damn, sorry. That's the first time the old wiki has ever failed me. I didn't even think to check.
Thanks :/
[editline]7th June 2014[/editline]
Thank you
[CODE]
local function playerHurtSound( ent, dmginfo )
local damage = dmginfo:GetDamage()
local health = ent:Health() - damage
[/CODE]
Sorry, you need to Log In to post a reply to this thread.