Garry's Mod Lua:如何制作delay/cooldown?

Garry's Mod Lua: How to make delay/cooldown?

我有意将 IN_USE 设置为我的主要攻击而不是 SWEP:PrimaryAttack。但是这样做,它已经成为我可以进行垃圾邮件攻击的地方,所以我正在寻找一个 delay/cooldown 到它。我环顾了 CurTime 之类的东西;但是,我已经有一个 IF then Else 语句,但不确定如何在其中使用 CurTime 编码。

function SWEP:Think()
    if self.Owner:KeyDown(IN_USE) && self.Owner:IsPlayer() then
        local Angles = self.Owner:GetAngles()

        self:SendAnim()   
        self:SetWeaponHoldType( "melee" )
        timer.Simple(0.1, function() 
            if not IsValid(self) or not self.Owner:Alive() then return end self.Weapon:EmitSound( "weapons/iceaxe/iceaxe_swing1.wav" ) self.Weapon:PrimarySlash() self.Owner:SetAnimation( PLAYER_ATTACK1 ) end )
        timer.Simple(0.35, function() 
            if not IsValid(self) or not self.Owner:Alive() then return end self.Weapon:EmitSound( "weapons/iceaxe/iceaxe_swing1.wav" ) self.Weapon:PrimarySlash() end)
        timer.Simple(0.5, function() if not IsValid(self) or not self.Owner:Alive() then return end self:SetWeaponHoldType( "knife" ) end)
    end
function SWEP:Initialize()
    self.NextUseTime = CurTime()
    self.UseDelay = 1.5
end

function SWEP:Think()
    if self.Owner:KeyDown(IN_USE) && self.Owner:IsPlayer() && ( self.NextUseTime - CurTime() <= 0 ) then
        local Angles = self.Owner:GetAngles()

        self:SendAnim()   
        self:SetWeaponHoldType( "melee" )
        timer.Simple(0.1, function() 
            if not IsValid(self) or not self.Owner:Alive() then return end self.Weapon:EmitSound( "weapons/iceaxe/iceaxe_swing1.wav" ) self.Weapon:PrimarySlash() self.Owner:SetAnimation( PLAYER_ATTACK1 ) end )
        timer.Simple(0.35, function() 
            if not IsValid(self) or not self.Owner:Alive() then return end self.Weapon:EmitSound( "weapons/iceaxe/iceaxe_swing1.wav" ) self.Weapon:PrimarySlash() end)
        timer.Simple(0.5, function() if not IsValid(self) or not self.Owner:Alive() then return end self:SetWeaponHoldType( "knife" ) end)

        self.NextUseTime = CurTime() + self.UseDelay
    end

如果您已经有一个 SWEP:Initialize 函数,只需复制内容并将其添加到您现有的函数中。