Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions addons/sourcemod/scripting/CustomChatColors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Plugin myinfo =
GlobalForward preLoadedForward;
GlobalForward loadedForward;
GlobalForward configReloadedForward;
GlobalForward senderPrefixForward;

ConVar g_cvar_GreenText;
ConVar g_cvar_ReplaceText;
Expand Down Expand Up @@ -284,6 +285,7 @@ public void OnPluginStart()
preLoadedForward = new GlobalForward("CCC_OnUserConfigPreLoaded", ET_Event, Param_Cell);
loadedForward = new GlobalForward("CCC_OnUserConfigLoaded", ET_Ignore, Param_Cell);
configReloadedForward = new GlobalForward("CCC_OnConfigReloaded", ET_Ignore);
senderPrefixForward = new GlobalForward("CCC_OnSenderPrefix", ET_Ignore, Param_Cell, Param_String, Param_Cell);

g_bProto = CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf;

Expand Down Expand Up @@ -4931,6 +4933,27 @@ public Action Hook_UserMessage(UserMsg msg_id, Handle bf, const int[] players, i
CFormatColor(g_msgSender, sizeof(g_msgSender), g_msgAuthor);
}

// Other plugins can put a prefix before the sender name and the CCC tag (a rank tag...),
// for every author, CCC flags or not
if (!bIsAction && g_msgAuthor > 0)
{
char sPrefix[64];
Call_StartForward(senderPrefixForward);
Call_PushCell(g_msgAuthor);
Call_PushStringEx(sPrefix, sizeof(sPrefix), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(sizeof(sPrefix));
Call_Finish();

if (sPrefix[0])
{
// FormatChatMessage colors the whole line only for CCC-enabled authors: color the
// prefix here for the others, their sender was already colored above
if (!IsClientEnabled())
CFormatColor(sPrefix, sizeof(sPrefix), g_msgAuthor);
Format(g_msgSender, sizeof(g_msgSender), "%s%s", sPrefix, g_msgSender);
}
}

strcopy(g_sMsgCacheName, sizeof(g_sMsgCacheName), g_msgName);
strcopy(g_sMsgCacheSender, sizeof(g_sMsgCacheSender), g_msgSender);
strcopy(g_sMsgCacheText, sizeof(g_sMsgCacheText), g_msgText);
Expand Down
16 changes: 14 additions & 2 deletions addons/sourcemod/scripting/include/ccc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define _ccc_included

#define CCC_V_MAJOR "8"
#define CCC_V_MINOR "1"
#define CCC_V_PATCH "10"
#define CCC_V_MINOR "2"
#define CCC_V_PATCH "0"

#define CCC_VERSION CCC_V_MAJOR..."."...CCC_V_MINOR..."."...CCC_V_PATCH

Expand Down Expand Up @@ -224,6 +224,18 @@ forward Action CCC_OnUserConfigPreLoaded(int client);
*/
forward void CCC_OnUserConfigLoaded(int client);

/**
* Called while a chat message is built, to put a prefix before the sender name (and before the CCC tag).
* Called for every author, whether CCC colors are enabled for him or not; not for /me actions.
* The prefix may hold color tags ({red}, {#RRGGBB}); end it with a color tag so the name keeps its own.
*
* @param client Author client index
* @param prefix Buffer for the prefix, empty on entry
* @param maxlen Size of the buffer
* @noreturn
*/
forward void CCC_OnSenderPrefix(int client, char[] prefix, int maxlen);

/**
* Called when the configuration file is reloaded with the sm_reloadccc command
*
Expand Down