Skip to content

Commit db13c55

Browse files
committed
Merge branch 'rainbow-tag'
2 parents 5cc60ef + 2543589 commit db13c55

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

addons/sourcemod/configs/hextags.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
// All the avaible colors are: https://goo.gl/VgAHbK (colorvariables supported).
2727
// Custom colors(DON'T MIX THEM):
2828
// Put them at the "key" start.
29-
// 1. {rainbow} -> Make every character follow the rainbow colors.
30-
// 2. {random} -> Make every character random colored.
29+
// 1. {rainbow} -> Make every character follow the rainbow colors. Must be the only color and at the start of the string.
30+
// 2. {random} -> Make every character random colored. Must be the only color and at the start of the string.
3131
//
3232
// NOTE: Using Custom colors the max message length is gonna be half (from 128 to 64)
3333
//

addons/sourcemod/scripting/hextags.sp

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,56 @@ public Action CP_OnChatMessage(int& author, ArrayList recipients, char[] flagstr
375375
//Add colors & tags
376376
char sNewName[MAXLENGTH_NAME];
377377
char sNewMessage[MAXLENGTH_MESSAGE];
378-
Format(sNewName, MAXLENGTH_NAME, "%s%s%s{default}", sTags[author][ChatTag], sTags[author][NameColor], name);
378+
// Rainbow name
379+
if (StrEqual(sTags[author][NameColor], "{rainbow}"))
380+
{
381+
char sTemp[MAXLENGTH_MESSAGE];
382+
383+
int color;
384+
int len = strlen(name);
385+
for(int i = 0; i < len; i++)
386+
{
387+
if (IsCharSpace(name[i]))
388+
{
389+
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, name[i]);
390+
continue;
391+
}
392+
393+
int bytes = GetCharBytes(name[i])+1;
394+
char[] c = new char[bytes];
395+
strcopy(c, bytes, name[i]);
396+
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetColor(++color), c);
397+
if (IsCharMB(name[i]))
398+
i += bytes-2;
399+
}
400+
Format(sNewName, MAXLENGTH_NAME, "%s%s{default}", sTags[author][ChatTag], sTemp);
401+
}
402+
else if (StrEqual(sTags[author][NameColor], "{random}")) //Random name
403+
{
404+
char sTemp[MAXLENGTH_MESSAGE];
405+
406+
int len = strlen(name);
407+
for(int i = 0; i < len; i++)
408+
{
409+
if (IsCharSpace(name[i]))
410+
{
411+
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, name[i]);
412+
continue;
413+
}
414+
415+
int bytes = GetCharBytes(name[i])+1;
416+
char[] c = new char[bytes];
417+
strcopy(c, bytes, name[i]);
418+
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetRandomColor(), c);
419+
if (IsCharMB(name[i]))
420+
i += bytes-2;
421+
}
422+
Format(sNewName, MAXLENGTH_NAME, "%s%s{default}", sTags[author][ChatTag], sTemp);
423+
}
424+
else
425+
{
426+
Format(sNewName, MAXLENGTH_NAME, "%s%s%s{default}", sTags[author][ChatTag], sTags[author][NameColor], name);
427+
}
379428
Format(sNewMessage, MAXLENGTH_MESSAGE, "%s%s", sTags[author][ChatColor], message);
380429

381430
//Update the params
@@ -877,6 +926,54 @@ void GetTags(int client, KeyValues kv, bool final = false)
877926
Debug_Print("Setted tag: %s", sTags[client][ScoreTag]);
878927
CS_SetClientClanTag(client, sTags[client][ScoreTag]); //Instantly load the score-tag
879928
}
929+
if (StrContains(sTags[client][ChatTag], "{rainbow}") == 0)
930+
{
931+
Debug_Print("Found {rainbow} in ChatTag");
932+
ReplaceString(sTags[client][ChatTag], sizeof(sTags[][]), "{rainbow}", "");
933+
char sTemp[MAXLENGTH_MESSAGE];
934+
935+
int color;
936+
int len = strlen(sTags[client][ChatTag]);
937+
for(int i = 0; i < len; i++)
938+
{
939+
if (IsCharSpace(sTags[client][ChatTag][i]))
940+
{
941+
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, sTags[client][ChatTag][i]);
942+
continue;
943+
}
944+
945+
int bytes = GetCharBytes(sTags[client][ChatTag][i])+1;
946+
char[] c = new char[bytes];
947+
strcopy(c, bytes, sTags[client][ChatTag][i]);
948+
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetColor(++color), c);
949+
if (IsCharMB(sTags[client][ChatTag][i]))
950+
i += bytes-2;
951+
}
952+
strcopy(sTags[client][ChatTag], sizeof(sTags[][]), sTemp);
953+
Debug_Print("Replaced ChatTag with %s", sTags[client][ChatTag]);
954+
}
955+
if (StrContains(sTags[client][ChatTag], "{random}") == 0)
956+
{
957+
ReplaceString(sTags[client][ChatTag], sizeof(sTags[][]), "{random}", "");
958+
char sTemp[MAXLENGTH_MESSAGE];
959+
int len = strlen(sTags[client][ChatTag]);
960+
for(int i = 0; i < len; i++)
961+
{
962+
if (IsCharSpace(sTags[client][ChatTag][i]))
963+
{
964+
Format(sTemp, sizeof(sTemp), "%s%c", sTemp, sTags[client][ChatTag][i]);
965+
continue;
966+
}
967+
968+
int bytes = GetCharBytes(sTags[client][ChatTag][i])+1;
969+
char[] c = new char[bytes];
970+
strcopy(c, bytes, sTags[client][ChatTag][i]);
971+
Format(sTemp, sizeof(sTemp), "%s%c%s", sTemp, GetRandomColor(), c);
972+
if (IsCharMB(sTags[client][ChatTag][i]))
973+
i += bytes-2;
974+
}
975+
strcopy(sTags[client][ChatTag], sizeof(sTags[][]), sTemp);
976+
}
880977
Debug_Print("Succesfully setted tags");
881978
}
882979

0 commit comments

Comments
 (0)