[Include] L_ColorEmbed - Color embed strings and highlight words to be used for client-messages, dialogs and gametexts/textdraw
#1

L_ColorEmbed
Color embed strings and highlight words to be used for;
client-messages, dialogs and gametexts/textdraw.
It's been quite a while since I've released something, so I planned to work for my last release of this year. This include allows you to color embed the given string, highlight the given words in a string, and those formatted strings can be used on dialogs, gametexts, textdraws or even as client messages.

For a quick overview, I can list what all this include could do:

• Allow color embedding directly on chat using it's natives.
• Allow color embedding and creating new lines for a dialog's caption directly in-game.
• Highlight any given words on a text either for client-messages/dialogs or for gametexts/textdraw.
• Highlighting can be done in two ways - One which highlights the given word a single time only, the other can highlight words even if they're repeated.
• There's also in built functions which allows you to highlight online nicknames to be used for client-messages(even chat)/dialogs or for gametexts/textdraws.
Natives: There's a total of 10 natives, complete list:
pawn Code:
native NickHighlight_SCM(text[], scmcol[9], bool:ignorecase = false, hcol[9] = "\0");
native NickHighlight_SCMEx(text[], scmcol[9], bool:ignorecase = false, hcol[9] = "\0");
native NickHighlight_Text(text[], txcol[], hcol[], bool:ignorecase = false);
native NickHighlight_TextEx(text[], txcol[], hcol[], bool:ignorecase = false);
native WordsHighlight_SCM(text[], scmcol[9], hcol[9], words[][], bool:ignorecase = false, size = sizeof(words));
native WordsHighlight_SCMEx(text[], scmcol[9], hcol[9], words[][], bool:ignorecase = false, size = sizeof(words));
native WordsHighlight_Text(text[], txcol[], hcol[], words[][], bool:ignorecase = false, size = sizeof(words));
native WordsHighlight_TextEx(text[], txcol[], hcol[], words[][], bool:ignorecase = false, size = sizeof(words));
native ColorEmbed_SCM(text[], rchar = 'x', size = sizeof(text));
native ColorEmbed_Dialog(text[], rchar = 'x', size = sizeof(text));
Explanation:
pawn Code:
/*

Parameters for both NickHighlight_SCM and NickHighlight_SCMEx

text[] = The text that has to be formatted.
scmcol[] = The color that the client message has got, usually for chat, it's white {FFFFFF}
ignorecase = If it's set to false, names will be highlighted on text only if it's exactly like how the player's nick is.
hcol[] = The highlight color to be displayed, if it's not set, GetPlayerColor will be used instead.

The difference between NickHighlight_SCM and NickHighlight_SCMEx is that if the 'text' repeats
the highlighted player's name, the latter one will highlight that too where as the first one will highlight
only once.

Example:
public OnPlayerText(playerid, text[])
{
    new
        temp_String[144];
    strcpy(temp_String, text, sizeof(temp_String));
    SendPlayerMessageToAll(playerid, NickHighlight_SCM(temp_String, "{FFFFFF}",  false, "{FF0000}");
    return 0;
}
//Here the highlighting color is red, {FF0000}
*/


native NickHighlight_SCM(text[], scmcol[9], bool:ignorecase = false, hcol[9] = "\0");
native NickHighlight_SCMEx(text[], scmcol[9], bool:ignorecase = false, hcol[9] = "\0");

/*

Parameters for both NickHighlight_Text and NickHighlight_TextEx

text[] = The text that has to be formatted.
txcol[] = The default color of the text. Suppose if the starting color is "~g~", txcol should also be "~g~"
hcol[] = The color used for highlighting.
ignorecase = Similar to the above function's, checks for case sensitive.

*/

native NickHighlight_Text(text[], txcol[], hcol[], bool:ignorecase = false);
native NickHighlight_TextEx(text[], txcol[], hcol[], bool:ignorecase = false);

/*

Parameters for WordsHighlight_SCM and WordsHighlight_SCMEx

text[] = The text to be formatted.
scmcol[] = Default color of the client message.
hcol[] = The color that's used for highlighting.
words[][] = Words to be highlighted.
ignorecase = Whether to ignore case sensitivity or not.
size = Number of words.

Example:

new
    WORDS[][] = {"Function", "This", "Testing"};
WordsHighlight_SCM(text, "{FFFFFF}", "{FF0000}", WORDS, false, 3);

*/

