• GM:PrimaryAttack calling 3-4 times while only 1 press of mouse button
    4 replies, posted
As the title says, GM:PrimaryAttack is firing 3-4 times while I only press the mouse button once. [CODE]function SWEP:PrimaryAttack() //self.Weapon:SetNextPrimaryFire( CurTime() + .5 ) local tr = LocalPlayer():GetEyeTrace() local ent = tr.Entity if IsValid( ent ) then net.Start( "LockDoor" ) net.WriteEntity( ent ) net.SendToServer() end end[/CODE] Is there a var i'm not defining? I'm probably missing something really stupid. If you need more info just ask, thanks.
Check IsFirstTimePredicted() to do anything that's only supposed to be done once.
Yup. To clarify lots of stuff are ran multiple times because of prediction, which is a good thing. If you're interested, you can read on [url=https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking]Source Multiplayer Networking[/url] and the specific nature of [url=https://developer.valvesoftware.com/wiki/Prediction]prediction[/url].
Thank you very much, I'm still somewhat new to Lua.
Networking was the one thing that I spent a long time flat out not understanding. It was only until last year that I realized I wasn't programming in a way that vibed well with networking and it took me a little bit to really wrap my brain around how it works and how your code should reflect upon its existence, so no worries if you don't get it right away, especially when you're just starting out.
Sorry, you need to Log In to post a reply to this thread.