AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with hook_say (https://forums.alliedmods.net/showthread.php?t=131904)

Ex3cuTioN 07-10-2010 04:41

Problem with hook_say
 
LOL

Every word i say in chat, me or a random player takes like command in console.

If i write in chat "slay player" it will write in my console "amx_slay player" and works for any random player.
If i write in chat "lol_why_is_not_working" it will write in my console "amx_lol_why_is_not_working"

But i have the "if" in my hook_say, i want only to check if he says /goto or /go

PHP Code:

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say","hook_say");
    
register_clcmd("amx_goto","cmdGOTO");
    
register_clcmd("amx_go","cmdGOTO");
}

public 
hook_say(id) {
    new 
s_Args[192];
    
    
read_args(s_Argssizeof(s_Args) - 1);
    
remove_quotes(s_Args);
    
    if(
equal(s_Args"/goto"5) || (s_Args,"/go",3)) {
        
replace(s_Argssizeof(s_Args) - 1"/""");
        
client_cmd(id"amx_%s"s_Args);
    }
    
    return 
PLUGIN_CONTINUE;


LATER EDIT :

I solved the problem, but i have a question.

Q : How could i make only 1 if ?

PHP Code:

public hook_say(id) {
    static 
s_Args[192];
    
    
read_args(s_Argssizeof(s_Args) - 1);
    
remove_quotes(s_Args);
    
    if(
equal(s_Args"/goto"5)) {
        
replace(s_Argssizeof(s_Args) - 1"/""");
        
client_cmd(id"amx_%s"s_Args);
    }
    else if(
equal(s_Args,"/go",3)) {
        
replace(s_Argssizeof(s_Args) - 1"/""");
        
client_cmd(id"amx_%s"s_Args);
    }
    
    return 
PLUGIN_CONTINUE;



ConnorMcLeod 07-10-2010 04:53

Re: Problem with hook_say
 
Read arg 1 instead of args, then you don't need to remove quotes.
And do the 2 equal checks in the same line (you forgot 'equal' in your 1st code) :

PHP Code:

public hook_say(id)
{
    static 
szSaid[192];

    
read_argv(1szSaidcharsmax(szSaid));

    if( 
equal(szSaid"/goto"5) || equal(szSaid"/go"3) )
    {
        
client_cmd(id"amx_%s"szSaid[1]);
    }



Ex3cuTioN 07-10-2010 04:56

Re: Problem with hook_say
 
It works

Thank you :D


All times are GMT -4. The time now is 07:06.

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