Particle Emitter Problem.

Hello, I am fooling around with particleEmitters to try to create a realistic smoke effect. the effect is done, and it indeed does work, But whenever i pause the game or go into console, i get



[addons\chainsaw\lua\weapons\weapon_zs_chainsaw\cl_init.lua:29] ParticleEmitter: Couldn't make emitter! Too many emitters!
[addons\chainsaw\lua\weapons\weapon_zs_chainsaw\cl_init.lua:32] attempt to index field 'emitter' (a nil value)


Here is my code for creating the particles:
[lua]
local smoke = {
“particle/smokesprites_0001”,
“particle/smokesprites_0002”,
“particle/smokesprites_0003”,
“particle/smokesprites_0004”,
“particle/smokesprites_0005”,
“particle/smokesprites_0006”,
“particle/smokesprites_0007”,
“particle/smokesprites_0008”,
“particle/smokesprites_0009”,
“particle/smokesprites_0010”,
“particle/smokesprites_0012”,
“particle/smokesprites_0013”,
“particle/smokesprites_0014”,
“particle/smokesprites_0015”,
“particle/smokesprites_0016”
}

function SWEP:Think()
self.emitter = ParticleEmitter(self:GetPos())
local BoneIndx = self.Owner:LookupBone(“ValveBiped.Bip01_R_Hand”)
local position = self.Owner:GetBonePosition( BoneIndx )
local particle = self.emitter:Add( table.Random(smoke), position)
if self.Weapon:IsValid() then
particle:SetDieTime( 1 )
particle:SetStartAlpha( 10 )
particle:SetEndAlpha( 0 )
particle:SetStartSize( 0 )
particle:SetEndSize( math.Rand( 20, 30 ) )
particle:SetRoll( math.Rand( 360, 480 ) )
particle:SetRollDelta( math.Rand( -1, 1 ) )
particle:SetColor( 180, 180, 180 )
particle:SetVelocity(VectorRand()10+vector_up40)
particle:SetGravity(Vector(math.Rand(-100,100),math.Rand(-100,100),math.Rand(150,200)))
particle:SetAirResistance(100)
particle:SetCollide(true)
end
end
[/lua]
EDIT: i think i might have found the problem. the server builds up ALL THESE emitters while the game is paused/stopped.
i tested this, and there was a larger puff of smoke after resuming the game. the puff was larger and more opaque the longer i had it paused.
So, here’s the next question. How would i opress the think function creating emitters while the game is paused?

[lua]function SWEP:Initialize()
self.emitter = ParticleEmitter(self:GetPos())
end

function SWEP:Think()
self.emitter:SetPos(self:GetPos())
– particle stuff
end[/lua]

You don’t need to make a new emitter every frame, and that is what is causing your first error of “too many emitters.” This, in turn, causes the second error, because it refuses to create the emitter since there are too many, and then you try to work off it.

This should fix your problem. :buddy:

-snip- wouldn’t work