Raised This Month: $ Target: $400
 0% 

Hooking Console commands


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RaYden
Member
Join Date: Sep 2007
Old 10-19-2007 , 10:11   Hooking Console commands
Reply With Quote #1

Uh ... sorry for the previous misplacement of this topic , 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
}

Last edited by RaYden; 10-19-2007 at 10:20.
RaYden is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-19-2007 , 12:46   Re: Hooking Console commands
Reply With Quote #2

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-19-2007 , 13:13   Re: Hooking Console commands
Reply With Quote #3

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.
__________________
M249-M4A1 is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 10-19-2007 , 17:14   Re: Hooking Console commands
Reply With Quote #4

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()...
[ --<-@ ] Black Rose is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-19-2007 , 18:33   Re: Hooking Console commands
Reply With Quote #5

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

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
RaYden
Member
Join Date: Sep 2007
Old 10-19-2007 , 18:38   Re: Hooking Console commands
Reply With Quote #6

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

Last edited by RaYden; 10-19-2007 at 18:43.
RaYden is offline
RaYden
Member
Join Date: Sep 2007
Old 10-19-2007 , 19:10   Re: Hooking Console commands
Reply With Quote #7

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>
RaYden is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 10-20-2007 , 15:22   Re: Hooking Console commands
Reply With Quote #8

Woops! make it replace(...7.... instead of 6
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
RaYden
Member
Join Date: Sep 2007
Old 10-24-2007 , 16:17   Re: Hooking Console commands
Reply With Quote #9

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;

}
RaYden 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 01:20.


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