Veteran Member
Join Date: Jul 2011
Location: Belgium
|
12-22-2021
, 09:08
Re: acronym
|
#30
|
Quote:
Originally Posted by iceeedr
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(szText, charsmax(szText));
remove_quotes(szText); trim(szText);
if (!szText[0]) return PLUGIN_CONTINUE;
for (new iPattern = 0, szHighlight[MAX_HIGHLIGHT_LEN], iPatterns = sizeof(g_ChatKeywords); iPattern < iPatterns; iPattern++) { if (!equal(szText, g_ChatKeywords[iPattern][Keyword])) continue;
if(!HasAcronym) HasAcronym = 1
format(szHighlight, charsmax(szHighlight), "%s^1", g_ChatKeywords[iPattern][Highlight]); replace_all(szText, charsmax(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(id, szName, charsmax(szName)) ColorChat(0, "!x03%s%s!x01: %s", szName, is_user_alive(id) ? "" : " !x01*(DEAD)*!x01", szText); return PLUGIN_HANDLED; }
stock ColorChat(const id, const input[], any:...) { new count = 1, players[32]; static msg[191]; vformat(msg, 190, input, 3);
replace_all(msg, 190, "!x04", "^4"); replace_all(msg, 190, "!x03", "^3"); replace_all(msg, 190, "!x01", "^1");
if(id) players[0] = id; else get_players(players, count, "ch"); { for(new i = 0; i < count; i++) { if(is_user_connected(players[i])) { message_begin(MSG_ONE_UNRELIABLE, g_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(szText, szAcronym)) // Message and acronym are equal, don't do anymore unnessecary checks. { bContainsAcronym = true; replace_all(szText, charsmax(szText), szAcronym, szOutput);
log_amx("Acronym and message are equal, replacing %s with %s", szAcronym, szOutput);
break; }
if(containi(szText, szAcronym)) // Message contains acronym, check if it's a valid one. { formatex(szTempAcronym, charsmax(szTempAcronym), " %s ", szAcronym);
if(!containi(szTempAcronym, szAcronym)) // 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.
|
|