• Help Cooldown SWEP
    7 replies, posted
I need help with this one thing i have made on my server, a stick that freezes a player and unfreezes 5 seconds later. So far its working the only problem is their is no cooldown so it can be hit like 10 times on one player and keep them frozen. I need help making a cooldown almost like a reload. I have no clue how to start it off. I cant paste all the code here because it is from DarkRP and idk if i could get in trouble doing so. Its a copy of the stunstick except it has this code under the function SWEP:DoAttack(dmg) [CODE] ent:Freeze( true ) ent:ChatPrint( "You have been frozen by a Government Official!" ) self.Owner:ChatPrint( "You have froze this player!" ) timer.Simple( 5, function() ent:Freeze( false ) ent:ChatPrint( "You have thawed out! (UnFrozen)" ) self.Owner:ChatPrint( "This player has thawed out! (UnFroze)" ) end ) [/CODE]
This is how you would do it. [CODE]self:SetNextAttack( 1 )[/CODE]
Didn't work any other solutions? [CODE] ent:Freeze( true ) ent:ChatPrint( "You have been frozen by a Government Official!" ) self.Owner:ChatPrint( "You have froze this player!" ) timer.Simple( 5, function() ent:Freeze( false ) ent:ChatPrint( "You have thawed out! (UnFrozen)" ) self.Owner:ChatPrint( "This player has thawed out! (UnFroze)" ) end ) self:SetNextAttack( 1 ) [/CODE] and [CODE] function SWEP:PrimaryAttack() BaseClass.PrimaryAttack(self) self:SetNextSecondaryFire(self:GetNextPrimaryFire()) self:DoAttack(10) self:SetNextAttack( 1 ) end function SWEP:SecondaryAttack() BaseClass.PrimaryAttack(self) self:SetNextSecondaryFire(self:GetNextPrimaryFire()) self:DoAttack(10) self:SetNextAttack( 1 ) end [/CODE]
Heres how i'm doing it here. Let me clue you in on a little secret. Theres this big book on the web called the wiki with a bunch of documentation on what each class/hook/blah blah does. Theres even tutorials! In fact, i even pulled this straight from a tutorial because i am learning myself. [lua] self.Weapon:SetNextSecondaryFire( CurTime() + 1 ) --Adds a one second delay for the shots [/lua] If you're looking how to prevent people from spamming the swep on a player then i'm out of luck. Good luck [b]eating[/b] i mean learning.
I tried both [CODE] self:SetNextSecondaryFire( CurTime() + 50 ) [/CODE] and [CODE] self.Weapon:SetNextSecondaryFire( CurTime() + 50 ) [/CODE] Still no good result any others? Here is the full code : [url]http://pastebin.com/maJ3rR5q[/url]
[QUOTE=Lucifer1;51076008]I need help with this one thing i have made on my server, a stick that freezes a player and unfreezes 5 seconds later. So far its working the only problem is their is no cooldown so it can be hit like 10 times on one player and keep them frozen. I need help making a cooldown almost like a reload. I have no clue how to start it off. I cant paste all the code here because it is from DarkRP and idk if i could get in trouble doing so. Its a copy of the stunstick except it has this code under the function SWEP:DoAttack(dmg) [CODE] ent:Freeze( true ) ent:ChatPrint( "You have been frozen by a Government Official!" ) self.Owner:ChatPrint( "You have froze this player!" ) timer.Simple( 5, function() ent:Freeze( false ) ent:ChatPrint( "You have thawed out! (UnFrozen)" ) self.Owner:ChatPrint( "This player has thawed out! (UnFroze)" ) end ) [/CODE][/QUOTE] have you tried under the part where you freeze them to check if there already frozen? somthing like [CODE] if target:IsFlagSet(64) == false then ent:Freeze( true ) ent:ChatPrint( "You have been frozen by a Government Official!" ) self.Owner:ChatPrint( "You have froze this player!" ) end [/CODE] fixed it better for you just replace target with what ever your targets ent is. this checks the flag on the player to see if there frozen.
Me trying to fix it came across something weird heres the code [CODE] function SWEP:PrimaryAttack() self:SecondaryAttack() end function SWEP:SecondaryAttack() BaseClass.PrimaryAttack(self) self:SetNextSecondaryFire(CurTime() + 5) self:SetNextPrimaryFire(CurTime() + 5) self:DoAttack(10) end [/CODE] The primary can fire every second but the secondary cant fire untill 5 seconds after the primary or 5 seconds after the last secondary fire any reason? EDIT : Heres the full code -> [url]http://pastebin.com/MUD4WzwU[/url] My goal is to make the swep take 5-10 seconds after hitting once to be able to hit agian
[QUOTE=Lucifer1;51082088]Me trying to fix it came across something weird heres the code [CODE] function SWEP:PrimaryAttack() self:SecondaryAttack() end function SWEP:SecondaryAttack() BaseClass.PrimaryAttack(self) self:SetNextSecondaryFire(CurTime() + 5) self:SetNextPrimaryFire(CurTime() + 5) self:DoAttack(10) end [/CODE] The primary can fire every second but the secondary cant fire untill 5 seconds after the primary or 5 seconds after the last secondary fire any reason? EDIT : Heres the full code -> [url]http://pastebin.com/MUD4WzwU[/url] My goal is to make the swep take 5-10 seconds after hitting once to be able to hit agian[/QUOTE] with your primary all your doing is calling your secondary instead try somthing like this. [CODE] function SWEP:PrimaryAttack() self:SetNextPrimaryFire(CurTime() + 5) self:SetNextSecondaryFire(CurTime() + 5) self:DoAttack(10) end function SWEP:SecondaryAttack() self:SetNextPrimaryFire(CurTime() + 5) self:SetNextSecondaryFire(CurTime() + 5) self:DoAttack(10) end [/CODE] this should make sure that both prim and secd are set to the same time.
Sorry, you need to Log In to post a reply to this thread.