From 31b69224b17501e282cb26c27d3c71ab064270aa Mon Sep 17 00:00:00 2001 From: Azumgi Date: Fri, 26 Jan 2018 17:46:18 +0300 Subject: [PATCH] Forgot to add chat.lua to commit with unsent messages --- vmf_source/scripts/mods/vmf/modules/chat.lua | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 vmf_source/scripts/mods/vmf/modules/chat.lua diff --git a/vmf_source/scripts/mods/vmf/modules/chat.lua b/vmf_source/scripts/mods/vmf/modules/chat.lua new file mode 100644 index 0000000..fa31339 --- /dev/null +++ b/vmf_source/scripts/mods/vmf/modules/chat.lua @@ -0,0 +1,32 @@ +local vmf = get_mod("VMF") + +-- #################################################################################################################### +-- ##### Hooks Functions ############################################################################################## +-- #################################################################################################################### + +-- HOOK: [ChatManager.register_channel] +local hook_send_unsent_messages = function (func, self, channel_id, members_func) + + func(self, channel_id, members_func) + + if channel_id == 1 then + for _, message in ipairs(vmf.unsended_chat_messages) do + self:add_local_system_message(1, message, true) + end + end +end + +-- #################################################################################################################### +-- ##### Event functions ############################################################################################## +-- #################################################################################################################### + +-- at the moment of loading VMF Chat Manager is not initialized yet, +-- so it should be hooked with some delay +vmf.hook_chat_manager = function() + + if not vmf.is_chat_manager_hooked then + vmf.is_chat_manager_hooked = true + + vmf:hook("ChatManager.register_channel", hook_send_unsent_messages) + end +end \ No newline at end of file