Kill NPC when it touches a certain prop?

Greetings!

I was wondering how to get a NPC killed by a certain prop in LUA. For example: I throw a baby at GMan -> GMan gets killed.
Does anyone know how to archieve this?

Thank you in advance! :smiley:

And how would this work with NPCs? Could you give me an example?

The old wiki has an example.

Just make sure to to use hooks.

Here is a quick example I made for you:



function ENT:Touch(entity)
if entity:GetModel() == "what_ever_model.mdl" then -- The NPC will die when it touches a certain model, if you want an entity then change the "GetModel" to "GetClass"
self:TakeDamage(9999999,self,self)
end end


why not just use v:Kill()?

NPCs are not SENTS. That is useless.

You would need to have an “EntityOnTakeDamage” hook and check for physics damage. I believe you can get the physics damage inflicter, so it would be something like.



hook.Add("EntityOnTakeDamage","KillGman",function(target,dmginfo)
 if target:IsNPC() and target:GetClass == "npc_gman" then
  if dmginfo:GetDamageType == DMG_CRUSH then
   if dmginfo:GetInflictor():GetModel() == "your model" then
     dmginfo:SetDamage(9999999)
   end
  end
 end
end) 



The only issue with this is that it would only work if the prop actually does damage in the first place. Probably not the best way to do it, I am in a rush and this is the first thing that came to my head.

`

When I use your script it gives me this error.


[ERROR] addons/myaddon/lua/weapons/weapon_myaddon/shared.lua:75: function arguments expected near '=='
  1. unknown - addons/myaddon/lua/weapons/weapon_myaddon/shared.lua:0

Missing the ()



dmginfo:GetDamageType()


Still the same error. :confused:

Same with



target:GetClass() == "npc_gman"


Ahh, no errors, but it doesn’t kill gman when I launch the specified prop at him.

Because, he isn’t taking damage, hook will only work if the baby actually hurts the GMan, which is why I disagreed with his post and knew it wouldn’t work.

You need to use a new method

Stop hating on me, I just messed up once. All I was trying to do is help -_-

derp just check distance

Try setting this on the prop beforehand.