AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] A way to hook say commands and using in commands (https://forums.alliedmods.net/showthread.php?t=207106)

^SmileY 01-29-2013 18:24

[TUT] A way to hook say commands and using in commands
 
1 Attachment(s)
Hello, i tried to search any tutorial talking about how to hook a say command and using it as command in console, but i don't found in forum.
This tutorial will about it using a commands in messagemode like: .kick, .ban and other commands if you need.


First, hook a say command or say_team in plugin_init()

PHP Code:

#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    
register_plugin("Say Commands","0.0.1","SmileY");
    
    
register_clcmd("say","cmdSAY");
    
register_clcmd("say_team","cmdSAY");
}

public 
cmdSAY(id)
{
    new 
Args[192];
    
read_args(Args,charsmax(Args));    // Hook the args in a global say or say_team command
    
remove_quotes(Args);
    
    
// if contain a symbol in a begin of string, then use like as console command
    
if(Args[0] == '.' /*Add Here your style of commands, like '.' or '!' for example*/)
    {
        
client_cmd(id,Args);

        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;


The second part basics you need to register command in a plugin_init() using the symbol of your choiced:

PHP Code:

register_clcmd(".kill","cmdKill",ADMIN_SLAY,"<Name | #id>"); 

And finally any function for your registred command:

PHP Code:

// Remember: This function is registred in console and has a .kill command!

public cmdKill(id,level,cid)     // And done, use your function like in console xD
{
    if(!
cmd_access(id,level,cid,2)) return PLUGIN_HANDLED;
    
    new 
Arg[32];
    
read_argv(1,Arg,charsmax(Arg));
    
    new 
iPlayer cmd_target(id,Arg,CMDTARGET_OBEY_IMMUNITY CMDTARGET_ALLOW_SELF CMDTARGET_ONLY_ALIVE);
    
    if(!
iPlayer) return PLUGIN_HANDLED;
    
    new 
szName[2][32];
    
get_user_name(id,szName[0],charsmax(szName[]));
    
    
get_user_name(iPlayer,szName[1],charsmax(szName[]));
    
    
user_silentkill(iPlayer);
    
    
client_print(0,print_chat,"* %s has ninja killed %s",szName[0],szName[1]);
    
    return 
PLUGIN_HANDLED;


Ending:
If your like to register all commands in another plugin its works!



Ps.
The original ideia has been made by Twilight Suzuka in this thread|Plugin http://forums.alliedmods.net/showthread.php?p=549954

ConnorMcLeod 01-30-2013 11:38

Re: [TUT] A way to hook say commands and using in commands
 
You don't need to resend a client_cmd to achieve what you want to do (i agree that register_cmd("say .kill" won't allow you to retrieve arguments but you don't need to delay the execution with a new client_cmd).

^SmileY 01-30-2013 12:00

Re: [TUT] A way to hook say commands and using in commands
 
if you register a clcmd using a symbol '.' in another plugin, this will resend to console like a console command its for one or more plugin compatibility.

i Guess, but how to call a .kill for example without using a new client_cmd ??

ConnorMcLeod 01-30-2013 13:05

Re: [TUT] A way to hook say commands and using in commands
 
Pass args directly to a function, you already know them.


All times are GMT -4. The time now is 19:53.

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