Skip to content

Commit

Permalink
Merge branch 'rainbow-tag'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexer10 committed Dec 19, 2019
2 parents 5cc60ef + 2543589 commit db13c55
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
4 changes: 2 additions & 2 deletions addons/sourcemod/configs/hextags.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// All the avaible colors are: https://goo.gl/VgAHbK (colorvariables supported).
// Custom colors(DON'T MIX THEM):
// Put them at the "key" start.
// 1. {rainbow} -> Make every character follow the rainbow colors.
// 2. {random} -> Make every character random colored.
// 1. {rainbow} -> Make every character follow the rainbow colors. Must be the only color and at the start of the string.
// 2. {random} -> Make every character random colored. Must be the only color and at the start of the string.
//
// NOTE: Using Custom colors the max message length is gonna be half (from 128 to 64)
//
Expand Down
99 changes: 98 additions & 1 deletion addons/sourcemod/scripting/hextags.sp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,56 @@ public Action CP_OnChatMessage(int& author, ArrayList recipients, char[] flagstr
//Add colors & tags
char sNewName[MAXLENGTH_NAME];
char sNewMessage[MAXLENGTH_MESSAGE];
Format(sNewName, MAXLENGTH_NAME, "%s%s%s{default}", sTags[author][ChatTag], sTags[author][NameColor], name);
// Rainbow name
if (StrEqual(sTags[author][NameColor], "{rainbow}"))
{
char sTemp[MAXLENGTH_MESSAGE];

int color;
int len = strlen(name);
for(int i = 0; i < len; i++)
{
if (IsCharSpace(name[i]))
{
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, name[i]);
continue;
}

int bytes = GetCharBytes(name[i])+1;
char[] c = new char[bytes];
strcopy(c, bytes, name[i]);
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetColor(++color), c);
if (IsCharMB(name[i]))
i += bytes-2;
}
Format(sNewName, MAXLENGTH_NAME, "%s%s{default}", sTags[author][ChatTag], sTemp);
}
else if (StrEqual(sTags[author][NameColor], "{random}")) //Random name
{
char sTemp[MAXLENGTH_MESSAGE];

int len = strlen(name);
for(int i = 0; i < len; i++)
{
if (IsCharSpace(name[i]))
{
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, name[i]);
continue;
}

int bytes = GetCharBytes(name[i])+1;
char[] c = new char[bytes];
strcopy(c, bytes, name[i]);
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetRandomColor(), c);
if (IsCharMB(name[i]))
i += bytes-2;
}
Format(sNewName, MAXLENGTH_NAME, "%s%s{default}", sTags[author][ChatTag], sTemp);
}
else
{
Format(sNewName, MAXLENGTH_NAME, "%s%s%s{default}", sTags[author][ChatTag], sTags[author][NameColor], name);
}
Format(sNewMessage, MAXLENGTH_MESSAGE, "%s%s", sTags[author][ChatColor], message);

//Update the params
Expand Down Expand Up @@ -877,6 +926,54 @@ void GetTags(int client, KeyValues kv, bool final = false)
Debug_Print("Setted tag: %s", sTags[client][ScoreTag]);
CS_SetClientClanTag(client, sTags[client][ScoreTag]); //Instantly load the score-tag
}
if (StrContains(sTags[client][ChatTag], "{rainbow}") == 0)
{
Debug_Print("Found {rainbow} in ChatTag");
ReplaceString(sTags[client][ChatTag], sizeof(sTags[][]), "{rainbow}", "");
char sTemp[MAXLENGTH_MESSAGE];

int color;
int len = strlen(sTags[client][ChatTag]);
for(int i = 0; i < len; i++)
{
if (IsCharSpace(sTags[client][ChatTag][i]))
{
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, sTags[client][ChatTag][i]);
continue;
}

int bytes = GetCharBytes(sTags[client][ChatTag][i])+1;
char[] c = new char[bytes];
strcopy(c, bytes, sTags[client][ChatTag][i]);
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetColor(++color), c);
if (IsCharMB(sTags[client][ChatTag][i]))
i += bytes-2;
}
strcopy(sTags[client][ChatTag], sizeof(sTags[][]), sTemp);
Debug_Print("Replaced ChatTag with %s", sTags[client][ChatTag]);
}
if (StrContains(sTags[client][ChatTag], "{random}") == 0)
{
ReplaceString(sTags[client][ChatTag], sizeof(sTags[][]), "{random}", "");
char sTemp[MAXLENGTH_MESSAGE];
int len = strlen(sTags[client][ChatTag]);
for(int i = 0; i < len; i++)
{
if (IsCharSpace(sTags[client][ChatTag][i]))
{
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, sTags[client][ChatTag][i]);
continue;
}

int bytes = GetCharBytes(sTags[client][ChatTag][i])+1;
char[] c = new char[bytes];
strcopy(c, bytes, sTags[client][ChatTag][i]);
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetRandomColor(), c);
if (IsCharMB(sTags[client][ChatTag][i]))
i += bytes-2;
}
strcopy(sTags[client][ChatTag], sizeof(sTags[][]), sTemp);
}
Debug_Print("Succesfully setted tags");
}

Expand Down

0 comments on commit db13c55

Please sign in to comment.