AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Solved code Problem (https://forums.alliedmods.net/showthread.php?t=329624)

ho83 01-01-2021 08:41

code Problem
 
Hi. I have This code. This code detects the sentences I want in the chat and does something. But the problem is that if there is a space in a sentence, the code can not recognize it. This code only recognizes words and is not able to recognize sentences. This is my first problem. The second problem is that this code only recognizes words sent by users. I want, for example, if the server also sends words in the chat, the code can recognize it. Is this possible? Thanks.
Code :
PHP Code:

public ChatGlobalCommand(id)
{
    static 
lastsaid[512], said[512]
    
read_args(said512)
    if(
equal(saidlastsaid))
        return 
PLUGIN_CONTINUE
        
    
for(new 0sizeof BAD_WORDSi++)
    {
        if(
containi(saidBAD_WORDS[i]))
            
replace_all(saidcharsmax(said), BAD_WORDS[i], "***")    
    }
    
formatex(lastsaidcharsmax(lastsaid), "%s"said)
    
client_cmd(id"say %s"said)
    return 
PLUGIN_HANDLED



Natsheh 01-01-2021 09:20

Re: code Problem
 
Show plugin_init

ho83 01-01-2021 09:36

Re: code Problem
 
Quote:

Originally Posted by Natsheh (Post 2730889)
Show plugin_init

Thanks for reply
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "work"
#define VERSION "1.0"
#define AUTHOR "RateX"

new BAD_WORDS[][] = 
{
    
// Add the bad words here. Ex:
    
"Today is Gang War Day, Given By",
    
"ass"
}

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say ""ChatGlobalCommand")
}

public 
ChatGlobalCommand(id)
{
    static 
lastsaid[512], said[512]
    
read_args(said512)
    if(
equal(saidlastsaid))
        return 
PLUGIN_CONTINUE
        
    
for(new 0sizeof BAD_WORDSi++)
    {
        if(
containi(saidBAD_WORDS[i]))
            
replace_all(saidcharsmax(said), BAD_WORDS[i], "***")    
    }
    
formatex(lastsaidcharsmax(lastsaid), "%s"said)
    
client_cmd(id"say %s"said)
    return 
PLUGIN_HANDLED



Bugsy 01-01-2021 11:43

Re: code Problem
 
Try this
Code:
public ChatGlobalCommand(id) {     static lastsaid[512], said[512] , iPos;     read_args(said, 512)         if(equal(said, lastsaid))         return PLUGIN_CONTINUE         for ( new i = 0 ; i < sizeof BAD_WORDS ; i++ )     {
        //The return value of containi() cannot be used as a bool since it returns -1 (true) if nothing is found. Always use != -1, > -1, or >= 0
        if ( ( iPos = containi( said , BAD_WORDS[i] ) ) > -1 )
        {
            //Replaced replace_all() with setc() to fill in bad word chars with *
            setc( said[ iPos ] , strlen( BAD_WORDS[ i ] ) , '*' );             //replace_all( said , charsmax( said ) , BAD_WORDS[i] , "***")         }     }         formatex(lastsaid, charsmax(lastsaid), "%s", said)     client_cmd(id, "say %s", said)         return PLUGIN_HANDLED }

ho83 01-01-2021 12:07

Re: code Problem
 
Quote:

Originally Posted by Bugsy (Post 2730901)
Try this
Code:
public ChatGlobalCommand(id) {     static lastsaid[512], said[512] , iPos;     read_args(said, 512)         if(equal(said, lastsaid))         return PLUGIN_CONTINUE         for ( new i = 0 ; i < sizeof BAD_WORDS ; i++ )     {
        //The return value of containi() cannot be used as a bool since it returns -1 (true) if nothing is found. Always use != -1, > -1, or >= 0
        if ( ( iPos = containi( said , BAD_WORDS[i] ) ) > -1 )
        {
            //Replaced replace_all() with setc() to fill in bad word chars with *
            setc( said[ iPos ] , strlen( BAD_WORDS[ i ] ) , '*' );             //replace_all( said , charsmax( said ) , BAD_WORDS[i] , "***")         }     }         formatex(lastsaid, charsmax(lastsaid), "%s", said)     client_cmd(id, "say %s", said)         return PLUGIN_HANDLED }

Thank you dear. Can you change this code to work only for messages sent by the server?
For example, when the server said in chat "Today is Gang WarDay" plugin do this : server_cmd("amx_omenu 1")

Thanks

fysiks 01-01-2021 18:24

Re: code Problem
 
Quote:

Originally Posted by ho83 (Post 2730903)
Thank you dear. Can you change this code to work only for messages sent by the server?
For example, when the server said in chat "Today is Gang WarDay" plugin do this : server_cmd("amx_omenu 1")

That seems like an entirely different plugin/request. Also, it would be best if you simply edit the plugin that sends this message to do what you want. Also, if the server is sending the message, who are you expecting to get the amxmodmenu?


All times are GMT -4. The time now is 12:48.

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