AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Limit for a command (https://forums.alliedmods.net/showthread.php?t=101109)

BOYSplayCS 08-20-2009 20:45

Limit for a command
 
How would you create a limit for a command?

Example:

If I wanted to put a limit on the number of times someone can say /blah per round, how would I do that?

Alucard^ 08-20-2009 21:24

Re: Limit for a command
 
I think with this:

PHP Code:

new counter

...

public 
YourFunction()
{
          if(++
counter == 2)
          { 
               
// Command has been used 2 times
          
}
   
// normal


by joaquimandrade

BOYSplayCS 08-20-2009 22:01

Re: Limit for a command
 
But, that's not putting a limit on the number of times someone can use that command.

Bugsy 08-20-2009 22:09

Re: Limit for a command
 
Use return PLUGIN_HANDLED. The only catch is your blocker plugin must be placed before the plugin containing the function in plugins.ini

Tested with my aimbot detection plugin

plugins.ini:
Code:

thisplugin.amxx
aimbotdetet.amxx

PHP Code:

new g_iSaid33 ];

public 
plugin_init() 
{
    
register_concmd"amx_aimwatch" "HookCmd" );
}

public 
HookCmdid )
{
    if ( ++
g_iSaidid ] >= )
    {
        
client_printid print_center"BLOCKED" );
        return 
PLUGIN_HANDLED;
    }



BOYSplayCS 08-20-2009 22:21

Re: Limit for a command
 
I don't get how that works - it seems like you're only creating a variable and then checking if it is greater than or equal to 3.

Explain, please?

Bugsy 08-20-2009 22:36

Re: Limit for a command
 
In this example I am creating a function to react when a console command is called, just as you normally do when creating a plugin. In this case, we want to block the "amx_aimwatch" command from being called after 3 times so we return PLUGIN_HANDLED in the blocker plugin. Console commands hit the list of plugins in order as listed in plugins.ini so as long as we place the blocker plugin before the plugin containing the function then we can prevent it from reaching the function plugin.

BOYSplayCS 08-20-2009 22:38

Re: Limit for a command
 
Ah, I get it now! Thank you.

Bad_Bud 08-20-2009 22:56

Re: Limit for a command
 
I wouldn't recommend putting a ++ in a conditional statement... I just think it makes the code a little harder to follow at no benefit.

SnoW 08-21-2009 10:37

Re: Limit for a command
 
Quote:

Originally Posted by Bad_Bud (Post 907526)
I wouldn't recommend putting a ++ in a conditional statement... I just think it makes the code a little harder to follow at no benefit.

There really is a benefit. If you would increase it separately the variable would be loaded twice.

Bad_Bud 08-21-2009 12:03

Re: Limit for a command
 
Is there any proof of the actual machine cycles on that? Wouldn't a for loop compared to a while be slower because the ++ is applied separately from the comparison? I've never seen anyone refer to this as an optimization... links for Bad_Bud please?

If you change a variable and try to compare it immediately afterward, isn't that going to create a stall anyway?


All times are GMT -4. The time now is 15:11.

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