Having problems with NPC:Give()

The commands is supposed to give a weapon to and NPC, however when the NPC gets the weapon, it acts as if it doesn’t have one, even if you can clearly see that it has one holding in hands, but never actually shoots it. Is this a bug with the command or am I doing something wrong? Even giving weapon to freshly spawned NPC doesn’t work.

Are you using a custom NPC or a standard one?
Is the gun from HL2 or a SWEP?
Not all NPCs know how to use all weapons.

It’s default HL2 weapons and it is given to a NPC that doesn’t have a weapon yet.

Is the NPC a combine solider or a zombie? Zombies can’t use weapons. You get the point. What NPC exactly are you trying to give the weapon to?

npc_combine_s, also doesn’t work for npc_citizen.

It seems to not work for me too, maybe a bug with GMod?

Yeah, been trying to figure if I have to give the weapon to NPC before or after spawning, doesn’t seem to work either way, the only known way to spawn it with weapons is use “npc_create_equipment” and then use “npc_create” to create npc which is impractical.

There’s a keyvalue which sandbox NPC spawning uses ( source in sandbox/commands.lua ), maybe try that?

How would I use that?

if ( Equipment && Equipment != “none” && valid ) then
NPC:SetKeyValue( “additionalequipment”, Equipment )
NPC.Equipment = Equipment

I guess Equipment means the weapon entity?

Equipment is a classname, you must use this BEFORE calling Spawn() on the NPC.

Thanks, got it working using that keyvalue command.