If I were to kill an [B]specific[/B] NPC, how would I have a function be executed after that happening?
[url]http://wiki.garrysmod.com/page/GM/OnNPCKilled[/url]
You use this hook and compare the first argument to your specific npc. ( I am assuming NPC:GetClass() == "myclass" or NPC:GetModel() )
[lua]
function OnNPCKilled( NPC, attacker, weapon )
if (NPC:GetClass() == "Antlion Guard") then
PrintMessage( HUD_PRINTTALK, "(EVENT) The beast has been killed! " .. attacker:GetName() .. " did <# of damage> to the beast and receives a Diamond! <Name> did <amount of dmaage> and receives a <award>!" )
elseif (NPC:GetClass() == "Antlion") then
PrintMessage( HUD_PRINTTALK, "(EVENT) The beast's child has been killed! " .. attacker:GetName() .. " receives a ruby! The child spews poison on all around it! " )
end
end
hook.Add("OnNPCKilled", "OnNPCKilled", OnNPCKilled);
[/lua]
The hook works, however the NPC:GetClass does not.
Because classname of antlion guard is not "Antlion Guard" but "npc_antlionguard".
You could have figured that out on your own by printing the NPC:GetClass() from that hook.
[QUOTE=rbreslow;42033032][lua]
function OnNPCKilled( NPC, attacker, weapon )
if (NPC:GetClass() == "Antlion Guard") then
PrintMessage( HUD_PRINTTALK, "(EVENT) The beast has been killed! " .. attacker:GetName() .. " did <# of damage> to the beast and receives a Diamond! <Name> did <amount of dmaage> and receives a <award>!" )
elseif (NPC:GetClass() == "Antlion") then
PrintMessage( HUD_PRINTTALK, "(EVENT) The beast's child has been killed! " .. attacker:GetName() .. " receives a ruby! The child spews poison on all around it! " )
end
end
hook.Add("OnNPCKilled", "OnNPCKilled", OnNPCKilled);
[/lua]
The hook works, however the NPC:GetClass does not.[/QUOTE]
Too bad no one has the mining stuff from Noobonic.
Sorry, you need to Log In to post a reply to this thread.