• SWEP Coding help
    4 replies, posted
Ok, so I made this swep which plays a sound then shoots the weapon, BUT if you click it multiple times, it plays the sound multiple times then shoots it a multiple times, anyone know how to fix? [CODE]function SWEP:PrimaryAttack() timer.Simple(1.4, function() self:PrimaryFire() end ) self.Weapon:EmitSound("punch/punchingswag.mp3") end [/CODE]
Why are you using a timer there? Then you can still spam it. Just put SWEP.Primary(or Secondary).Delay = 1.4 and in the PrimaryAttack use [lua] if ( !self:CanPrimaryAttack() ) then return false; end[/lua]
[QUOTE=Busan1;43108710]Why are you using a timer there? Then you can still spam it. Just put SWEP.Primary(or Secondary).Delay = 1.4 and in the PrimaryAttack use [lua] if ( !self:CanPrimaryAttack() ) then return false; end[/lua][/QUOTE] I don't know if I'm doing it wrong, but I did that and it still the same, this is what I have [CODE] function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then self.Weapon:EmitSound("punch/punchingswag.mp3") return false; end [/CODE] Also, I'm trying to make it play a sound then shoot.
Did you consider your logic at all? If you were to read that out, it would go, "If I can't Primary Attack, then play the primary attack sound"
I believe this is what you are after [url]http://wiki.garrysmod.com/page/Global/IsFirstTimePredicted[/url]
Sorry, you need to Log In to post a reply to this thread.