• ent:AddCallback() to detect damage
    9 replies, posted
Is it possible to use an ent:AddCallback on an entity to detect if it was shot and possibly how much damage it sustained?
no, but you can override the function instead. [code]local ent = FindMetaTable("Entity") local oldOnTakeDamage = ent.OnTakeDamage function ent:OnTakeDamage(dmginfo) oldOnTakeDamage() -- code here end[/code]
[QUOTE=Nopari;47373653]no, but you can override the function instead. [code]local ent = FindMetaTable("Entity") local oldOnTakeDamage = ent.OnTakeDamage function ent:OnTakeDamage(dmginfo) oldOnTakeDamage() -- code here end[/code][/QUOTE] I'm not sure you can. These are functions that are used by the class itself...
Why don't you just make an EntityTakeDamage hook with hook.Add? Am I missing something?
[QUOTE=zerf;47374088]Why don't you just make an EntityTakeDamage hook with hook.Add? Am I missing something?[/QUOTE] this is what I thought too, there must have been a particular reason to not just hook it
I am confused. Why don't you just use: [CODE] function ent:OnTakeDamage(DamageInfo) local Dmg = DamageInfo:GetDamage() end [/CODE]
Because that doesn't work on engine entities, only sents, and it is also a bad idea in the event the entity already does something else with OnTakeDamage
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url]
[QUOTE=Kogitsune;47376506]Because that doesn't work on engine entities, only sents, and it is also a bad idea in the event the entity already does something else with OnTakeDamage[/QUOTE] Ah, I see, didn't really think he was doing it on an already existing entity, was guessing he is making his own. Didn't really say that XD
Sorry, you need to Log In to post a reply to this thread.