How to make a swep spawn an SNPC?

Title. I need to know how to make a swep spawn an SNPC.

[lua]local tr = self.Owner:GetEyeTrace()
local npc = ents.create(“npc_zombie”)
npc:SetPos(tr.HitPos)
npc:SetAngles(self.Owner:GetAngles())
npc:Spawn()[/lua]
In SWEP:PrimaryAttack()

This is the simplest way to do it, wrote in the reply window and untested but it should work.

Just by reading that, I’m guessing that will just spawn it where the person is looking? I don’t know why, but when I read the title I though in my head something like this:
[lua]
function SWEP:PrimaryAttack()
player:ConCommand(“npc_breen”)
end
[/lua]
I like to do console commands alot because I used to do alot of .cfg scripting for Half-Life 2: Deathmatch :v:

In general it is best to leave the client out of the decision making process as much as possible. With your code the server would send a command to the player telling it to send a command to the server to tell it to spawn an NPC. Also if you rely on console commands you have to remember that the client can call them any time they want. And yes, that code will spawn an NPC where you are looking and it should be facing away from you.

I put that code in and it is giving me this error:

weapons/weapon_captain’s_parrot/shared.lua:69: attempt to call field ‘create’ (a nil value)

I’ll post the shared.lua if it is needed.

Create should be capitalized.

Yeah, I know how to do it without console commands. I just used to do .cfg stuff ALOT :snoop: