Drop entity when NPC died

Hi, i do a little script.


if not SERVER then return end

local WeaponList = {
	"zombies_mysterybox" -- The dropped entity
}

hook.Add("OnNPCKilled", "DropWeaponOnNPCKilled", function(npc, killer, weapon)

	local weapon = ents.Create(table.Random(WeaponList))
	
	weapon:SetPos(npc:LocalToWorld(npc:OBBCenter()))
	
	weapon:Spawn()
	
	
end)

I want this to work for “npc_animal_bear” only. What i can do it please? Thank you (sorry for my bad language (i am French))

faut mettre dans ton hook,


if npc:GetClass() == "npc_animal_bear" then 
--ton bla bla 
else return end

Hum, cela ne marche pas, peux tu me préciser où dois-je le mettre? Merci

Same procedure



if not SERVER then return end

local WeaponList = {
	"zombies_mysterybox" -- The dropped entity
}

hook.Add("OnNPCKilled", "DropWeaponOnNPCKilled", function(npc, killer, weapon)

	if npc:GetClass() == "npc_animal_bear" then 
		local weapon = ents.Create(table.Random(WeaponList))	
		weapon:SetPos(npc:LocalToWorld(npc:OBBCenter()))	
		weapon:Spawn()
	else
		return
	end
	
end)


Thank you very much