From 8403dac85e6667e8813065c964ff5b979106fde3 Mon Sep 17 00:00:00 2001 From: Zoephix Date: Mon, 8 Mar 2021 10:40:22 +0100 Subject: [PATCH] Added chat timestamps --- gamemode/config/sh_config.lua | 4 ++++ gamemode/core/libs/sh_chatbox.lua | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gamemode/config/sh_config.lua b/gamemode/config/sh_config.lua index 97b59708..daf3b332 100644 --- a/gamemode/config/sh_config.lua +++ b/gamemode/config/sh_config.lua @@ -62,6 +62,10 @@ nut.config.add("loocDelayAdmin", false, "Whether or not LOOC chat delay is enabl category = "chat" }) +nut.config.add("chatShowTime", false, "Whether or not to show timestamps in front of chat messages.", nil, { + category = "chat" +}) + nut.config.add("spawnTime", 5, "The time it takes to respawn.", nil, { data = {min = 0, max = 10000}, category = "characters" diff --git a/gamemode/core/libs/sh_chatbox.lua b/gamemode/core/libs/sh_chatbox.lua index 1441575f..01c84288 100644 --- a/gamemode/core/libs/sh_chatbox.lua +++ b/gamemode/core/libs/sh_chatbox.lua @@ -7,6 +7,11 @@ if (!nut.command) then include("sh_command.lua") end +-- Returns a timestamp +function nut.chat.timestamp(ooc) + return nut.config.get("chatShowTime") and (ooc and " " or "").."("..nut.date.getFormatted("%H:%M")..")"..(ooc and "" or " ") or "" +end + -- Registers a new chat type with the information provided. function nut.chat.register(chatType, data) if (!data.onCanHear) then @@ -52,9 +57,10 @@ function nut.chat.register(chatType, data) color = data.onGetColor(speaker, text) end + local timestamp = nut.chat.timestamp(false) local translated = L2(chatType.."Format", name, text) - chat.AddText(color, translated or string.format(data.format, name, text)) + chat.AddText(timestamp, color, translated or timestamp..string.format(data.format, name, text)) end end @@ -303,7 +309,7 @@ do icon = Material(hook.Run("GetPlayerIcon", speaker) or icon) - chat.AddText(icon, Color(255, 50, 50), " [OOC] ", speaker, color_white, ": "..text) + chat.AddText(icon, nut.chat.timestamp(true), Color(255, 50, 50), " [OOC] ", speaker, color_white, ": "..text) end, prefix = {"//", "/ooc"}, noSpaceAfter = true, @@ -334,7 +340,7 @@ do speaker.nutLastLOOC = CurTime() end, onChatAdd = function(speaker, text) - chat.AddText(Color(255, 50, 50), "[LOOC] ", nut.config.get("chatColor"), speaker:Name()..": "..text) + chat.AddText(nut.chat.timestamp(false), Color(255, 50, 50), "[LOOC] ", nut.config.get("chatColor"), speaker:Name()..": "..text) end, onCanHear = nut.config.get("chatRange", 280), prefix = {".//", "[[", "/looc"},