Overheating doesn't work.

I’m working on a SWEP, that should overheat, but it does it right when I fire it.
Here’s the part of the code



function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	local bullet = {}
		bullet.Num = self.Primary.NumberofShots
		bullet.Src = self.Owner:GetShootPos()
		bullet.Dir = self.Owner:GetAimVector()
		bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
		bullet.Tracer = 0
		bullet.Force = self.Primary.Force
		bullet.Damage = self.Primary.Damage
		bullet.AmmoType = self.Primary.Ammo
	local rnda = self.Primary.Recoil * -1
	local rndb = self.Primary.Recoil * math.random(-1, 1)
	self:ShootEffects()
	self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(self.Primary.Sound)
	self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
	self:TakePrimaryAmmo(self.Primary.TakeAmmo)
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + .1 )

		self:Muzzleflash()
		self:Overheat()
	end
function SWEP:Overheat()
if CurTime() > 3 and self.Owner:KeyDown(IN_ATTACK) then
	self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
	self.Weapon:EmitSound("RTCW/sten/sten_overheat.wav")
	end
	end

CurTime() is always more than 3.

Then what should I replace it with?

With something that works. Enable your common sense.

And what does work?

Something that won’t always return true.

I am not telling you the answer, you’ll never learn that way.

And what if I can’t find anything equivalent?

Then you are not trying hard enough.

I will give you a hint: You want to add that 3 to a variable which you must set when you start shooting and reset when you stop shooting.

Scooby Doo and a mysterious variable.
I don’t know what it can be.

Think stopwatch.

What Robotboy wanted to say is that CurTime() is always a number above 3(except fo the first 3 seconds of the server), so if you call:
[lua]CurTime() > 3[/lua]
then it’s like constantly running
[lua]2311923 > 3
1938923 > 3
28378 > 3[/lua]
and so on as it’s a time in seconds representing how long the server has been running.

What Robotboy wanted you to do is add few variables.
Just add a variable that will store the last time weapon has been called, then add a variable that will be telling you if the weapon is still in use.

The problem is I have no idea what those variables could be.

You create your own variable, you can name it whatever you want.

The stupidity is great with this one…


function SWEP:Overheat()
	self.Weapon.OverheatCount = self.Weapon.OverheatCount + 1
	if self.Weapon.OverheatCount == 10 then
		self.Weapon.OverheatTime = CurTime() + 3
		self.Weapon.OverheatCount = 0
	end
	if self.Weapon.OverheatTime and self.Weapon.OverheatTime  > CurTime() and self.Owner:KeyDown(IN_ATTACK) then
		self.Weapon:SetNextPrimaryFire( CurTime() + 2 )
		self.Weapon:EmitSound("RTCW/sten/sten_overheat.wav")
	end


something like this :S



function SWEP:PrimaryAttack()
	
	if( not self:CanPrimaryAttack() ) then return end
	
	local bullet = {}
		bullet.Num = self.Primary.NumberofShots
		bullet.Src = self.Owner:GetShootPos()
		bullet.Dir = self.Owner:GetAimVector()
		bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
		bullet.Tracer = 0
		bullet.Force = self.Primary.Force
		bullet.Damage = self.Primary.Damage
		bullet.AmmoType = self.Primary.Ammo
	
	local rnda = self.Primary.Recoil * -1
	local rndb = self.Primary.Recoil * math.random(-1, 1)
	
	self:ShootEffects();
	self.Owner:FireBullets( bullet );
	
	self.Weapon:EmitSound( self.Primary.Sound )
	self.Owner:ViewPunch( Angle( rnda, rndb, rnda ) )
	self:TakePrimaryAmmo( self.Primary.TakeAmmo )
	
	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + .1 )
	
	self:Muzzleflash()
	self:Overheat()
	
end

function SWEP:Overheat()

	local currentTime = CurTime();
	
	-- move this somewhere else, just make sure the variable exists
	self.Weapon.fireTime = self.Weapon.fireTime or 0
	
	-- grab the time we started firing
	if( self.Weapon.fireTime <= 0 ) then self.Weapon.fireTime = currentTime end
	
	-- we stopped firing, reset our time
	if( not self.Owner:KeyDown( IN_ATTACK ) ) then
		self.Weapon.fireTime = 0
		return
	end
	
	-- in 10 seconds, overheat the gun
	if( ( currentTime - self.Weapon.fireTime ) >= 10 ) then
		self.Weapon:SetNextPrimaryFire( currentTime + 2 );
		self.Weapon:EmitSound( "RTCW/sten/sten_overheat.wav" );
		self.Weapon.fireTime = 0
	end
	
end


I assume you probably want to add a “cooldown”.
Not sure if firetTime would ever be reset. Would be easier if you posted the entire SWEP.

If you have played Wolfenstein, then there is such a feature - if you have a long shoot, weapon overheats you and you need to wait for some time.