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

[TUT] A way to hook say commands and using in commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-29-2013 , 18:24   [TUT] A way to hook say commands and using in commands
Reply With Quote #1

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
Attached Files
File Type: sma Get Plugin or Get Source (say_commands.SMA - 790 views - 1.3 KB)
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 05-22-2013 at 08:50.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-30-2013 , 11:38   Re: [TUT] A way to hook say commands and using in commands
Reply With Quote #2

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).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 01-30-2013 , 12:00   Re: [TUT] A way to hook say commands and using in commands
Reply With Quote #3

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

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-30-2013 , 13:05   Re: [TUT] A way to hook say commands and using in commands
Reply With Quote #4

Pass args directly to a function, you already know them.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 10:42.


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