Getting SNPCs recognized by GM:OnNPCKilled

So i have a scripted npc, but stuff needs to happen when it dies
the problem is its not getting picked up by the GM:OnNPCKilled hook
how can i make this happen? because the same things need to happen for the every npcs, and this way i have it in one place (since its gonna see modification in the future)

also, on the scripted npc, when i do ent:SetHealth(1000), it won’t get affected
neither does ent.Var :frowning:

thanks for the help :3

You need to add support yourself.

Wherever your SNPC’s take damage function is, there is probably (or should be) a SNPC:Function() that calls when the health is less than zero, to handle SNPC death. Inside that function, I’d call whatever function you want to happen when your SNPC death.

As to SetHealth, if I recall, SNPCs use a custom health system (for example, I use the variable SNPC.cHealth). If you want to use Entity:SetHealth(int) on your SNPC, then you may want to redefine the function for that SNPC, so it’d look something like this:

[lua]function ENT:SetHealth(int)
self.cHealth = int
end[/lua]

I can’t remember if SNPC entities use “ENT” or not - It’s been a while since I’ve worked with SENTs or SNPCs, and I’m not on my home computer at the moment.

That’s pretty much all you have to do, though, to accomplish what you want.

[lua]function ENT:OnTakeDamage(dmginfo)
– Conditions to check for death here
hook.Call(“OnNPCKilled”,GAMEMODE,self,dmginfo:GetAttacker(),dmginfo:GetInflictor())
end[/lua]
This should do the trick, untested.

i shall try it out :smiley: will post back when it works :3

oh and what about the ent:SetHealth and ent.Var thingy?

the hooking code works :3 one question about it, is it possible to pass extra variables to the hook? like this:
[lua]
hook.Call(“OnNPCKilled”, GAMEMODE, self, dmginfo:GetAttacker(), dmginfo:GetInflictor(), var1, var2, var3, …)
[/lua]

the variables still bug me tho :<
i tried doing the health thingy, but it doesn’t work, the hp variable stays nil for some reason D:

EDIT: I hate myself >_> for double posting and for getting it to work after posting this D:
thanks guys :3

also, answer on my own question, yes you can add extra parameters :smiley:

Why are you over complicating things? Just call your own hook, or dont hook it at all and do stuff on the NPC in the OnTakeDamage Hook!

what i have now is perfect :smiley:
like most people say, write your own deathcheck and if he dies call the onnpckilled hook :3