How to make different death sounds for NPC's?

Well, I’m making a pack of npc’s and I have no clue how to make different death sounds for my npc’s. I have the sounds I want to use, but I don’t know what line to put in the lua file. Help please

And maybe how to make them have different sounds for hurt too, like if I shoot them they say something other than the normal pain sound?

Put all the sounds in a table on init. Such as table={“bleh”,“poop”} then in the ondeath hook for snpc, just emit a sound from table.Random(table)

Can you give me an example of what the init should look like?

[LUA]DeathList = {
Sound(“vo/npc/male01/answer30.wav”),
Sound(“vo/npc/male01/hi01.wav”),
Sound(“vo/npc/male01/hi02.wav”),
Sound(“vo/npc/male01/question06.wav”),
Sound(“vo/npc/male01/question29.wav”),
}
HurtList = {
Sound(“vo/npc/male01/answer30.wav”),
Sound(“vo/npc/male01/hi01.wav”),
Sound(“vo/npc/male01/hi02.wav”),
Sound(“vo/npc/male01/question06.wav”),
Sound(“vo/npc/male01/question29.wav”),
}

function ENT:OnTakeDamage(dmg)
self.Entity.Healthz = self.Entity.Healthz - dmg:GetDamage();

if(self.Entity.Healthz <= 0) then 
	self:EmitSound(table.Random(DeathList))
	timer.Simple(4, function()
		self.Entity:Remove();
	end)
else
	self.EmitSound(table.Random(HurtList))
end

end[/LUA]
Something like that. Define self.Healthz in the init. This code will go in shared.lua

So I’m probably going to need to make different shared.lua files for all the different snpc’s?

I’ve never made an SNPC so correct me if I’m wrong, but you should be doing that anyways.

Ok, I’ve downloaded a couple npc packs, and I think I have a basic outline of what to do. I’ll post here again if I have any problems.


woops

It’s people.

I’d just stick with normal hl2 sounds 0_0

Ok, I’m only able to spawn them when I don’t define self.Healthz. When I do I can’t spawn them. This is a screenshot of the errors I get.

entities
pc_heavynight\shared.lua:51 : attempt to perform arithmetic on field ‘Healthz’ (a nil value)
Are you sure there should be a z on the end of ‘Healthz’?

And what npc are you using to back it?
Like…what npc is it but using that model?

I was using that code that skopaplyse posted and he said to define self.Healthz in the init so i did. I’m trieing to make my own npc class for it.

EDIT: When I define self.Healthz i get this error.
entities/npc_heavyknight/init.lua:53: ‘<eof>’ expected near ‘end’

To get the health of an entity:

self:Health() will give you the health of the Entity. You can do self.Entity but I believe that just self works also.

As an alternative though you could also try this:

Check the class of the NPC (Victim) and make them emit a random sound. Or you can stick with the above example by Skapocalypse.

<eof> means you have an end where it shouldn’t be, or you’re missing an end somewhere.