Lua Weapon Help


 function SWEP:CSShootBullet( dmg, recoil, numbul, cone, fireFrom, aimVector, distanceLeft, showTracerOverride, orig )
	numbul 	= numbul 	or 1
	cone 	= cone 		or 0.01
	distanceLeft = distanceLeft or self.MaxPenetration;
	fireFrom = fireFrom or self.Owner:GetShootPos()
	aimVector = aimVector or self.Owner:GetAimVector()

	for i = 1, numbul do
		local showTracer = showTracerOverride or 0;
		
		if (!showTracerOverride) then
			self.bulletNumber = self.bulletNumber + 1;  <= ***LINE 12***
			
			if (self.bulletNumber == self.TracerRarity) then
				self.bulletNumber = 0;
				showTracer = 1;
			end
		end
		
		local realSpread = Vector(0, 0, 0);
		
		if (cone != 0) then
			realSpread = Vector(math.random() * cone * randSign(), math.random() * cone * randSign(), math.random() * cone * randSign());
		end
		
		local trueAim = aimVector + realSpread;
		local trace = {};
		trace.start = fireFrom;
		trace.endpos = trace.start + (trueAim * 1000000);
		
		local traceRes = util.TraceLine(trace);
		local dir = (traceRes.HitPos - trace.start):Normalize();
		local hitPosition = traceRes.HitPos;
		
		local bullet = {}
		bullet.Num 		= 1
		bullet.Src 		= fireFrom								// Source
		bullet.Dir 		= dir									// Dir of bullet
		bullet.Spread 	= Vector(0, 0, 0)						// Aim Cone
		bullet.Tracer	= showTracer							// Show a tracer on every x bullets 
		bullet.Force	= 5										// Amount of force to give to phys objects
		bullet.Damage	= dmg
		
		self.Owner:FireBullets(bullet)
		
		if (SERVER && traceRes.Entity && traceRes.Entity:GetClass() == "prop_vehicle_jeep" && traceRes.Entity:GetTable().CarDamage) then
			if (traceRes.Entity:GetModel() != "models/weapons/m4a1.mdl") then
				traceRes.Entity:GetTable().CarDamage = traceRes.Entity:GetTable().CarDamage - (dmg * .5);
					
				if traceRes.Entity:GetTable().CarDamage <= 0 then
					traceRes.Entity:DisableVehicle();
				end
					
				local Driver = traceRes.Entity:GetDriver();
					
				if Driver and Driver:IsValid() and Driver:IsPlayer() then
					local NewHealth = Driver:Health() - (dmg * .4);
						
					if NewHealth <= 0 then
						Driver:Kill();
					else
						Driver:SetHealth(NewHealth);
						Driver:GetTable().OnEnteredHealth = NewHealth;
					end
				end
			end
		else
			if (CLIENT && orig) then				
				for k, v in pairs(player.GetAll()) do
					if (!v:Alive()) then
						local playerRagdoll = v:GetRagdollEntity()
						
						if (playerRagdoll) then
							for _, ent in pairs(ents.FindInSphere(traceRes.HitPos, 5)) do						
								if ent == playerRagdoll then
									RunConsoleCommand(biurder', v:UniqueID());
								end
							end
						end
					end
				end
			end
			
			distanceLeft = distanceLeft - hitPosition:Distance(fireFrom);
			
			if (distanceLeft > 0 && (!traceRes.Entity || !IsValid(traceRes.Entity) || !traceRes.Entity:IsPlayer())) then
				for i = 1, self.MaxPenetration_Depth do
					if (distanceLeft < (i * 1000)) then break; else
						local testPos = hitPosition + (trueAim * i * 5);
						
						if (util.IsInWorld(testPos)) then
							self:CSShootBullet(dmg * .75, recoil, 1, 0, testPos, aimVector, distanceLeft - (i * 1000), showTracer);
							self:CSShootBullet(dmg * .75, recoil, 1, 0, testPos + (trueAim * 5), aimVector * -1, -100, showTracer);
							
							break
						end
					end
				end
			end
		end
	end
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK); 		// View model animation
	self.Owner:MuzzleFlash();								// Crappy muzzle light
	self.Owner:SetAnimation(PLAYER_ATTACK1);				// 3rd Person Animation
	
	
	
	if ( self.Owner:IsNPC() ) then return end
	
	// CUSTOM RECOIL !
	if (!showTracerOverride && ((SinglePlayer() && SERVER) || ( !SinglePlayer() && CLIENT && IsFirstTimePredicted() ) )) then
	
		local eyeang = self.Owner:EyeAngles()
		eyeang.pitch = eyeang.pitch - recoil
		self.Owner:SetEyeAngles( eyeang )
	
	end

end 

[weapons\weapon_ambationbase\shared.lua:12] attempt to perform arithmetic on field ‘bulletNumber’ (a nil value) Can someone help>? I would appreciate it.

bulletNumber is nil, so you should change that line to:

[lua]
self.bulletNumber = (self.bulletNumber + 1) or 0;
[/lua]

Thank you.