Source-Chat-Relay bot reads in-game chat messages (and sends them to Discord) via OnClientSayCommand_Post(). SF2 uses command listeners and calls FakeClientCommand() to send message to team chat. Because of this bot reads and sends one message two times (due to original say "Text" (which are blocked in command listener but not in OnClientSayCommand()) and its duplicate say_team "Text").
I suggest to use OnClientSayCommand() instead of two command listeners (say and say_team) because it should block original message and bot won't see original say message if this message are moved to say_team.
Code Snippet (didn't test):
public void OnClientSayCommand(int client, const char[] command, const char[] sArgs) {
if ( !g_bPlayerCalledForNightmare[client] )
g_bPlayerCalledForNightmare[client] = ( StrContains( sArgs, "nightmare", false ) != -1 || StrContains( sArgs, "Nightmare", false ) != -1 );
if ( !g_bEnabled || g_cvAllChat.BoolValue || SF_IsBoxingMap() ) return Plugin_Continue;
if ( !IsRoundEnding() ) {
bool bSayTeam = strcmp( command, "say_team" ) == 0;
if ( g_bPlayerEliminated[client] ) {
if ( !IsPlayerAlive( client ) && GetClientTeam( client ) == TFTeam_Red )
return Plugin_Stop; // Plugin_Stop in this case stops message AND post hook so bot won't see message in OnClientSayCommand_Post()
char szMessage[256];
FormatEx( szMessage, sizeof szMessage, "{blue}%N:{default} %s", client, sArgs );
//Broadcast the msg to the source tv, if the server has one.
PrintToSourceTV( szMessage );
if ( !bSayTeam ) {
FakeClientCommandEx( client, "say_team '%s'", sArgs );
return Plugin_Stop;
}
}
if ( !bSayTeam ) {
char szMessage[256];
FormatEx( szMessage, sizeof szMessage, "{red}%N:{default} %s", client, sArgs );
//Broadcast the msg to the source tv, if the server has one.
PrintToSourceTV( szMessage );
}
}
return Plugin_Continue;
}
Also, i'm not sure about escaping text in FakeClientCommandEx( client, "say_team '%s'", sArgs );
Source-Chat-Relay bot reads in-game chat messages (and sends them to Discord) via
OnClientSayCommand_Post()
. SF2 uses command listeners and callsFakeClientCommand()
to send message to team chat. Because of this bot reads and sends one message two times (due to originalsay "Text"
(which are blocked in command listener but not inOnClientSayCommand()
) and its duplicatesay_team "Text"
).I suggest to use
OnClientSayCommand()
instead of two command listeners (say
andsay_team
) because it should block original message and bot won't see originalsay
message if this message are moved tosay_team
.Code Snippet (didn't test):
Also, i'm not sure about escaping text in
FakeClientCommandEx( client, "say_team '%s'", sArgs );