Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/autorun/sh_custom_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ CreateConVar( "custom_chat_max_lines", "6", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLIC
CreateConVar( "custom_chat_enable_absence_messages", "1", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
"On first spawn, show messages about when a player was last present on the server.", 0, 1 )

CreateConVar( "custom_chat_absence_mintime", "300", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
"Minimum time in seconds to show absence messages. Set to 0 to disable.", 0 )

CreateConVar( "custom_chat_enable_friend_messages", "1", bit.bor( FCVAR_ARCHIVE, FCVAR_REPLICATED, FCVAR_NOTIFY ),
"Show messages to players when their friends spawn on the server.", 0, 1 )

Expand Down
3 changes: 3 additions & 0 deletions lua/custom_chat/client/join_leave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ local function OnPlayerActivated( ply, steamId, name, color, absenceLength )
if absenceLength < 1 then return end
if CustomChat.GetConVarInt( "enable_absence_messages", 0 ) == 0 then return end

local minTime = CustomChat.GetConVarInt( "absence_mintime", 0 )
if minTime > 0 and absenceLength < minTime then return end

-- Show the last time the server saw this player
local lastSeenTime = CustomChat.NiceTime( math.Round( absenceLength ) )

Expand Down
21 changes: 15 additions & 6 deletions lua/custom_chat/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ function CustomChat.GetLanguageText( id )
return language.GetPhrase( "custom_chat." .. id )
end

local year = 60 * 60 * 24 * 365
local month = 60 * 60 * 24 * 30
local day = 60 * 60 * 24
local hour = 60 * 60
local minute = 60
function CustomChat.NiceTime( time )
local L = CustomChat.GetLanguageText

local timeUnits = {
{ value = math.floor( time / ( 60 * 60 * 24 * 30 * 12 ) ), name = "time.years" },
{ value = math.floor( time / ( 60 * 60 * 24 * 30 ) ) % 12, name = "time.months" },
{ value = math.floor( time / ( 60 * 60 * 24 ) ) % 30, name = "time.days" },
{ value = math.floor( time / ( 60 * 60 ) ) % 24, name = "time.hours" },
{ value = math.floor( time / 60 ) % 60, name = "time.minutes" },
{ value = math.floor( time / year ), name = "time.years" },
{ value = math.floor( time / month ) % 12, name = "time.months" },
{ value = math.floor( time / day ) % 30, name = "time.days" },
{ value = math.floor( time / hour ) % 24, name = "time.hours" },
{ value = math.floor( time / minute ) % 60, name = "time.minutes" },
{ value = time % 60, name = "time.seconds" }
}

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

local selectedUnits = {}
for i = 1, math.min( 2, #nonZeroUnits ) do
local unitsToShow = 1
if time > month then
unitsToShow = 2
end
for i = 1, math.min( unitsToShow, #nonZeroUnits ) do
table.insert( selectedUnits, nonZeroUnits[i] )
end

Expand Down