Update basetriggers ShowFriendlyFire to use the same chat text visibility system as ShowTimeLeft (#1494)

This system is a bit sketchy but I didn't want to rework the entire thing. (If this were to be reworked, it should probably use ReplyToCommand for a lot of this).

This also allows the server to call ff and get a result.
This commit is contained in:
FlaminSarge 2021-06-24 07:45:56 -07:00 committed by GitHub
parent d73f4e7eca
commit 0d956b229f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,9 +60,9 @@ ConVar g_Cvar_WinLimit;
ConVar g_Cvar_FragLimit; ConVar g_Cvar_FragLimit;
ConVar g_Cvar_MaxRounds; ConVar g_Cvar_MaxRounds;
#define TIMELEFT_ALL_ALWAYS 0 /* Print to all players */ #define PRINT_TO_ALL_ALWAYS 0 /* Print to all players */
#define TIMELEFT_ALL_MAYBE 1 /* Print to all players if sm_trigger_show allows */ #define PRINT_TO_ALL_MAYBE 1 /* Print to all players if sm_trigger_show allows */
#define TIMELEFT_ONE 2 /* Print to a single player */ #define PRINT_TO_ONE 2 /* Print to a single player */
bool mapchooser; bool mapchooser;
@ -188,12 +188,12 @@ public void ConVarChange_TimeleftInterval(ConVar convar, const char[] oldValue,
public Action Timer_DisplayTimeleft(Handle timer) public Action Timer_DisplayTimeleft(Handle timer)
{ {
ShowTimeLeft(0, TIMELEFT_ALL_ALWAYS); ShowTimeLeft(0, PRINT_TO_ALL_ALWAYS);
} }
public Action Command_Timeleft(int client, int args) public Action Command_Timeleft(int client, int args)
{ {
ShowTimeLeft(client, TIMELEFT_ONE); ShowTimeLeft(client, PRINT_TO_ONE);
return Plugin_Handled; return Plugin_Handled;
} }
@ -238,16 +238,7 @@ public Action Command_Motd(int client, int args)
public Action Command_FriendlyFire(int client, int args) public Action Command_FriendlyFire(int client, int args)
{ {
if (client == 0) ShowFriendlyFire(client, PRINT_TO_ONE);
{
ReplyToCommand(client, "[SM] %t", "Command is in-game only");
return Plugin_Handled;
}
if (!IsClientInGame(client))
return Plugin_Handled;
ShowFriendlyFire(client);
return Plugin_Handled; return Plugin_Handled;
} }
@ -259,7 +250,7 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char
} }
else if (strcmp(sArgs, "timeleft", false) == 0) else if (strcmp(sArgs, "timeleft", false) == 0)
{ {
ShowTimeLeft(client, TIMELEFT_ALL_MAYBE); ShowTimeLeft(client, PRINT_TO_ALL_MAYBE);
} }
else if (strcmp(sArgs, "thetime", false) == 0) else if (strcmp(sArgs, "thetime", false) == 0)
{ {
@ -277,7 +268,7 @@ public void OnClientSayCommand_Post(int client, const char[] command, const char
} }
else if (strcmp(sArgs, "ff", false) == 0) else if (strcmp(sArgs, "ff", false) == 0)
{ {
ShowFriendlyFire(client); ShowFriendlyFire(client, PRINT_TO_ALL_MAYBE);
} }
else if (strcmp(sArgs, "currentmap", false) == 0) else if (strcmp(sArgs, "currentmap", false) == 0)
{ {
@ -336,8 +327,8 @@ void ShowTimeLeft(int client, int who)
char finalOutput[1024]; char finalOutput[1024];
if (who == TIMELEFT_ALL_ALWAYS if (who == PRINT_TO_ALL_ALWAYS
|| (who == TIMELEFT_ALL_MAYBE && g_Cvar_TriggerShow.IntValue)) || (who == PRINT_TO_ALL_MAYBE && g_Cvar_TriggerShow.IntValue))
{ {
client = 0; client = 0;
} }
@ -491,8 +482,8 @@ void ShowTimeLeft(int client, int who)
FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client); FormatEx(finalOutput, sizeof(finalOutput), "%T", "NoTimelimit", client);
} }
if (who == TIMELEFT_ALL_ALWAYS if (who == PRINT_TO_ALL_ALWAYS
|| (who == TIMELEFT_ALL_MAYBE && g_Cvar_TriggerShow.IntValue)) || (who == PRINT_TO_ALL_MAYBE && g_Cvar_TriggerShow.IntValue))
{ {
PrintToChatAll("[SM] %s", finalOutput); PrintToChatAll("[SM] %s", finalOutput);
} }
@ -507,7 +498,7 @@ void ShowTimeLeft(int client, int who)
} }
} }
void ShowFriendlyFire(int client) void ShowFriendlyFire(int client, int who)
{ {
if (g_Cvar_FriendlyFire) if (g_Cvar_FriendlyFire)
{ {
@ -521,13 +512,20 @@ void ShowFriendlyFire(int client)
strcopy(phrase, sizeof(phrase), "Friendly Fire Off"); strcopy(phrase, sizeof(phrase), "Friendly Fire Off");
} }
if (g_Cvar_TriggerShow.IntValue) if (who == PRINT_TO_ALL_ALWAYS
|| (who == PRINT_TO_ALL_MAYBE && g_Cvar_TriggerShow.IntValue))
{ {
client = 0;
PrintToChatAll("[SM] %t", phrase); PrintToChatAll("[SM] %t", phrase);
} }
else else if (client != 0 && IsClientInGame(client))
{ {
PrintToChat(client,"[SM] %t", phrase); PrintToChat(client, "[SM] %t", phrase);
}
if (client == 0)
{
PrintToServer("[SM] %T", phrase, client);
} }
} }
} }