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[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[/code]
CurTime() is always more than 3.
[QUOTE=Robotboy655;43795407]CurTime() is always more than 3.[/QUOTE]
Then what should I replace it with?
[QUOTE=I'm great;43795423]Then what should I replace it with?[/QUOTE]
With something that works. Enable your common sense.
[QUOTE=Robotboy655;43795426]With something that works. Enable your common sense.[/QUOTE]
And what does work?
[QUOTE=I'm great;43795473]And what does work?[/QUOTE]
Something that won't always return true.
I am not telling you the answer, you'll never learn that way.
[QUOTE=Robotboy655;43795522]Something that won't always return true.
I am not telling you the answer, you'll never learn that way.[/QUOTE]
And what if I can't find anything equivalent?
[QUOTE=I'm great;43795618]And what if I can't find anything equivalent?[/QUOTE]
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.
[QUOTE=Robotboy655;43796298]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.[/QUOTE]
Scooby Doo and a mysterious variable.
I don't know what it can be.
[QUOTE=I'm great;43796448]Scooby Doo and a mysterious variable.
I don't know what it can be.[/QUOTE]
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.
[QUOTE=Netheous;43808380]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.[/QUOTE]
The problem is I have no idea what those variables could be.
[QUOTE=I'm great;43808759]The problem is I have no idea what those variables could be.[/QUOTE]
You create your own variable, you can name it whatever you want.
The stupidity is great with this one...
[CODE]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
[/CODE]
something like this :S
[CODE]
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
[/CODE]
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.
[QUOTE=Drak_Thing;43810499][CODE]
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
[/CODE]
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.[/QUOTE]
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.
Sorry, you need to Log In to post a reply to this thread.