Skip to content

Commit a31e639

Browse files
authored
Restore default chat behavior while paused (#905)
The problem is that `gpGlobals->curtime` doesn't change in pause, it's used by dataprop `m_fLastPlayerTalkTime`, so chat doesn't work during pause, previously the code in the plugin compensated for this, which changed the default game behavior, and all the code in the game function `Host_Say` was ignored, and some things, such as plugins intercepting the `player_say` event, did not work correctly. In fact, in this function `Host_Say`, there is a lot of code, much more than in plugin `pause`, for example adding a prefix to the message, formatting the text in the correct form, checking the validity of the message, creating event `player_say`, checking whether each player can hear you, etc. Some bugs for example: `HlstastsX` (used to collect stats and chat) did not collect chat stats. Plugins allowing to ignore another player could not work.
1 parent bf86334 commit a31e639

1 file changed

Lines changed: 26 additions & 42 deletions

File tree

addons/sourcemod/scripting/pause.sp

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
public Plugin myinfo =
3434
{
3535
name = "Pause plugin",
36-
author = "CanadaRox, Sir, Forgetest",
36+
author = "CanadaRox, Sir, Forgetest, A1m`",
3737
description = "Adds pause functionality without breaking pauses, also prevents SI from spawning because of the Pause.",
38-
version = "6.7.1",
38+
version = "6.8",
3939
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
4040
};
4141

@@ -178,6 +178,7 @@ public void OnClientPutInServer(int client)
178178
if (!IsFakeClient(client))
179179
{
180180
CPrintToChatAll("%t %t", "Tag", "ClientFullyLoaded", client);
181+
SetEntPropFloat(client, Prop_Data, "m_fLastPlayerTalkTime", 0.0);
181182
}
182183
}
183184
}
@@ -501,15 +502,17 @@ void Pause()
501502
CPrintToChat(client, "%t %t", "Tag", "PausePreventSpawn");
502503
}
503504
}
504-
505+
506+
SetEntPropFloat(client, Prop_Data, "m_fLastPlayerTalkTime", 0.0);
507+
505508
if (!pauseProcessed)
506509
{
507510
sv_pausable.BoolValue = true;
508511
FakeClientCommand(client, "pause");
509512
sv_pausable.BoolValue = false;
510513
pauseProcessed = true;
511514
}
512-
515+
513516
if (team == L4D2Team_Spectator)
514517
{
515518
sv_noclipduringpause.ReplicateToClient(client, "1");
@@ -542,6 +545,8 @@ void Unpause(bool real = true)
542545
{
543546
if (IsClientInGame(client) && !IsFakeClient(client))
544547
{
548+
SetEntPropFloat(client, Prop_Data, "m_fLastPlayerTalkTime", 0.0);
549+
545550
if(!unpauseProcessed)
546551
{
547552
sv_pausable.BoolValue = true;
@@ -759,18 +764,20 @@ void ToggleCommandListeners(bool enable)
759764
{
760765
if (enable && !listened)
761766
{
762-
AddCommandListener(Say_Callback, "say");
763-
AddCommandListener(TeamSay_Callback, "say_team");
764767
AddCommandListener(Unpause_Callback, "unpause");
765768
AddCommandListener(Callvote_Callback, "callvote");
769+
770+
HookEvent("player_say", Event_PlayerSay, EventHookMode_Post);
771+
766772
listened = true;
767773
}
768774
else if (!enable && listened)
769775
{
770-
RemoveCommandListener(Say_Callback, "say");
771-
RemoveCommandListener(TeamSay_Callback, "say_team");
772776
RemoveCommandListener(Unpause_Callback, "unpause");
773777
RemoveCommandListener(Callvote_Callback, "callvote");
778+
779+
UnhookEvent("player_say", Event_PlayerSay, EventHookMode_Post);
780+
774781
listened = false;
775782
}
776783
}
@@ -840,45 +847,22 @@ Action Callvote_Callback(int client, char[] command, int argc)
840847
return Plugin_Handled;
841848
}
842849

843-
Action Say_Callback(int client, char[] command, int argc)
850+
void Event_PlayerSay(Event hEvent, const char[] sEventName, bool bDontBroadcast)
844851
{
845-
if (isPaused)
846-
{
847-
char buffer[256];
848-
GetCmdArgString(buffer, sizeof(buffer));
849-
StripQuotes(buffer);
850-
if (IsChatTrigger() || buffer[0] == '!' || buffer[0] == '/') // Hidden command or chat trigger
851-
{
852-
return Plugin_Handled;
853-
}
854-
if (client == 0)
855-
{
856-
PrintToChatAll("Console : %s", buffer);
857-
}
858-
else
859-
{
860-
CPrintToChatAllEx(client, "{teamcolor}%N{default} : %s", client, buffer);
861-
}
862-
return Plugin_Handled;
863-
}
864-
return Plugin_Continue;
852+
int iUserId = hEvent.GetInt("userid");
853+
RequestFrame(FrameDelay_PlayerSay, iUserId);
865854
}
866855

867-
Action TeamSay_Callback(int client, char[] command, int argc)
856+
void FrameDelay_PlayerSay(int iUserId)
868857
{
869-
if (isPaused)
870-
{
871-
char buffer[256];
872-
GetCmdArgString(buffer, sizeof(buffer));
873-
StripQuotes(buffer);
874-
if (IsChatTrigger() || buffer[0] == '!' || buffer[0] == '/') // Hidden command or chat trigger
875-
{
876-
return Plugin_Handled;
877-
}
878-
PrintToTeam(client, GetClientTeam(client), buffer);
879-
return Plugin_Handled;
858+
int iClient = GetClientOfUserId(iUserId);
859+
if (iClient < 1 || !isPaused) {
860+
return;
880861
}
881-
return Plugin_Continue;
862+
863+
// During a pause the time (gpGlobals->curtime) does not change.
864+
// Let's reset this property for the chat to work.
865+
SetEntPropFloat(iClient, Prop_Data, "m_fLastPlayerTalkTime", 0.0);
882866
}
883867

884868
Action Unpause_Callback(int client, char[] command, int argc)

0 commit comments

Comments
 (0)