NPC doesn't attack the player

I have a problem with an NPC spawning script.

The combine spawned via the the below code receives a pistol with which he should normally shoot the player, as you know, combines don’t like players much.
At least it works that way in sandbox.

Well, the combine spawns, I stand in front of me. He turns to me, getting ready to attack - BUT: **He repeats the animation where he pulls out the pistol I gave him over and over again, not attacking me.

What am I doing wrong?**

The code is below:
(Deriving from base gamemode)

I checked the variables spawn.pos, spawn.angle and (all set by me) but they have no errors.
The same problem occurs with other weapons and npcs, however some just stand still with their weapon.
Zombies who don’t have any weapons attack as usual.

            local ent = ents.Create( "npc_metropolice" )
            ent:SetPos( spawn.pos )
            ent:SetAngles( spawn.angle )
            ent:SetHealth( )


I have tried your solution, yet basically nothing has changed.

Aren’t these capabilities only required to be set with SNPCS? Because I’m using the standard HL2 ones.


Try using SNPC’s then

But first try giving him a different weapon

Why do I need to use SNPCS?

I’d like to not recode the AI if I already got all the hl2 npcs at my fingertipps.

Also, in the sandbox gamemode the hl2 standard npcs are used too, and they can shoot at you - so is it possible that this isn’t the actual problem?

Thanks for your help so far

Okay, SNPCS are out of this.

Try giving him an SMG, see if he can fire it.

Thanks for your reply

Like I said in the original post, I tried it with all different npcs and different weapons

I tried npc_combine_s too, with smg, pistol and ar2 as well a shotgun and crowbar

nothing worked :confused:


It should work, if you create an NPC which has already been coded and is working, it should work when you spawn it.

I know, yet the npc does just stand around like… an idiot.

I tried it, mine does the same, i’m sure you need to create an SNPC.

Follow my tutorial on creating an NPC shop, but cut out the shop part

I’m sure you don’t need to create a snpc.

Use this :

npc:SetKeyValue("additionalequipment", "weapon_pistol")

Hmm odd it doesn’t work but there is a way around it, that I know.


This works :

local ent = ents.Create( "npc_metropolice" )
ent:SetKeyValue("additionalequipment", "weapon_pistol")

It really works.

I really appreciate your help, thanks** a lot!** I would have probably not found out without your help :slight_smile: