AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hooking Console commands (https://forums.alliedmods.net/showthread.php?t=62135)

RaYden 10-19-2007 10:11

Hooking Console commands
 
Uh ... sorry for the previous misplacement of this topic :oops:, my bad

So generally I want to hook what a player wrights into his console ... and then work with what I hooked, It was suggested to recomply all my plugins but that is to inefficient and time consuming as there are a lot of plugins and many more may be added with ought me realizing ( my server is administered by me and a friend that may temper with the plugins )

So I wanted to make a plugin that will convert any console command that starts with amx_command to admin_command ( demanded by server admins ).

I figured that it would be possible if i do this
Code:

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_clcmd("cmd", "handle_say") <<- is this wright?
  }

public handle_say(id)
{
    new sayz[256],good[256]
    read_args(sayz,255)
    if( containi(sayz, "admin_") != -1 && strlen(sayz) > 6 )
        {
        format(good,255,sayz[6])   
        console_cmd(id,"admin_%s",good)
        }
    return PLUGIN_CONTINUE
}


YamiKaitou 10-19-2007 12:46

Re: Hooking Console commands
 
Try using the native client_command. You don't need to register anything new and you can do it using what you have right there. Just replace public handle_say(id) with public client_command(id). It should work fine, but I am not sure

M249-M4A1 10-19-2007 13:13

Re: Hooking Console commands
 
PHP Code:

register_clcmd("cmd""handle_say") <<- is this wright

handle_say is just a name of the function you want to handle your stuff. Name doesn't matter.

[ --<-@ ] Black Rose 10-19-2007 17:14

Re: Hooking Console commands
 
Why would you possibly want to edit?
I think you have to enter every one of them since "admin_" isn't a cmd...
I belive register_clcmd isn't using containi()...

Wilson [29th ID] 10-19-2007 18:33

Re: Hooking Console commands
 
I think you made a typo in your original code. You executed admin_%s instead of executing amx_%s - making your code do basically nothing.

Code:
public client_command( id ) {     new cmd[64], args[256];     read_argv( 0, cmd, 63 ); // The command is arg 0     read_args( args, 255 ); // Everything else is contained in "args"     if( equali( cmd, "admin_", 6 ) ) // Test if first 6 chars are equal to it     {         replace( cmd, 6, "admin_", "amx_" ); // Replace in the first 6 chars         engclient_cmd( id, "%s %s", cmd, args ); // engclient instead of client since it is going to the engine anyway         return PLUGIN_HANDLED; // block the original command     }     return PLUGIN_CONTINUE; // otherwise do nothing }
That should get the job done.

RaYden 10-19-2007 18:38

Re: Hooking Console commands
 
it was not a typo i thought it was subliminal to express my intention as i made that up not via script editor
Ty for confirming it and helping me :D rep+

Quote:

handle_say is just a name of the function you want to handle your stuff. Name doesn't matter.
I know that it was the "cmd" that i was referring to

RaYden 10-19-2007 19:10

Re: Hooking Console commands
 
hehe looks like i jumped the gun ... looks like i get error when exec command

runtime error 10
replace<> buffer not big enought <7>=6>

Wilson [29th ID] 10-20-2007 15:22

Re: Hooking Console commands
 
Woops! make it replace(...7.... instead of 6

RaYden 10-24-2007 16:17

Re: Hooking Console commands
 
Hehehe i've done that b4 posting ... as i recall it didn't work ... allso the engclient_cmd didn't work either ... witch was cainda weard ... but I've made a working version of the script ( at least this works for me )
I guess ill post it here for other ppl (if they use search)
Quote:

#include <amxmodx>
#include <amxmisc>
#include <string>

#define PLUGIN "admin2amx"
#define VERSION "1.0"
#define AUTHOR "RaYden"


public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
}

public client_command( id ) {

new cmd[64], args[256], cmd1[325]
read_argv( 0, cmd, 63 );
read_args( args, 255 );

if( equali( cmd, "admin_", 6 ) )
{

format(cmd,63,cmd[6])
format(cmd1,324,"amx_%s %s",cmd,args)
client_cmd(id,cmd1)

return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;

}


All times are GMT -4. The time now is 01:20.

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