Swep Charge up?

hi. I have a question.
Ive been trying to make it so that before my swep fires a bullet, it “Charges Up” for 4 seconds before the bullet shoots. Ive tried a bunch of scripts but i cant seem to get this to work. Any help?

I don’t have the answer right here for you, but try looking at the newton launcher code in the terrortown files. I believe its class name is weapon_ttt_push

i want the charge up to not do anything to the bullet itself. i want it to delay for 4 seconds before shooting the bullet.

Hello, I would recoment you using a timer.Simple() :slight_smile:

Exemple




local time = 4

timer.Simple(time, function()
    <code>
end



This will only make a 4 sec delay before it shoots!

D’oh But of course! Why didn’t i think of timers!

Thanks!

[editline]9th March 2013[/editline]

alright. the swep now “charges up”. but i am having a problem. Now, instead of just creating one bullet, it creates loads, taking up the clip ammon AND the ammo that hasn’t been reloaded yet! What is going on???



function SWEP:PrimaryAttack()

	if self.Weapon:Clip1() > 39 then
	local shoot_angle = Vector(0,0,0)
	if self.Owner:IsNPC() then
		if self.Owner:GetEnemy() != NULL && self.Owner:GetEnemy() != nil then
			shoot_angle = self.Owner:GetEnemy():GetPos() - self.Owner:GetPos() 
			//apply accuracy
			shoot_angle = shoot_angle + Vector(math.random(-85,85),math.random(-85,85),math.random(-85,85))*(shoot_angle:Distance(Vector(0,0,0))/1500)
			//print("Shoot angle is:")
			//print(shoot_angle)
			shoot_angle:Normalize()
			//print("Normalized, shoot angle is:")
			//print(shoot_angle)
		else
			return
		end
	else
		shoot_angle = self.Owner:GetAimVector()
	end
	local shoot_pos   = self.Owner:GetPos() + self.Owner:GetRight() * 5 + self.Owner:GetUp() * 50 + shoot_angle * 35
	
	if self.Owner:IsPlayer() then
		shoot_pos   = self.Owner:GetPos() + self.Owner:GetRight() * 5 + self.Owner:GetUp() * 55 + shoot_angle * 35
	end

				local time = 2
self.Weapon:EmitSound("DSBFGC1.wav")
timer.Simple(time, function()
	
	local shot = ents.Create("d3_rocket")
	if (IsValid(shot)) then
	shot:SetModel( "models/dav0r/hoverball.mdl" ) 	
	shot:SetParent(rocket)
	shot:SetPos(shoot_pos)
	shot:SetAngles(shoot_angle:Angle())
	shot:Activate()

	shot:Spawn()
	end
	
	
	
	local phy = shot:GetPhysicsObject()
	if phy:IsValid() then
		phy:ApplyForceCenter((shoot_angle * 10000))
	end
	
	
	self.Owner:MuzzleFlash()
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
	self.Weapon:EmitSound(Sound(self.Primary.Sound))
	//self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0, 0 ))
	if !self.Owner:IsNPC() then
	if (self.Primary.TakeAmmoPerBullet) then
		self:TakePrimaryAmmo(self.Primary.NumShots)
	else
		self:TakePrimaryAmmo(40)
	end
	end
	
		//if not self:CanPrimaryAttack() or self.Owner:WaterLevel() > 2 then return end
	-- If your gun have a problem or if you are under water, you'll not be able to fire

	self.Reloadaftershoot = CurTime() + self.Primary.Delay
	-- Set the reload after shoot to be not able to reload when firering

	//self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
	-- Set next secondary fire after your fire delay

	//self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
	-- Set next primary fire after your fire delay

	-- Emit the gun sound when you fire

	//self:RecoilPower()

	//self:TakePrimaryAmmo(1)
	-- Take 1 ammo in you clip

	if ((game.SinglePlayer() and SERVER) or CLIENT) then
		//self.Weapon:SetNetworkedFloat("LastShootTime", CurTime())
	end
		
	end
  
) 
end
		
end