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! :D
[QUOTE=AnonTakesOver;44921109][url]http://wiki.garrysmod.com/page/ENTITY/Touch[/url][/QUOTE]
And how would this work with NPCs? Could you give me an example?
[url]http://wiki.garrysmod.com/page/GM/OnNPCKilled[/url]
The old wiki has an example.
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7b43.html[/url]
Just make sure to to use hooks.
Here is a quick example I made for you:
[code]
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
[/code]
[QUOTE=vrej;44933262]Here is a quick example I made for you:
[code]
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
[/code][/QUOTE]
why not just use v:Kill()?
[QUOTE=vrej;44933262]Here is a quick example I made for you:
[code]
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
[/code][/QUOTE]
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.
[CODE]
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)
[/CODE]
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.
[QUOTE=Fortune11709;44939002]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.
[CODE]
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)
[/CODE]
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.[/QUOTE]`
When I use your script it gives me this error.
[CODE][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[/CODE]
Missing the ()
[code]
dmginfo:GetDamageType()
[/code]
[QUOTE=AnonTakesOver;44939466]Missing the ()
[code]
dmginfo:GetDamageType()
[/code][/QUOTE]
Still the same error. :/
[QUOTE=Silverah!;44939722]Still the same error. :/[/QUOTE]
Same with
[code]
target:GetClass() == "npc_gman"
[/code]
[QUOTE=AnonTakesOver;44939779]Same with
[code]
target:GetClass() == "npc_gman"
[/code][/QUOTE]
Ahh, no errors, but it doesn't kill gman when I launch the specified prop at him.
[QUOTE=Silverah!;44939802]Ahh, no errors, but it doesn't kill gman when I launch the specified prop at him.[/QUOTE]
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.
[url]http://wiki.garrysmod.com/page/Entity/SetPhysicsAttacker[/url]
Sorry, you need to Log In to post a reply to this thread.