Raised This Month: $ Target: $400
 0% 

Limit for a command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-20-2009 , 20:45   Limit for a command
Reply With Quote #1

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?
BOYSplayCS is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 08-20-2009 , 21:24   Re: Limit for a command
Reply With Quote #2

I think with this:

PHP Code:
new counter

...

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

by joaquimandrade
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-20-2009 , 22:09   Re: Limit for a command
Reply With Quote #3

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;
    }

__________________
Bugsy is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-20-2009 , 22:01   Re: Limit for a command
Reply With Quote #4

But, that's not putting a limit on the number of times someone can use that command.
BOYSplayCS is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-20-2009 , 22:21   Re: Limit for a command
Reply With Quote #5

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?
BOYSplayCS is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-20-2009 , 22:36   Re: Limit for a command
Reply With Quote #6

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.
__________________
Bugsy is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 08-20-2009 , 22:38   Re: Limit for a command
Reply With Quote #7

Ah, I get it now! Thank you.
BOYSplayCS is offline
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-20-2009 , 22:56   Re: Limit for a command
Reply With Quote #8

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.
__________________
Bad_Bud is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 08-21-2009 , 10:37   Re: Limit for a command
Reply With Quote #9

Quote:
Originally Posted by Bad_Bud View Post
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.
SnoW is offline
Send a message via MSN to SnoW
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 08-21-2009 , 12:03   Re: Limit for a command
Reply With Quote #10

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?
__________________

Last edited by Bad_Bud; 08-21-2009 at 12:14.
Bad_Bud is offline
Reply


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


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