Raised This Month: $51 Target: $400
 12% 

Command can be activated while on cooldown


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 05-05-2023 , 05:19   Command can be activated while on cooldown
Reply With Quote #1

Hello, so i have this command where you can get coins from database when entering a custom code, but somehow when i activate the code with the command and while the command is on cooldown, it can be activated again from another player. Here is what im using -

Any help would be appreciated

PHP Code:
public RedeemCodeCommand(id)
{
    if(
read_argc()<2){
      
client_print(idprint_console"Usage: bio_bank_activate <code>");
      return 
PLUGIN_HANDLED;
   }

    if (
get_gametime() - g_lastCodeUseTime 6)
    {
        
client_print(idprint_console"[BANZUKE] Wait a bit before using this command...")
        return 
PLUGIN_HANDLED;
    }

    
g_lastCodeUseTime get_gametime()

    new 
szPromoCode[PLATFORM_MAX_PATH]

    
read_args(szPromoCodecharsmax(szPromoCode))
    
remove_quotes(szPromoCode)
    
trim(szPromoCode)

    new 
szQuery[MAX_FMT_LENGTH]

    
formatex(szQuerycharsmax(szQuery), "SELECT * FROM `bank` WHERE `activation_code` = '%s'"szPromoCode)
    
SQL_ThreadQuery(g_SqlTuple"ActivePromoCode_QueryHandler"szQuery)

    return 
PLUGIN_CONTINUE

HowToRuski is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2023 , 20:54   Re: Command can be activated while on cooldown
Reply With Quote #2

You already have a thread for this exact same question, no need to create another thread.

Did you try debugging the code? Try printing the value of "g_lastCodeUseTime", "get_gametime()", and "get_gametime() - g_lastCodeUseTime" so you can see what is going on while the plugin is running.

Another thing that I do often is to create a small plugin with only the small functionality that you're trying to test so that you can make sure that nothing else in your actual plugin is causing the issue somehow. Basically, prove that the logic works in a test plugin before putting it in your main one.
__________________
fysiks is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-13-2023 , 12:25   Re: Command can be activated while on cooldown
Reply With Quote #3

Quote:
Originally Posted by HowToRuski View Post
Hello, so i have this command where you can get coins from database when entering a custom code, but somehow when i activate the code with the command and while the command is on cooldown, it can be activated again from another player. Here is what im using -

Any help would be appreciated

PHP Code:
public RedeemCodeCommand(id)
{
    if(
read_argc()<2){
      
client_print(idprint_console"Usage: bio_bank_activate <code>");
      return 
PLUGIN_HANDLED;
   }

    if (
get_gametime() - g_lastCodeUseTime 6)
    {
        
client_print(idprint_console"[BANZUKE] Wait a bit before using this command...")
        return 
PLUGIN_HANDLED;
    }

    
g_lastCodeUseTime get_gametime()

    new 
szPromoCode[PLATFORM_MAX_PATH]

    
read_args(szPromoCodecharsmax(szPromoCode))
    
remove_quotes(szPromoCode)
    
trim(szPromoCode)

    new 
szQuery[MAX_FMT_LENGTH]

    
formatex(szQuerycharsmax(szQuery), "SELECT * FROM `bank` WHERE `activation_code` = '%s'"szPromoCode)
    
SQL_ThreadQuery(g_SqlTuple"ActivePromoCode_QueryHandler"szQuery)

    return 
PLUGIN_CONTINUE

Code:
public RedeemCodeCommand(id)
{
    if (read_argc() < 2)
    {
        client_print(id, print_console, "Usage: bio_bank_activate <code>");
        return PLUGIN_HANDLED;
    }

    new szPromoCode[PLATFORM_MAX_PATH];
    read_args(szPromoCode, charsmax(szPromoCode));
    remove_quotes(szPromoCode);
    trim(szPromoCode);

    new cooldownTime = g_cooldowns[id]; // get the cooldown time for this player
    if (get_gametime() - cooldownTime < 6)
    {
        client_print(id, print_console, "[BANZUKE] Wait a bit before using this command...");
        return PLUGIN_HANDLED;
    }

    g_cooldowns[id] = get_gametime(); // set the new cooldown time for this player

    new szQuery[MAX_FMT_LENGTH];
    
    formatex(szQuery, charsmax(szQuery), "SELECT * FROM `bank` WHERE `activation_code` = '%s'", szPromoCode);
    SQL_ThreadQuery(g_SqlTuple, "ActivePromoCode_QueryHandler", szQuery);

    return PLUGIN_CONTINUE;
}
"as you mentioned that other players can activate the code while the command is on cooldown for one player"
cooldown time for each player separately, instead of using a global variable g_lastCodeUseTime.
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
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:10.


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