Charge up weapons

I know I’ve been asking a lot from you guys, but this should be my last question for a while. I am making a SWEP for a friend of mine and he wants it to charge up, and depending on how much it’s charged depends on how big and powerful the explosion is, I am really wanting to make this for him, he will love this after I can finish it.

What is the question?

How would i make a charge up weapon?

Well what do you know how to do?

timer.Simple( 3, function()

Or some kinda, fire())
and, charge())

charge() could be a counter that stops on click release.

use the SWEP:Think() function to make it gather energy as the fire button is being held
if the fire button is no longer being held then release the projectile and set its power to however much energy was gathered
add in additional systems as needed (not firing if not charged long enough etc)

yes, that sounds good, however, i barely use SWEP:Think() so i may need an example of this, please


function SWEP:Think()

that’s not what i mean, could you do a mock of what it could be like using the mouse arguments?

SWEP.Charge = 0
function SWEP:Think()
if !SERVER then return end
if self.Owner:KeyDown(IN_ATTACK) then
self.Charge = math.Clamp(self.Charge + 1, 0, 10)
self:NextThink(CurTime() + 1)
return true
if self.Owner:KeyReleased(IN_ATTACK) then
if self.Charge == 10 then
self:ShootLaserShit() – ?
return true

The above will only be advancing the charge every second; I advise making CurTime() + 1 something like CurTime() + 0.1 so that the increments are more precise.

You could also advance the charge per frame, but this is the simpler method.

I have finally fixed it. I thank you all for your help