SWEP is Running Primary Attack 3-4 times instead of once per iteration?
3 replies, posted
Hey guys. I'm trying to make a SWEP, and here's my code:
[lua]SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 1
function SWEP:PrimaryAttack()
MsgN("Hello!")
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
end[/lua]
Now, according to this code, every [B]ONE[/B] second it should print Hello to my console.
This is not what happens at all. Every [B]ONE[/B] second, it prints hello 3 -4 times. I know how this is possible, essentially it's going through the Primary Attack function 3-4 times before a second has passed.
How do I stop it from doing this? I need it to run whats within SWEP:PrimaryAttack() ONCE per mouse1 click, and not how many times it can before the delay is reached...
Anyone?
Try adding "if ( CLIENT ) then return end" just before your MsgN function.
You can also do:
[code]if not IsFirstTimePredicted( ) then
return
end[/code]
Which should solve it - I'd bet the client is running the function multiple times for prediction purposes.
-snip-
Sorry, you need to Log In to post a reply to this thread.