NPC Using SWEP, Stops Calling PrimaryAttack()

I’ve yet to figure this out, and I was hoping SOMEONE could help me out. I’ve added this stuff in the SWEP’s Initialize:

[lua]if SERVER and self.Owner:IsNPC() then
self:SetWeaponHoldType(self.HoldType)
self:SetNPCMinBurst(30)
self:SetNPCMaxBurst(30)
self:SetNPCFireRate(self.Primary.Delay)
self:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_VERY_GOOD )
end[/lua]

This is at the top of PrimaryAttack, before anything else, so it should definitely be called when primary fire hits:

[lua]if SERVER then
ErrorNoHalt("IsNPC: "…tostring(self.Owner:IsNPC()))
end[/lua]

I should be being spammed with these ErrorNoHalts, but he fires 3-5 times (and everything works), then it just stops. I just don’t get it. No errors, nothing to tell me why this is happening. Has anyone dealt with this before?

EDIT: This is the usual output I see with this.


//I spawn the npc
18:55:32 L 12/10/2012 - 18:43:09: Lua Error: IsNPC:  true
18:55:32 L 12/10/2012 - 18:43:09: Lua Error: IsNPC:  true
18:55:33 L 12/10/2012 - 18:43:10: Lua Error: IsNPC:  true
18:55:33 L 12/10/2012 - 18:43:10: Lua Error: IsNPC:  true
18:55:34 L 12/10/2012 - 18:43:10: Lua Error: IsNPC:  true
18:55:34 L 12/10/2012 - 18:43:10: Lua Error: IsNPC:  true  // He stops firing here.
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false //Everything from here down is a small burst from a player.
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false
18:55:36 L 12/10/2012 - 18:43:13: Lua Error: IsNPC:  false

He’ll start to fire again, sometimes, if I move out of sight, and he moves himself to line of sight, then fires a few more rounds.

Have you tried adding an Else condition to your second part to help elucidate what the game thinks the NPC has become? Maybe using GetOwner, GetClass, and converting those to a string for output would at least give insight on what’s going on.

You may want to also make sure you’re really getting a ‘false’ return on the boolean and not a ‘nil’ value coerced into such; I don’t know what would cause that but might also be worth checking.

Thanks, that helped quite a bit. It seems like the weapon owner (self.Owner) in Initialize is nil. I assume because it hasn’t been assigned an owner yet. That may be the problem.

EDIT:
Oddly enough, it seems I’ve found a little extra info on the problem. I’ve moved the declarations around a bit, not much has really changed. But I did learn that he only fires while he’s moving. Once he stops, he stops firing, even though the muzzle flash seems to continue firing.