Lag(?) only with secondaryAttack.

I have a SWEP which has a primary and secondary attack which for testing purposes both do the same thing. They play the animation, sound, and shoot the bullet. But for some reason the secondary attack seems to lag behind when I use it. So if an enemy player is staffing back and forth, I have to shoot ahead of them to actually hit them. Now when I do this, they do get hurt but I dont see the blood come off of them on my screen. If I shoot them when they are in my crosshair then I see the blood but they don’t get hurt.
With primary attack it works perfectly, I see the blood and they get hurt when they are in my crosshair.

I also tried putting the code in Think() using the IsKeyPressed(IN_ATTACK2) function, and it acted the same way as when it was in secondary attack.

Here is the code that is in BOTH primary and secondary attack
[lua]
self:EmitSound( self.Primary.Sound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:MuzzleFlash()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
// Shoot the bullet
self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
[/lua]

If both sets of code are the same, I can’t see why it’d lag on the secondary and not the primary, try directly copying and pasting the entire attack section in?

It was a straight copy over.
I also do not know why it would matter since the code is correct. To verify that there was a lag, I printed something out in the GM:EntityTakeDamage function and the text is being printed with primary when I shoot with my crosshair over the enemy but not with secondary. It only prints if I compensate for the lag.

I have also had others test it and they have verified this lag issue.

erm, You need to make a check of next time it should be able to be used.

[LUA]
function SWEP:Secondary()
if(self.NextFire>CurTime()then return end
self:EmitSound( self.Primary.Sound )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:MuzzleFlash()
self.Owner:SetAnimation( PLAYER_ATTACK1 )
// Shoot the bullet
self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
self.NextFire = CurTime()+0.5
end
[/LUA]
Edit* A cleaner way to do it would be with self:SetNextSecondaryFire() and self:GetNextSecondaryFire() and also self:CanPrimaryAttack() not sure what the last one checks but you can make your own function of it and run your checks in there and return true or false.

Would that cause some sort of lag like I described above because I am doing something similar to that just not with time. In the actual code it uses mana to fire and the mana has to recharge to fire again, so there is a delay between shots. The code I gave was just test code that I put into both primary and secondary fire to figure out the lag issue.

well with your mana idea, it would still be called alot until it was out of mana, so you would still need a time check.

The delay between shots isn’t the problem here. The way the mana is works fine, trust me, and it doesnt matter anyways since it isn’t part of the code used to test this.

The problem is that what I see on my screen doesnt seem to be registered by the server ONLY for secondary attack. I see blood splatter but no damage is done. Primary attack works fine, I see the blood and it does damage and it has the EXACT same code.
If it was just the blood that was messed up then it wouldn’t be as big of a problem, but the fact that I have to shoot before the player crosses my crosshair to compensate for the lag on secondary attack IS the problem.

Oh I thought you meant it was lagging your game/server. I’m not sure then, I haven’t used CSShootBullet() other than checking that the bullet is firing from and to the correct positions is the only thing I can think of. Other then that I’m not sure.