Raised This Month: $99 Target: $400

Cooldown for commands?

Post New Thread Reply   
Thread Tools Display Modes
AlliedModders Donor
Join Date: Dec 2012
Location: England
Old 01-11-2014 , 19:09   Re: Cooldown for commands?
Reply With Quote #11

Originally Posted by Mitchell View Post
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];
LastUsed[client] = 0;
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;
Fairly new to sourcepawn scripting so if I'm wrong please don't rip on me ;) haha.

Pasted the code into notepad++ to take a better look regarding what you meant. I'm assuming you asked why he created a new variable "currentTime" instead of using the variable he already made "LastUsed" as they both get the current time.

Took me a little thinking to realise, if he didn't make the new variable "currentTime" then the check wouldn't work as although "LastUsed" is set to the current time as well, it is set after the if statement that checks the time limit meaning at that if statement, "currentTime" and "LastUsed" wouldn't hold the same value.

Forgive me if I'm chatting complete nonsense haha, I just wanted to see if my thoughts were indeed correct or I'm not understanding it completely haha.
sim242 is offline
Send a message via Skype™ to sim242

Thread Tools
Display Modes

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 11:25.

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