• Entity Takes Damage
    7 replies, posted
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 :)
For a gamemode, you can use [lua]function GM:EntityTakeDamage(ent, wep, attacker, dmg, dmginfo) --stuff end[/lua] Otherwise, [lua]hook.Add("EntityTakeDamage","SomeHookNameHere", function(ent, wep, attacker, dmg, dmginfo) --stuff end)[/lua]
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() --stuff end[/lua]
Thanks :) [editline]8th February 2012[/editline] The GetInflictor deosnt work, i did this: [lua] attacker:ChatPrint(wep) [/lua]' and it said Bad argument expected string got player
Im trying to print the weapon used. Bump
[code]attacker:SendLua("LocalPlayer():ChatPrint(wep:GetPrintName())")[/code] Used SendLua because GetPrintName is clientside.
Yes but I need to use it in a serverside script as well.
Sorry, you need to Log In to post a reply to this thread.