Raised This Month: $ Target: $400
 0% 

Cooldown for commands?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 01-01-2013 , 18:57   Cooldown for commands?
Reply With Quote #1

I've seen a method to use cooldown for commands without having to create any timer.
Somebody has it?
__________________
retired
shavit is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-01-2013 , 19:03   Re: Cooldown for commands?
Reply With Quote #2

if you don't use a timer, then you need to assign variable[client] the current time when they use a trigger, then don't allow it until currenttime-variable[client](currenttime) is >= n time units.

improper functions, for example only...
PHP Code:
new LastUsed[MAXPLAYERS+1];
public 
OnClientPutInServer(client){
    
LastUsed[client] = 0;
}
public 
Action:Command_MyCommand(blahblahclient){
    new 
currentTime GetTime();
    if (
currentTime LastUsed[client] < 15) return Plugin_Handled// 15 seconds hasn't passed yet, don't allow

    
LastUsed[client] = GetTime();
    
// Rest of command code here

__________________
View my Plugins | Donate

Last edited by TnTSCS; 01-01-2013 at 19:08.
TnTSCS is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 01-01-2013 , 19:16   Re: Cooldown for commands?
Reply With Quote #3

I have posted an example here some time ago.

Yours sincerely
Impact
__________________
Impact123 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-01-2013 , 19:19   Re: Cooldown for commands?
Reply With Quote #4

GMTA
__________________
View my Plugins | Donate
TnTSCS is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-02-2013 , 10:49   Re: Cooldown for commands?
Reply With Quote #5

I can't believe nobody started talking about creating a timer for this lol [/sarcasm]
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-02-2013 , 11:49   Re: Cooldown for commands?
Reply With Quote #6

Quote:
Originally Posted by TnTSCS View Post
if you don't use a timer, then you need to assign variable[client] the current time when they use a trigger, then don't allow it until currenttime-variable[client](currenttime) is >= n time units.

improper functions, for example only...
PHP Code:
new LastUsed[MAXPLAYERS+1];
public 
OnClientPutInServer(client){
    
LastUsed[client] = 0;
}
public 
Action:Command_MyCommand(blahblahclient){
    new 
currentTime GetTime();
    if (
currentTime LastUsed[client] < 15) return Plugin_Handled// 15 seconds hasn't passed yet, don't allow

    
LastUsed[client] = GetTime();
    
// Rest of command code here

Why'd you assign a variable, and not assign the LasUsed variable the local variable you created?
LastUsed[client] = GetTime(); -> LastUsed[client] = currentTime;
Mitchell is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-02-2013 , 19:15   Re: Cooldown for commands?
Reply With Quote #7

because... "improper functions, for example only..."

I hand wrote that, while at work, being distracted... anyways, it was meant to help the OP get the gist
__________________
View my Plugins | Donate
TnTSCS is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-02-2013 , 21:41   Re: Cooldown for commands?
Reply With Quote #8

Quote:
Originally Posted by TnTSCS View Post
I hand wrote that, while at work, being distracted
Excuses, Excuses
Mitchell is offline
TheINCDope
Member
Join Date: Apr 2013
Old 07-02-2013 , 13:32   Re: Cooldown for commands?
Reply With Quote #9

Quote:
Originally Posted by TnTSCS View Post
if you don't use a timer, then you need to assign variable[client] the current time when they use a trigger, then don't allow it until currenttime-variable[client](currenttime) is >= n time units.

improper functions, for example only...
PHP Code:
new LastUsed[MAXPLAYERS+1];
public 
OnClientPutInServer(client){
    
LastUsed[client] = 0;
}
public 
Action:Command_MyCommand(blahblahclient){
    new 
currentTime GetTime();
    if (
currentTime LastUsed[client] < 15) return Plugin_Handled// 15 seconds hasn't passed yet, don't allow

    
LastUsed[client] = GetTime();
    
// Rest of command code here

What if I want to make the cool down start from the begining of round, and wouldnt repeat, only 15 seccond passed and u can use command how mutch times u want? and after respawn in next round the cooldown would be started again.
TheINCDope is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 07-02-2013 , 19:20   Re: Cooldown for commands?
Reply With Quote #10

So, from what I'm understanding, you want to not allow the use of the command until 15 seconds has passed after they spawn?

If so, then:
again, improper syntax, just example:
PHP Code:
new LastUsed[MAXPLAYERS+1];
public 
OnPluginStart() {
    
HookEvent("player_spawn"EventPlayerSpawn);
}
 
public 
Action:EventPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast){
    new 
client GetClientOfUserId(GetEventInt(event"userid")); 
    
LastUsed[client] = 0

public 
Action:Command_MyCommand(blahblahclient){ 
    new 
currentTime GetTime(); 
    if (
currentTime LastUsed[client] < 15) return Plugin_Handled// 15 seconds hasn't passed since player has spawned, don't allow 

    
LastUsed[client] = currentTime
    
// Rest of command code here 

__________________
View my Plugins | Donate

Last edited by TnTSCS; 07-02-2013 at 19:21.
TnTSCS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode