From 4381c12b61fba33ed678f61f648d5f870c1e79b3 Mon Sep 17 00:00:00 2001 From: Riccardo H Date: Tue, 30 Jul 2019 23:50:00 +0200 Subject: [PATCH] fixed default_titles name colors https://github.com/totles/z4lab-surftimer/issues/24 --- addons/sourcemod/scripting/surftimer/hooks.sp | 61 ++++++++++++++++++- addons/sourcemod/scripting/surftimer/misc.sp | 20 +++++- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/hooks.sp b/addons/sourcemod/scripting/surftimer/hooks.sp index fc15b9b..21ac599 100644 --- a/addons/sourcemod/scripting/surftimer/hooks.sp +++ b/addons/sourcemod/scripting/surftimer/hooks.sp @@ -470,9 +470,9 @@ public Action Say_Hook(int client, const char[] command, int argc) WriteChatLog(client, "say", sText); PrintToServer("%s: %s", szName, sText); - if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) - Format(szName, sizeof(szName), "%s%s", g_pr_namecolour[client], szName); - else if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && g_bDbCustomTitleInUse[client]) + //if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + // Format(szName, sizeof(szName), "%s%s", g_pr_namecolour[client], szName); + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && g_bDbCustomTitleInUse[client]) setNameColor(szName, g_iCustomColours[client][0], 64); if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && g_bDbCustomTitleInUse[client] && g_bHasCustomTextColour[client]) @@ -487,6 +487,12 @@ public Action Say_Hook(int client, const char[] command, int argc) { char szChatRank[1024]; Format(szChatRank, 1024, "%s", g_pr_chat_coloredrank[client]); + char szChatRankColor[1024]; + Format(szChatRankColor, 1024, "%s", g_pr_chat_coloredrank[client]); + CGetRankColor(szChatRankColor, 1024); + + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + Format(szName, sizeof(szName), "{%s}%s", szChatRankColor, szName); if (GetConVarBool(g_hCountry) && (GetConVarBool(g_hPointSystem))) { @@ -512,6 +518,55 @@ public Action Say_Hook(int client, const char[] command, int argc) return Plugin_Continue; } +public void CGetRankColor(char[] sMsg, int iSize) // edit from CProcessVariables - colorvars +{ + if (!Init()) { + return; + } + + char[] sOut = new char[iSize]; char[] sCode = new char[iSize]; char[] sColor = new char[iSize]; + int iOutPos = 0; int iCodePos = -1; + int iMsgLen = strlen(sMsg); + int dev = 0; + + for (int i = 0; i < iMsgLen; i++) { + if (sMsg[i] == '{') { + iCodePos = 0; + } + + if (iCodePos > -1) { + sCode[iCodePos] = sMsg[i]; + sCode[iCodePos + 1] = '\0'; + + if (sMsg[i] == '}' || i == iMsgLen - 1) { + strcopy(sCode, strlen(sCode) - 1, sCode[1]); + StringToLower(sCode); + + if (CGetColor(sCode, sColor, iSize)) { + if(dev == 1) break; + dev++; + } else { + Format(sOut, iSize, "%s{%s}", sOut, sCode); + iOutPos += strlen(sCode) + 2; + } + + iCodePos = -1; + strcopy(sColor, iSize, ""); + } else { + iCodePos++; + } + + continue; + } + + sOut[iOutPos] = sMsg[i]; + iOutPos++; + sOut[iOutPos] = '\0'; + } + + strcopy(sMsg, iSize, sCode); +} + public Action Event_OnPlayerTeam(Handle event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(GetEventInt(event, "userid")); diff --git a/addons/sourcemod/scripting/surftimer/misc.sp b/addons/sourcemod/scripting/surftimer/misc.sp index 2ba29c8..22ec09e 100644 --- a/addons/sourcemod/scripting/surftimer/misc.sp +++ b/addons/sourcemod/scripting/surftimer/misc.sp @@ -2640,15 +2640,21 @@ stock Action PrintSpecMessageAll(int client) char szChatRank[64]; Format(szChatRank, 64, "%s", g_pr_chat_coloredrank[client]); - if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) - Format(szName, sizeof(szName), "%s%s", g_pr_namecolour[client], szName); - else if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && g_bDbCustomTitleInUse[client]) + //if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + // Format(szName, sizeof(szName), "%s%s", g_pr_namecolour[client], szName); + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && g_bDbCustomTitleInUse[client]) setNameColor(szName, g_iCustomColours[client][0], 64); // fluffys if (g_bHasCustomTextColour[client]) setTextColor(szTextToAll, g_iCustomColours[client][1], 1024); + char szChatRankColor[1024]; + Format(szChatRankColor, 1024, "%s", g_pr_chat_coloredrank[client]); + CGetRankColor(szChatRankColor, 1024); + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + Format(szName, sizeof(szName), "{%s}%s", szChatRankColor, szName); + if (GetConVarBool(g_hCountry)) CPrintToChatAll("%t", "Misc20", g_szCountryCode[client], szChatRank, szName, szTextToAll); else if (GetConVarBool(g_hPointSystem)) @@ -2657,6 +2663,10 @@ stock Action PrintSpecMessageAll(int client) { char szPlayerTitle2[256][2]; ExplodeString(szChatRank, "{blue}", szPlayerTitle2, 2, 256); + char szPlayerTitleColor[1024]; + Format(szPlayerTitleColor, 1024, "%s", szPlayerTitle2[1]); + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + Format(szName, sizeof(szName), "{%s}%s", szPlayerTitleColor, szName); if (IsPlayerAlive(client)) CPrintToChatAll("%t", "Misc21", szPlayerTitle2[0], szPlayerTitle2[1], szName, szTextToAll); else @@ -2668,6 +2678,10 @@ stock Action PrintSpecMessageAll(int client) { char szPlayerTitle2[256][2]; ExplodeString(szChatRank, "{orange}", szPlayerTitle2, 2, 256); + char szPlayerTitleColor[1024]; + Format(szPlayerTitleColor, 1024, "%s", szPlayerTitle2[1]); + if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames) && !g_bDbCustomTitleInUse[client]) + Format(szName, sizeof(szName), "{%s}%s", szPlayerTitleColor, szName); if (IsPlayerAlive(client)) CPrintToChatAll("%t", "Misc23", szPlayerTitle2[0], szPlayerTitle2[1], szName, szTextToAll); else