Skip to content

Commit c6d9357

Browse files
committed
Split logic to force lastReceivedMessage from tags.lua
1 parent d9b82fb commit c6d9357

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

lua/custom_chat/client/main.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,23 @@ net.Receive( "customchat.say", function()
698698

699699
CustomChat.lastReceivedMessage = nil
700700
end )
701+
702+
hook.Add( "InitPostEntity", "CustomChat.PostInit", function()
703+
if not aTags then
704+
CustomChat.USE_TAGS = true
705+
end
706+
707+
hook.Add( "OnPlayerChat", "CustomChat.PreprocessPlayerChat", function( ply, text, isTeam, isDead )
708+
-- Make sure the `lastReceivedMessage` table exists when
709+
-- the `OnPlayerChat` hook runs due to the "say" console command.
710+
CustomChat.lastReceivedMessage = CustomChat.lastReceivedMessage or {
711+
speaker = ply,
712+
text = text,
713+
channel = "global"
714+
}
715+
716+
if CustomChat.USE_TAGS then
717+
return CustomChat.Tags:AddMessageWithCustomTags( ply, text, isTeam, isDead )
718+
end
719+
end, HOOK_LOW )
720+
end )

lua/custom_chat/client/tags.lua

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ function Tags:GetNameColor( ply )
2929
return GAMEMODE:GetTeamColor( ply )
3030
end
3131

32-
local function CustomChat_AddCustomTags( ply, text, isTeam, isDead )
32+
function Tags:AddMessageWithCustomTags( ply, text, isTeam, isDead )
3333
if not IsValid( ply ) or not ply:IsPlayer() then return end
3434

35-
CustomChat.lastReceivedMessage = CustomChat.lastReceivedMessage or { speaker = ply, text = text, channel = "global" }
36-
3735
local parts = Tags:GetParts( ply )
3836
local customParts, keepOriginal = hook.Run( "OverrideCustomChatTags", ply )
3937

@@ -47,7 +45,6 @@ local function CustomChat_AddCustomTags( ply, text, isTeam, isDead )
4745
end
4846

4947
if not parts and not customParts then
50-
CustomChat.lastReceivedMessage = nil
5148
return
5249
end
5350

@@ -94,18 +91,10 @@ local function CustomChat_AddCustomTags( ply, text, isTeam, isDead )
9491
Insert( ": " .. text )
9592

9693
chat.AddText( unpack( message ) )
97-
CustomChat.lastReceivedMessage = nil
9894

9995
return true
10096
end
10197

102-
hook.Add( "InitPostEntity", "CustomChat.PreventChatTagsConflict", function()
103-
if aTags then return end
104-
105-
CustomChat.USE_TAGS = true
106-
hook.Add( "OnPlayerChat", "CustomChat.AddCustomTags", CustomChat_AddCustomTags, HOOK_LOW )
107-
end )
108-
10998
function Tags:OpenEditor()
11099
local L = CustomChat.GetLanguageText
111100
local byTeam = table.Copy( Tags.byTeam )

0 commit comments

Comments
 (0)