[英]Garry's Mod Lua: How to make delay/cooldown?
我故意將 IN_USE 設置為我的主要攻擊,而不是 SWEP:PrimaryAttack。 但是這樣做,它使我可以進行垃圾郵件攻擊,所以我正在尋找它的延遲/冷卻時間。 我環顧了 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 function,只需復制內容並將其添加到您現有的 function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.