Thread: acronym
View Single Post
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 12-22-2021 , 09:08   Re: acronym
Reply With Quote #30

Quote:
Originally Posted by iceeedr View Post
The change I sent was exclusively for his problem, the way to "fix" the plugin would be this:

PHP Code:
#include <amxmodx>

#define MAX_SAY_TEXT_LEN 128
#define MAX_KEYWORD_LEN 32
#define MAX_HIGHLIGHT_LEN 32

enum Match
{
    
Keyword[MAX_KEYWORD_LEN],
    
Highlight[MAX_HIGHLIGHT_LEN]
};

new 
g_ChatKeywords[][Match] =
{
    {
"gg""!x04Good Game !"}, //!x01 is yellow color | !x03 is team color | !x04 is green color
    
{"slm""!x04Slam Alikom"}
};

new 
g_msgSayText;

public 
plugin_init()
{
    
register_clcmd("say""@OnCmd_Say");
    
g_msgSayText get_user_msgid("SayText")
}

@
OnCmd_Say(id)
{
    new 
szText[MAX_SAY_TEXT_LEN];
    new 
HasAcronym;
    
read_args(szTextcharsmax(szText));

    
remove_quotes(szText);
    
trim(szText);

    if (!
szText[0])
        return 
PLUGIN_CONTINUE;

    for (new 
iPattern 0szHighlight[MAX_HIGHLIGHT_LEN], iPatterns sizeof(g_ChatKeywords); iPattern iPatternsiPattern++)
    {
        if (!
equal(szTextg_ChatKeywords[iPattern][Keyword]))
            continue;

        if(!
HasAcronymHasAcronym 1

        format
(szHighlightcharsmax(szHighlight), "%s^1"g_ChatKeywords[iPattern][Highlight]);
        
replace_all(szTextcharsmax(szText), g_ChatKeywords[iPattern][Keyword], szHighlight);
    }

    if(!
HasAcronym)
        return 
PLUGIN_CONTINUE

    
// %n was added on 1.9, but it directly parses a certain client's name.
    
new szName[64]
    
get_user_name(idszNamecharsmax(szName))
    
ColorChat(0"!x03%s%s!x01: %s"szNameis_user_alive(id) ? "" " !x01*(DEAD)*!x01"szText);
    return 
PLUGIN_HANDLED;
}

stock ColorChat(const id, const input[], any:...) {
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);

    
replace_all(msg190"!x04""^4");
    
replace_all(msg190"!x03""^3");
    
replace_all(msg190"!x01""^1");

    if(
idplayers[0] = id;
    else 
get_players(playerscount"ch"); {
        for(new 
0counti++) {
            if(
is_user_connected(players[i])) {
                
message_begin(MSG_ONE_UNRELIABLEg_msgSayText_players[i]);
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

But it changes the plugin creator's initial idea, so feel free to come up with a fix and not just criticism.
I've been working on this the past few days, don't think this is all just criticism, i just told you it wasn't a proper fix, that's it.

What you're sharing wouldn't work aswell as he wants the gg still to be called, even when it's in the middle of a sentence. just using equal isn't enough here.

This was my initial idea:

PHP Code:

if(equali(szTextszAcronym)) // Message and acronym are equal, don't do anymore unnessecary checks.
        
{
            
bContainsAcronym true;
            
replace_all(szTextcharsmax(szText), szAcronymszOutput);

            
log_amx("Acronym and message are equal, replacing %s with %s"szAcronymszOutput);

            break;
        }

        if(
containi(szTextszAcronym)) // Message contains acronym, check if it's a valid one.
        
{
            
formatex(szTempAcronymcharsmax(szTempAcronym), " %s "szAcronym);

            if(!
containi(szTempAcronymszAcronym)) // Invalid acronym.
            
{
                continue;
            }

            
bContainsAcronym true;
        } 
EDIT: After putting some time and effort in it again, i think this should be easy to do if we split up the acronym from the whole line, replace it and put it back into the text line.

Another possibility is checking if the last character of the acronym is EOS || space and first character before the acronym is a space. Been thinking a lot on how to do this, but can't seem to figure it out.
__________________

Last edited by Napoleon_be; 12-22-2021 at 10:52.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be