mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 10:28:26 +00:00
add Shavit_GetPlainChatrank. add {cr} to shavit_misc_clantag
This commit is contained in:
parent
41f62f0a8f
commit
720ddeed1d
@ -2140,6 +2140,17 @@ native void Shavit_SetPlayerPreFrame(int client, int PreFrame);
|
||||
*/
|
||||
native void Shavit_SetPlayerTimerFrame(int client, int TimerPreFrame);
|
||||
|
||||
/*
|
||||
* Retrieves the player's chatrank trimmed and without colors.
|
||||
*
|
||||
* @param client Client index
|
||||
* @param buf Buffer to put the put the chatrank into
|
||||
* @param buflen Size of buf
|
||||
* @param includename Include {name} in result.
|
||||
* @noreturn
|
||||
*/
|
||||
native void Shavit_GetPlainChatrank(int client, char[] buf, int buflen, bool includename=false);
|
||||
|
||||
// same as Shavit_PrintToChat() but loops through the whole server
|
||||
// code stolen from the base halflife.inc file
|
||||
stock void Shavit_PrintToChatAll(const char[] format, any ...)
|
||||
@ -2285,5 +2296,6 @@ public void __pl_shavit_SetNTVOptional()
|
||||
MarkNativeAsOptional("Shavit_SetStyleSettingFloat");
|
||||
MarkNativeAsOptional("Shavit_SetStyleSettingBool");
|
||||
MarkNativeAsOptional("Shavit_SetStyleSettingInt");
|
||||
MarkNativeAsOptional("Shavit_GetPlainChatrank");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -112,6 +112,16 @@ public Plugin myinfo =
|
||||
url = "https://github.com/shavitush/bhoptimer"
|
||||
}
|
||||
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
CreateNative("Shavit_GetPlainChatrank", Native_GetPlainChatrank);
|
||||
|
||||
RegPluginLibrary("shavit-chat");
|
||||
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
gEV_Type = GetEngineVersion();
|
||||
@ -1391,3 +1401,116 @@ public void SQL_GetChat_Callback(Database db, DBResultSet results, const char[]
|
||||
results.FetchString(3, gS_CustomMessage[client], 16);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveFromString(char[] buf, char[] thing, int extra)
|
||||
{
|
||||
int index;
|
||||
extra += strlen(thing);
|
||||
while ((index = StrContains(buf, thing, true)) != -1)
|
||||
{
|
||||
while (buf[index] != 0)
|
||||
{
|
||||
buf[index] = buf[index+extra];
|
||||
++index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Native_GetPlainChatrank(Handle handler, int numParams)
|
||||
{
|
||||
char buf[MAXLENGTH_NAME];
|
||||
int client = GetNativeCell(1);
|
||||
bool includename = !(GetNativeCell(4) == 0);
|
||||
int iChatrank = gI_ChatSelection[client];
|
||||
|
||||
if (HasCustomChat(client) && iChatrank == -1 && gB_NameEnabled[client])
|
||||
{
|
||||
strcopy(buf, sizeof(buf), gS_CustomName[client]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iChatrank < 0)
|
||||
{
|
||||
for(int i = 0; i < gA_ChatRanks.Length; i++)
|
||||
{
|
||||
if(HasRankAccess(client, i))
|
||||
{
|
||||
iChatrank = i;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 <= iChatrank <= (gA_ChatRanks.Length - 1))
|
||||
{
|
||||
chatranks_cache_t cache;
|
||||
gA_ChatRanks.GetArray(iChatrank, cache, sizeof(chatranks_cache_t));
|
||||
|
||||
strcopy(buf, sizeof(buf), cache.sName);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizeof(gS_GlobalColorNames); i++)
|
||||
{
|
||||
ReplaceString(buf, sizeof(buf), gS_GlobalColorNames[i], "");
|
||||
}
|
||||
|
||||
if (gEV_Type == Engine_CSGO)
|
||||
{
|
||||
for (int i = 0; i < sizeof(gS_CSGOColorNames); i++)
|
||||
{
|
||||
ReplaceString(buf, sizeof(buf), gS_CSGOColorNames[i], "");
|
||||
}
|
||||
}
|
||||
|
||||
RemoveFromString(buf, "^", 6);
|
||||
RemoveFromString(buf, "{RGB}", 6);
|
||||
RemoveFromString(buf, "&", 8);
|
||||
RemoveFromString(buf, "{RGBA}", 8);
|
||||
|
||||
char sName[MAX_NAME_LENGTH];
|
||||
if (includename /* || iChatRank == -1*/)
|
||||
{
|
||||
GetClientName(client, sName, MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
ReplaceString(buf, sizeof(buf), "{name}", sName);
|
||||
ReplaceString(buf, sizeof(buf), "{rand}", "");
|
||||
|
||||
if (gEV_Type != Engine_TF2)
|
||||
{
|
||||
char sTag[32];
|
||||
CS_GetClientClanTag(client, sTag, 32);
|
||||
ReplaceString(buf, sizeof(buf), "{clan}", sTag);
|
||||
}
|
||||
|
||||
if (gB_Rankings)
|
||||
{
|
||||
int iRank = Shavit_GetRank(client);
|
||||
char sRank[16];
|
||||
IntToString(iRank, sRank, 16);
|
||||
ReplaceString(buf, sizeof(buf), "{rank}", sRank);
|
||||
|
||||
int iRanked = Shavit_GetRankedPlayers();
|
||||
|
||||
if (iRanked == 0)
|
||||
{
|
||||
iRanked = 1;
|
||||
}
|
||||
|
||||
float fPercentile = (float(iRank) / iRanked) * 100.0;
|
||||
FormatEx(sRank, 16, "%.01f", fPercentile);
|
||||
ReplaceString(buf, sizeof(buf), "{rank1}", sRank);
|
||||
|
||||
FormatEx(sRank, 16, "%.02f", fPercentile);
|
||||
ReplaceString(buf, sizeof(buf), "{rank2}", sRank);
|
||||
|
||||
FormatEx(sRank, 16, "%.03f", fPercentile);
|
||||
ReplaceString(buf, sizeof(buf), "{rank3}", sRank);
|
||||
}
|
||||
|
||||
TrimString(buf);
|
||||
SetNativeString(2, buf, GetNativeCell(3), true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -164,6 +164,7 @@ Handle gH_GetPlayerMaxSpeed = null;
|
||||
bool gB_Rankings = false;
|
||||
bool gB_Replay = false;
|
||||
bool gB_Zones = false;
|
||||
bool gB_Chat = false;
|
||||
|
||||
// timer settings
|
||||
stylestrings_t gS_StyleStrings[STYLE_LIMIT];
|
||||
@ -314,7 +315,7 @@ public void OnPluginStart()
|
||||
gCV_AdvertisementInterval = new Convar("shavit_misc_advertisementinterval", "600.0", "Interval between each chat advertisement.\nConfiguration file for those is configs/shavit-advertisements.cfg.\nSet to 0.0 to disable.\nRequires server restart for changes to take effect.", 0, true, 0.0);
|
||||
gCV_Checkpoints = new Convar("shavit_misc_checkpoints", "1", "Allow players to save and teleport to checkpoints.", 0, true, 0.0, true, 1.0);
|
||||
gCV_RemoveRagdolls = new Convar("shavit_misc_removeragdolls", "1", "Remove ragdolls after death?\n0 - Disabled\n1 - Only remove replay bot ragdolls.\n2 - Remove all ragdolls.", 0, true, 0.0, true, 2.0);
|
||||
gCV_ClanTag = new Convar("shavit_misc_clantag", "{tr}{styletag} :: {time}", "Custom clantag for players.\n0 - Disabled\n{styletag} - style tag.\n{style} - style name.\n{time} - formatted time.\n{tr} - first letter of track.\n{rank} - player rank.", 0);
|
||||
gCV_ClanTag = new Convar("shavit_misc_clantag", "{tr}{styletag} :: {time}", "Custom clantag for players.\n0 - Disabled\n{styletag} - style tag.\n{style} - style name.\n{time} - formatted time.\n{tr} - first letter of track.\n{rank} - player rank.\n{cr} - player's chatrank from shavit-chat, trimmed, with no colors", 0);
|
||||
gCV_DropAll = new Convar("shavit_misc_dropall", "1", "Allow all weapons to be dropped?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
|
||||
gCV_ResetTargetname = new Convar("shavit_misc_resettargetname", "0", "Reset the player's targetname upon timer start?\nRecommended to leave disabled. Enable via per-map configs when necessary.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
|
||||
gCV_RestoreStates = new Convar("shavit_misc_restorestates", "0", "Save the players' timer/position etc.. when they die/change teams,\nand load the data when they spawn?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
|
||||
@ -390,6 +391,7 @@ public void OnPluginStart()
|
||||
gB_Rankings = LibraryExists("shavit-rankings");
|
||||
gB_Replay = LibraryExists("shavit-replay");
|
||||
gB_Zones = LibraryExists("shavit-zones");
|
||||
gB_Chat = LibraryExists("shavit-chat");
|
||||
}
|
||||
|
||||
public void OnClientCookiesCached(int client)
|
||||
@ -610,6 +612,11 @@ public void OnLibraryAdded(const char[] name)
|
||||
{
|
||||
gB_Zones = true;
|
||||
}
|
||||
|
||||
else if(StrEqual(name, "shavit-chat"))
|
||||
{
|
||||
gB_Chat = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnLibraryRemoved(const char[] name)
|
||||
@ -628,6 +635,11 @@ public void OnLibraryRemoved(const char[] name)
|
||||
{
|
||||
gB_Zones = false;
|
||||
}
|
||||
|
||||
else if(StrEqual(name, "shavit-chat"))
|
||||
{
|
||||
gB_Chat = false;
|
||||
}
|
||||
}
|
||||
|
||||
int GetHumanTeam()
|
||||
@ -933,10 +945,10 @@ void UpdateScoreboard(int client)
|
||||
void UpdateClanTag(int client)
|
||||
{
|
||||
// no clan tags in tf2
|
||||
char sTag[32];
|
||||
gCV_ClanTag.GetString(sTag, 32);
|
||||
char sCustomTag[32];
|
||||
gCV_ClanTag.GetString(sCustomTag, 32);
|
||||
|
||||
if(gEV_Type == Engine_TF2 || StrEqual(sTag, "0"))
|
||||
if(gEV_Type == Engine_TF2 || StrEqual(sCustomTag, "0"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -997,18 +1009,23 @@ void UpdateClanTag(int client)
|
||||
IntToString(Shavit_GetRank(client), sRank, 8);
|
||||
}
|
||||
|
||||
char sCustomTag[32];
|
||||
strcopy(sCustomTag, 32, sTag);
|
||||
ReplaceString(sCustomTag, 32, "{style}", gS_StyleStrings[gI_Style[client]].sStyleName);
|
||||
ReplaceString(sCustomTag, 32, "{styletag}", gS_StyleStrings[gI_Style[client]].sClanTag);
|
||||
ReplaceString(sCustomTag, 32, "{time}", sTime);
|
||||
ReplaceString(sCustomTag, 32, "{tr}", sTrack);
|
||||
ReplaceString(sCustomTag, 32, "{rank}", sRank);
|
||||
|
||||
if(gB_Chat)
|
||||
{
|
||||
char sChatrank[32];
|
||||
Shavit_GetPlainChatrank(client, sChatrank, sizeof(sChatrank), false);
|
||||
ReplaceString(sCustomTag, 32, "{cr}", sChatrank);
|
||||
}
|
||||
|
||||
Action result = Plugin_Continue;
|
||||
Call_StartForward(gH_Forwards_OnClanTagChangePre);
|
||||
Call_PushCell(client);
|
||||
Call_PushStringEx(sTag, 32, SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||
Call_PushStringEx(sCustomTag, 32, SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||
Call_PushCell(32);
|
||||
Call_Finish(result);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user