Raised This Month: $ Target: $400
 0% 

Hooking clcmd extra param


Post New Thread Reply   
 
Thread Tools Display Modes
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 07-06-2016 , 11:10   Re: Hooking clcmd extra param
Reply With Quote #11

Quote:
Originally Posted by Depresie View Post
Any chance of adding an optional extra param to an already existing command?
PHP Code:

public plugin_init()
{
      
register_clcmd("jointeam""handle_command")
}

public function(
id)
{
             
handle_command(idtrue)
}
public 
handle_command(idexception)
{
        if(!
exception)
        {
                  return 
PLUGIN_HANDLED;
        }
        

I'm not sure what are u trying to do, but take a look at this code:
PHP Code:
#include <amxmodx>

public plugin_init()
{
      
register_clcmd("jointeam""clcmd_jointeam")
}

public 
clcmd_jointeam(id)
{
    return 
handle_commands(idfalse); // true = allow team change | false = block team change
}


public 
my_function(id)
{
    
handle_commands(idtrue);
}

handle_commands(idbool:exception=true)
{
    if(!
exception)
        return 
PLUGIN_HANDLED;
        
    return 
PLUGIN_CONTINUE;

KiLLeR. is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-06-2016 , 11:17   Re: Hooking clcmd extra param
Reply With Quote #12

I got it done with checking teams and stuff..
But now i have another thing that bothers me, is there anyway to get rid of "command is unavailable for you at this point" ? not only the message
__________________
Depresie is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-06-2016 , 21:58   Re: Hooking clcmd extra param
Reply With Quote #13

Quote:
Originally Posted by Depresie View Post
I got it done with checking teams and stuff..
But now i have another thing that bothers me, is there anyway to get rid of "command is unavailable for you at this point" ? not only the message
You have to "handle" the command for that message to not show. I.e. return PLUGIN_HANDLED or PLUGIN_HANDLED_MAIN. There is a thread that explains the difference between the different standard return values.
__________________

Last edited by fysiks; 07-06-2016 at 21:59.
fysiks is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-08-2016 , 16:23   Re: Hooking clcmd extra param
Reply With Quote #14

Is there any way to retrieve the value used for the command in this hook?
Im talking about this value -> "jointeam 2"


PHP Code:
public plugin_init()
{
      
register_clcmd("jointeam""clcmd_jointeam")
}

public 
clcmd_jointeam(id)
{

__________________
Depresie is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 07-08-2016 , 16:45   Re: Hooking clcmd extra param
Reply With Quote #15

Quote:
Originally Posted by Depresie View Post
Is there any way to retrieve the value used for the command in this hook?
Im talking about this value -> "jointeam 2"
PHP Code:
public plugin_init()
{
      
register_clcmd("jointeam""clcmd_jointeam")
}

public 
clcmd_jointeam(id)
{
      new 
arg[2]
      
read_argv(1argcharsmax(arg));
      new 
teamIndex str_to_num(arg)

      [do 
what you want here]

      return 
PLUGIN_CONTINUE

2 will be stored in teamIndex

Untested.
__________________

Last edited by gabuch2; 07-08-2016 at 20:56.
gabuch2 is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-08-2016 , 17:45   Re: Hooking clcmd extra param
Reply With Quote #16

Thanks, but should the size of the arg be larger?

I mean there is 1 - T / 2 - CT / 3 - SP / 5 - Auto Assign
__________________
Depresie is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 07-08-2016 , 18:05   Re: Hooking clcmd extra param
Reply With Quote #17

Quote:
Originally Posted by Depresie View Post
Thanks, but should the size of the arg be larger?

I mean there is 1 - T / 2 - CT / 3 - SP / 5 - Auto Assign
Well it's a string with 1 char long, so all teams can be accepted as long the argument is an 1-digit integer.

I don't know if you can put, for example jointeam terrorists, if so, you need to increase the size of arg[] and modify the snippet accordingly.
__________________

Last edited by gabuch2; 07-08-2016 at 18:06.
gabuch2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-08-2016 , 18:36   Re: Hooking clcmd extra param
Reply With Quote #18

Quote:
Originally Posted by Shattered Heart Lynx View Post
Well it's a string with 1 char long, so all teams can be accepted as long the argument is an 1-digit integer.
No, "new arg[1]" is actually a string of zero length. Also, "maxchars" does not exist, it is "charsmax".

Please at least compile your code before posting it since you are not entirely familiar with AMX Mod X scripting. Even better would be actually testing it.

Quote:
Originally Posted by Depresie View Post
Is there any way to retrieve the value used for the command in this hook?
Im talking about this value -> "jointeam 2"


PHP Code:
public plugin_init()
{
      
register_clcmd("jointeam""clcmd_jointeam")
}

public 
clcmd_jointeam(id)
{

All commands registered in that manner use the same method for retrieving the associated arguments. All arguments will be strings and you should size the string such that it will account for all possible values.

If you happen to look in a plugin like admincmd.sma you'd see how it's done.
__________________

Last edited by fysiks; 07-08-2016 at 18:49.
fysiks is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 07-08-2016 , 20:57   Re: Hooking clcmd extra param
Reply With Quote #19

fuck I forgot the "end of string" character occupies a slot in the array.

And yes, I always mix up charsmax and maxchars, and I end up fixing the error when I throw the sma in the compiler.

Edited.
__________________
gabuch2 is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 07-09-2016 , 02:41   Re: Hooking clcmd extra param
Reply With Quote #20

Tyvm
__________________
Depresie 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 15:05.


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