native WordsHighlight_SCM(text[], scmcol[9], hcol[9], words[][], bool:ignorecase = false, size = sizeof(words));
native WordsHighlight_SCMEx(text[], scmcol[9], hcol[9], words[][], bool:ignorecase = false, size = sizeof(words));

/*

Parameters:

text[] = The text that has to be formatted.
txcol[] = The default color of the text.
hcol[] = The color that has to be used for highlighting.
words[][] = The words that has to be highlighted.
ignorecase = Whether case sensitivity has to be ignored or not.
size = Number of words.

Example:
new
    WORDS[][] = {"This", "Function", "Testing"};
WordsHighlight_Text(text, "~g~", "~h~~r~", WORDS, false, sizeof(words));

*/

native WordsHighlight_Text(text[], txcol[], hcol[], words[][], bool:ignorecase = false, size = sizeof(words));
native WordsHighlight_TextEx(text[], txcol[], hcol[], words[][], bool:ignorecase = false, size = sizeof(words));

/*

Parameters:

text[] = The text to be color embedded.
rchar = The string that has to indicate color embedding, eg : {xFF0000} - If this is found when rchar = 'x', then
        color embedding will take place and it will be replaced as  {FF0000}
size = size of the text.

ColorEmbed_SCM is used for client messages and ColorEmbed_Dialog is used for
dialog caption. The latter one also formats "\n" and forms a new line if found.

*/

native ColorEmbed_SCM(text[], rchar = 'x', size = sizeof(text));
native ColorEmbed_Dialog(text[], rchar = 'x', size = sizeof(text));
Download: https://github.com/Lordzy/L_ColorEmbed
Raw Source: https://raw.githubusercontent.com/Lo...ColorEmbed.inc
Example Source: https://raw.githubusercontent.com/Lo...bedExample.pwn

Screenshots:

- On the first image, I'm typing the names of the players who are online and it highlights them and also it shows that if NickHighlight_SCMEx is used, it highlights the names even if they're repeated.



- I wrote a command named "/displaywords" which accepts a string and passes it to WordsHighlight_SCMEx where the words chosen to be highlighted are Lordzy, KaperStone and XKIRIL. The first two are highlighted but not the last one because I set ignorecase to false so case sensitivity will not be ignored.



- Another command named "/dialogtest" which accepts a string and shows it as the caption. It would have escaped the color codes because SA-MP does it by default and even display the "\n" part. But by using ColorEmbed_Dialog it color embeds and also replaces "\n" from string to be as an escape character. ColorEmbed_SCM is also similar to this, it works for client messages/chat. The only difference is that "\n" won't be replaced as an escape character on ColorEmbed_SCM.



The code used for these images can be found at the examples folder.

Notes:
- SA-MP passes only 144 characters on client messages, so if there's anything unusual with the color embedding, the include isn't responsible.
And also thanks to KaperStone for naming this include as "L_ColorEmbed". I know that there's few more days to get on 2015, but anyways, happy new year!
Reply
#2

Nice !
Reply
#3

Seems nice, but maybe a suggestion is to make it go to the next line if the length surpasses 144.
Reply
#4

Good Job mate!
i like it
reped
Reply
#5

I thought of coding it few days back, but unfortunately I was lacking in knowledge of scripting and today you posted it. Must say, you did it very nicely.
Reply
#6

nice
Reply
#7

Thanks!

Quote:
Originally Posted by Abagail
View Post
Seems nice, but maybe a suggestion is to make it go to the next line if the length surpasses 144.
All functions of this include returns the data directly, so it can be done by the one who uses it. I wouldn't mind giving an example though :
pawn Code:
strcpy(temp_String, ColorEmbed_SCM(string), sizeof(temp_String));
new
    t_Str[50];

if(strmid(t_Str, temp_String, 140, strlen(temp_String)) > 0) //140 is the start point of extraction, end point is up to the end of string.
    //Some characters have been extracted from the source and passed to "t_Str"
else
    //No characters were extracted from source and passed to "t_Str".
Reply
#8

How to remove the Textdraw ? I don't know is that textdraw . The Test which appear in the middle of the screen after sending the message.
Reply
#9

Quote:
Originally Posted by Arxalan
View Post
How to remove the Textdraw ? I don't know is that textdraw . The Test which appear in the middle of the screen after sending the message.
You mean while using the example script I added on the repository?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)