1- function OnEngineMessage (p_Message )
1+ class ' AdvancedChatMessages'
2+
3+ function AdvancedChatMessages :__init ()
4+ -- Subscribe to events.
5+ self .m_EngineMessageEvent = Events :Subscribe (' Engine:Message' , self , self .OnEngineMessage )
6+ end
7+
8+ function AdvancedChatMessages :OnEngineMessage (p_Message )
9+ if p_Message == nil then
10+ return
11+ end
12+
213 -- We only care about UIHudChatMessages.
314 if p_Message .category ~= MessageCategory .UI or p_Message .type ~= MessageType .UIHudChatMessage then
4- return true
15+ return
516 end
617
718 -- Get the message, process it and pass it to our custom
819 -- WebUI package for rendering.
920 local s_Message = UIHudChatMessage (p_Message )
10-
21+
1122 if s_Message .channel == ChatChannelType .Admin then
1223 -- This is a workaround because many RCON tools prepend
1324 -- "Admin: " to admin messages.
1425 local s_String = s_Message .string :gsub (" ^Admin: " , ' ' )
1526
1627 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:all", "Admin", %s);' , WebUI :QuoteString (s_String )))
17- return true
28+ return
1829 end
1930
2031 -- Get the player sending the message, and our local player.
@@ -23,41 +34,41 @@ function OnEngineMessage(p_Message)
2334
2435 -- Players not found; cancel.
2536 if s_OtherPlayer == nil or s_LocalPlayer == nil then
26- return true
37+ return
2738 end
2839
2940 -- Player is a spectator.
3041 if s_OtherPlayer .teamID == 0 then
3142 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:spectator", %s, %s);' , WebUI :QuoteString (s_OtherPlayer .name ), WebUI :QuoteString (s_Message .string )))
32- return true
43+ return
3344 end
3445
3546 -- Player is on a different team; display enemy message.
3647 if (s_LocalPlayer .teamID == 0 and s_OtherPlayer .teamID == 2 ) or (s_LocalPlayer .teamID ~= 0 and s_OtherPlayer .teamID ~= s_LocalPlayer .teamID ) then
3748 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:enemy", %s, %s);' , WebUI :QuoteString (s_OtherPlayer .name ), WebUI :QuoteString (s_Message .string )))
38- return true
49+ return
3950 end
4051
4152 -- Player is in the same team.
4253 -- Display global message.
4354 if s_Message .channel == ChatChannelType .SayAll and s_LocalPlayer .teamID ~= 0 then
4455 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:all", %s, %s);' , WebUI :QuoteString (s_OtherPlayer .name ), WebUI :QuoteString (s_Message .string )))
45- return true
56+ return
4657 end
4758
4859 -- Display team message.
4960 if s_Message .channel == ChatChannelType .Team or s_LocalPlayer .teamID == 0 then
5061 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:team", %s, %s);' , WebUI :QuoteString (s_OtherPlayer .name ), WebUI :QuoteString (s_Message .string )))
51- return true
62+ return
5263 end
5364
5465 -- Display squad message.
5566 if s_Message .channel == ChatChannelType .Squad or s_Message .channel == ChatChannelType .SquadLeader then
5667 WebUI :ExecuteJS (string.format (' AdvancedChat.trigger("message:squad", %s, %s);' , WebUI :QuoteString (s_OtherPlayer .name ), WebUI :QuoteString (s_Message .string )))
57- return true
68+ return
5869 end
5970
60- return true
71+ return
6172end
6273
63- Events : Subscribe ( ' Engine:Message ' , OnEngineMessage )
74+ return AdvancedChatMessages
0 commit comments