AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get the Content of a Chat Message (https://forums.alliedmods.net/showthread.php?t=83176)

KillhemAll 01-05-2009 11:30

Get the Content of a Chat Message
 
Hi guys,

in my newest script i want to get the content of a chat message. e.g. Someone says noob then the script will return a message that a bad word was said.


How can I do that ?


KillhemAll :wink:

tuty 01-05-2009 11:57

Re: Get the Content of a Chat Message
 
something like this ?


PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New PlugIn"
#define VERSION "1.0"
#define AUTHOR "tuty"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
// Add your code here...
    
register_clcmd("say""handle_say");
    
register_clcmd("say_team""handle_say");
}
public 
handle_say(id)
{
    new 
said[192];
    
read_args(said191);

    
    if(
contain(said"noob"/* && contain(said, "word") && contain(sai, "word2")) */)
    {
        
client_print(idprint_chat"Hey, you are a noob not him xD!");
    }
    return 
PLUGIN_CONTINUE;



anakin_cstrike 01-05-2009 12:14

Re: Get the Content of a Chat Message
 
More efficient this way
PHP Code:

#include <amxmodx>

new g_Words[ ][ ] =
{
    
"noob",
    
"amxx",
    
"etc"
};

public 
plugin_init()
{
    
register_clcmd"say""hook_say" );
    
register_clcmd"say_team""hook_say" );
}

public 
hook_sayid )
{
    new 
said192 ];
    
read_argssaidcharsmaxsaid ) );
    
remove_quotessaid );
    
    new 
name32 ];
    
get_user_nameidnamecharsmaxname ) );
    
    for( new 
0sizeof g_Wordsi++ )
    {
        if( 
containisaidg_Words] ) )
            
client_print0print_chat"%s just said a nasty word ;-0"name );
    }
    return 
0;


PS: tuty. you have to use || instead of &&

KillhemAll 01-09-2009 11:52

Re: Get the Content of a Chat Message
 
Thank you all +Karma . There should be more people like you thx

Bad_Bud 01-09-2009 15:47

Re: Get the Content of a Chat Message
 
If you're going for ultramax efficiency, you may want to add a secondary handle_say type function to implement string slicing, that way you can hack off the "say " part of the said[] string. If you have a huge list of bad words to check against, I can imagine it would be checking those first four irrelevant cells countless times.

...or "say_team" for the say_team one.

Also, not sure there's a reason to use a charsmax function when you just defined how large the array was and could easily type it in...


All times are GMT -4. The time now is 09:11.

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