I've been racking my mind for a few days over a good way to do this. I know a bit of Java, so I was trying to apply my knowledge of that here. I just want to make something that uses the same function for bullet firing for two different firemodes, which I can just about figure out without causing a migraine. But one of the firemodes I was trying to add was a simple 3-round burst fire. Which obviously isn't in by default.
Currently I have a for loop, which repeats the firing function 3 times perfectly. But I need to add a delay between shots. Is the best place to do this in the loop, or in the firing function? Any advice given is welcomed.
As of now the firing function is just the CS: S base one. I need to work on something better at some point, but this is more important.
Tried using timers, but it won't accept the parameters for the shooting function. Heres the code if anyone can figure it out from this;
[lua]
--3 Round burst fire.
function SWEP:PrimaryAttack()
if debug then
print("Attack1")
end
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
if (!self:CanPrimaryAttack()) then return end
self.Weapon:EmitSound( self.Primary.Sound )
self:TakePrimaryAmmo(3)
if ( (SinglePlayer() && SERVER) || CLIENT ) then
self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
end
timer.Create("burstTimer", self.Primary.Delay, 3, self:ShootBullet, self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone)
end
--Shoots things.
function SWEP:ShootBullet(dmg, recoil, numbul, cone)
numbul = numbul or 1
cone = cone or 0.01
local bullet = {}
bullet.Num = numbul
bullet.Src = self.Owner:GetShootPos() --Where does it come from?
bullet.Dir = self.Owner:GetAimVector() --Where is it headed?
bullet.Spread = Vector( cone, cone, 0 ) --How accurate are we talking?
bullet.Tracer = 4 --How many should actually show?
bullet.Force = 5 --lolpunt
bullet.Damage = dmg --Uhhhhh...
self.Owner:FireBullets( bullet )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) --View model animation
self.Owner:MuzzleFlash() --Crappy muzzle light
self.Owner:SetAnimation( PLAYER_ATTACK1 ) --3rd Person Animation
end
[/lua]
self.ShootBullet , self as the first two arguments
[QUOTE=hexpunK;23212249]Tried using timers, but it won't accept the parameters for the shooting function. Heres the code if anyone can figure it out from this;
[lua]
--3 Round burst fire.
function SWEP:PrimaryAttack()
if debug then
print("Attack1")
end
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
if (!self:CanPrimaryAttack()) then return end
self.Weapon:EmitSound( self.Primary.Sound )
self:TakePrimaryAmmo(3)
if ( (SinglePlayer() && SERVER) || CLIENT ) then
self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
end
timer.Create("burstTimer", self.Primary.Delay, 3, self:ShootBullet, self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone)
end
--Shoots things.
function SWEP:ShootBullet(dmg, recoil, numbul, cone)
numbul = numbul or 1
cone = cone or 0.01
local bullet = {}
bullet.Num = numbul
bullet.Src = self.Owner:GetShootPos() --Where does it come from?
bullet.Dir = self.Owner:GetAimVector() --Where is it headed?
bullet.Spread = Vector( cone, cone, 0 ) --How accurate are we talking?
bullet.Tracer = 4 --How many should actually show?
bullet.Force = 5 --lolpunt
bullet.Damage = dmg --Uhhhhh...
self.Owner:FireBullets( bullet )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) --View model animation
self.Owner:MuzzleFlash() --Crappy muzzle light
self.Owner:SetAnimation( PLAYER_ATTACK1 ) --3rd Person Animation
end
[/lua][/QUOTE]
Well you can just use a timer.simple rather than creating your own timer.
Also, self:TakePrimaryAmmo(3). Won't it take 3 bullets instantly? What if you reload in the middle of the burst?
Put this in the fire function:
[lua]
//put burstfire = 0 up top somewhere
self:SetNextPrimaryFire( CurTime() + SWEP.Primary.Delay )
burstfire = burstfire + 1 //Burst code, betches (Kinda buggy with npcs, but awesome)
if (burstfire < 2) then
timer.Simple( .08, self.PrimaryAttack, self )
end
if (burstfire >= 2) then
burstfire = 0
end
[/lua]
Its just the code I used for my AN94 npc swep.
I'm not expecting the player to be reloading mid-firing. But that might be a good thing to add as a precaution. I'll try it out when I get back to my PC.
I know this is old, but was it ever fully resolved? I've tried adapting the code shown here, but to no avail.
[QUOTE=blathebiste;50815333]I know this is old[/QUOTE]
This isn't old, it's God damm ancient. Please make a new thread as this thread is by all means dead af.
Sorry, you need to Log In to post a reply to this thread.