make Shavit_PrintToChatAll a native so it can use gB_StopChatSound 'better'

This commit is contained in:
rtldg 2021-05-06 02:03:37 +00:00
parent 5f099a090b
commit cdc0c651b9
2 changed files with 33 additions and 21 deletions

View File

@ -1994,7 +1994,6 @@ native float Shavit_GetClosestReplayVelocityDifference(int client, bool threeD);
/**
* Use this native to stop the click sound that plays upon chat messages.
* Call it before each Shavit_PrintToChat().
* Shavit_PrintToChatAll() is not guaranteed to disable the sound from playing.
*
* @noreturn
*/
@ -2069,6 +2068,16 @@ native int Shavit_CanPause(int client);
*/
native int Shavit_PrintToChat(int client, const char[] format, any ...);
/**
* Use this native when printing anything in chat if it's related to the timer.
* This native will auto-assign colors and a chat prefix.
*
* @param format Formatting rules.
* @param any Variable number of format parameters.
* @noreturn
*/
native void Shavit_PrintToChatAll(const char[] format, any ...);
/**
* Logs an entry to bhoptimer's log file.
* (addons/sourcemod/logs/shavit.log)
@ -2307,23 +2316,6 @@ native void Shavit_GetPlainChatrank(int client, char[] buf, int buflen, bool inc
*/
native void Shavit_DeleteWR(int style, int track, const char[] map, int accountid, int recordid, bool delete_sql, bool update_cache);
// 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 ...)
{
char buffer[300];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
SetGlobalTransTarget(i);
VFormat(buffer, 300, format, 2);
Shavit_PrintToChat(i, "%s", buffer);
}
}
}
public SharedPlugin __pl_shavit =
{
name = "shavit",
@ -2415,6 +2407,7 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_OpenStatsMenu");
MarkNativeAsOptional("Shavit_PauseTimer");
MarkNativeAsOptional("Shavit_PrintToChat");
MarkNativeAsOptional("Shavit_PrintToChatAll");
MarkNativeAsOptional("Shavit_Rankings_DeleteMap");
MarkNativeAsOptional("Shavit_ReloadLeaderboards");
MarkNativeAsOptional("Shavit_ReloadReplay");

View File

@ -232,6 +232,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_MarkKZMap", Native_MarkKZMap);
CreateNative("Shavit_PauseTimer", Native_PauseTimer);
CreateNative("Shavit_PrintToChat", Native_PrintToChat);
CreateNative("Shavit_PrintToChatAll", Native_PrintToChatAll);
CreateNative("Shavit_RestartTimer", Native_RestartTimer);
CreateNative("Shavit_ResumeTimer", Native_ResumeTimer);
CreateNative("Shavit_SaveSnapshot", Native_SaveSnapshot);
@ -1770,15 +1771,33 @@ public int Native_StopChatSound(Handle handler, int numParams)
gB_StopChatSound = true;
}
public int Native_PrintToChatAll(Handle plugin, int numParams)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i))
{
SetGlobalTransTarget(i);
bool previousStopChatSound = gB_StopChatSound;
SemiNative_PrintToChat(i, 1);
gB_StopChatSound = previousStopChatSound;
}
}
}
public int Native_PrintToChat(Handle handler, int numParams)
{
int client = GetNativeCell(1);
return SemiNative_PrintToChat(client, 2);
}
static int iWritten = 0; // useless?
public int SemiNative_PrintToChat(int client, int formatParam)
{
int iWritten;
char sBuffer[256];
char sInput[300];
FormatNativeString(0, 2, 3, sizeof(sInput), iWritten, sInput);
FormatNativeString(0, formatParam, formatParam+1, sizeof(sInput), iWritten, sInput);
// space before message needed show colors in cs:go
// strlen(sBuffer)>252 is when CSS stops printing the messages
FormatEx(sBuffer, (gB_Protobuf ? sizeof(sBuffer) : 253), "%s%s %s%s", (gB_Protobuf ? " ":""), gS_ChatStrings.sPrefix, gS_ChatStrings.sText, sInput);