Reload Time?

I’m making a SWEP which spawns an object when the reload button is pressed. Problem is, when I press the reload button more than one object always spawns (due to the fact that I can’t take my finger off the button in time).

Is there a command like :

 self.Weapon:SetNextPrimaryFire( CurTime() + 5 ) 

But for reloading? So it only reads the reload key once every x seconds?

Sorry if I overlooked something simple. I tried timers, either I did them wrong or Lua just hates me.

use a boolean + a timer, and if you can’t do timers go here, it’s where i learned how to use them from:

Would you suggest a simple timer? For a boolean?

You could just try returning false in the SWEP:Reload() hook, and that might stop it. Just use a CurTime() timer to determine when they can reload.

Yes, but what is the

** self.Weapon:SetNextPrimaryFire**( CurTime() + 5 ) 

equivalent for reloading?

There isn’t. Reloading shouldn’t be an automatic weapon as long as you return false to SWEP:Reload().

[lua]function SWEP:Reload()

// This makes the reload a semi-automatic thing rather than a continuous thing
if ( !self.Owner:KeyPressed( IN_RELOAD ) ) then return end

// Code here


Most efficient logic that you’re looking for.

[lua]SWEP.ReloadTimer = 0
SWEP.ReloadTime = 5

function SWEP:Reload()
if CurTime() - self.ReloadTimer > self.ReloadTime then return false end

SWEP.ReloadTimer = CurTime()
return true


Like this.

Thanks guys, you’ve been great help :slight_smile: