Skip to content

Commit 9841cb7

Browse files
authored
Merge pull request #38 from wrefgtzweve/absence-cvar
Absence cvar
2 parents 4f35f8e + 999cff9 commit 9841cb7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lua/autorun/sh_custom_chat.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ CreateConVar( "custom_chat_max_lines", "6", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLIC
6464
CreateConVar( "custom_chat_enable_absence_messages", "1", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
6565
"On first spawn, show messages about when a player was last present on the server.", 0, 1 )
6666

67+
CreateConVar( "custom_chat_absence_mintime", "300", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
68+
"Minimum time in seconds to show absence messages. Set to 0 to disable.", 0 )
69+
6770
CreateConVar( "custom_chat_enable_friend_messages", "1", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
6871
"Show messages to players when their friends spawn on the server.", 0, 1 )
6972

lua/custom_chat/client/join_leave.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
113113
if absenceLength < 1 then return end
114114
if CustomChat.GetConVarInt( "enable_absence_messages", 0 ) == 0 then return end
115115

116+
local minTime = CustomChat.GetConVarInt( "absence_mintime", 0 )
117+
if minTime > 0 and absenceLength < minTime then return end
118+
116119
-- Show the last time the server saw this player
117120
local lastSeenTime = CustomChat.NiceTime( math.Round( absenceLength ) )
118121

lua/custom_chat/client/main.lua

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ function CustomChat.GetLanguageText( id )
3232
return language.GetPhrase( "custom_chat." .. id )
3333
end
3434

35+
local year = 60 * 60 * 24 * 365
36+
local month = 60 * 60 * 24 * 30
37+
local day = 60 * 60 * 24
38+
local hour = 60 * 60
39+
local minute = 60
3540
function CustomChat.NiceTime( time )
3641
local L = CustomChat.GetLanguageText
3742

3843
local timeUnits = {
39-
{ value = math.floor( time / ( 60 * 60 * 24 * 30 * 12 ) ), name = "time.years" },
40-
{ value = math.floor( time / ( 60 * 60 * 24 * 30 ) ) % 12, name = "time.months" },
41-
{ value = math.floor( time / ( 60 * 60 * 24 ) ) % 30, name = "time.days" },
42-
{ value = math.floor( time / ( 60 * 60 ) ) % 24, name = "time.hours" },
43-
{ value = math.floor( time / 60 ) % 60, name = "time.minutes" },
44+
{ value = math.floor( time / year ), name = "time.years" },
45+
{ value = math.floor( time / month ) % 12, name = "time.months" },
46+
{ value = math.floor( time / day ) % 30, name = "time.days" },
47+
{ value = math.floor( time / hour ) % 24, name = "time.hours" },
48+
{ value = math.floor( time / minute ) % 60, name = "time.minutes" },
4449
{ value = time % 60, name = "time.seconds" }
4550
}
4651

@@ -52,7 +57,11 @@ function CustomChat.NiceTime( time )
5257
end
5358

5459
local selectedUnits = {}
55-
for i = 1, math.min( 2, #nonZeroUnits ) do
60+
local unitsToShow = 1
61+
if time > month then
62+
unitsToShow = 2
63+
end
64+
for i = 1, math.min( unitsToShow, #nonZeroUnits ) do
5665
table.insert( selectedUnits, nonZeroUnits[i] )
5766
end
5867

0 commit comments

Comments
 (0)