• Last join time info
    7 replies, posted
Hi everyone! I was wondering if anyone could point me in the direction of addon that shows las join time in chat when player connects. Something like "*NAME* last joined 30 hours ago". Thanks!
I know the admin mod "Evolve" has this, and is probably what you have seen.
Thanks, other ways?
I don't think there are any other addons, you could always code it yourself or hire someone.
[QUOTE=Pandaman09;40972312]I don't think there are any other addons, you could always code it yourself or hire someone.[/QUOTE] Yeah, it's true. But i don't have time...
[lua]local function formatSteamID(stid) -- File names cannot contain colons, so we replace them here return string.gsub(stid, ":", "_") end local function formatTimeDifference(time) -- All we have is a number- make it pretty local diff = os.time() - time -- diff will be in seconds local amt = 0 local unit = "" if (diff < 60) then return "less than one minute ago" elseif (diff >= 60 and diff < 3600) then -- 1 minute to 1 hour amt = math.floor(diff / 60) unit = "minute" elseif (diff >= 3600 and diff < 86400) then -- 1 hour to 1 day amt = math.floor(diff / 3600) unit = "hour" elseif (diff >= 86400 and diff < 604800) -- 1 day to 1 week amt = math.floor(diff / 86400) unit = "day" else -- more than 1 week, you get the drill amt = math.floor(diff / 604800) unit = "week" end if (amt > 1) then unit = unit .. "s" end -- Plurals are cool, too return amt .. " " .. unit .. " ago" end local function chatAll(text) for k, v in pairs(player.GetAll()) do v:ChatPrint(text) end end local function GetLastJoinTime(pl) local fname = "jointimes/" .. formatSteamID(pl:SteamID()) .. ".txt" local retval = false if (file.Exists(fname, "DATA")) then retval = true pl.LastJoinTime = tonumber(file.Read(fname, "DATA")) end file.Write(fname, os.time()) return retval end hook.Add("PlayerInitialSpawn", "LastJoinTime", function(pl) if (GetLastJoinTime(pl)) then chatAll(pl:Name() .. " has connected. Last joined " .. formatTimeDifference(pl.LastJoinTime) .. ".") else chatAll(pl:Name() .. " has connected for the first time.") end end)[/lua] Untested, but this should work. Stores timestamps in text files. Not the best method but it's quick and easy. For Christ's sake I hate posting Lua, the forums always manage to fuck me.
Should probably get in the habbit of string.lower on the file.write now that the new 'bug' is considering a feature.
[QUOTE=KingofBeast;40990056][lua]local function formatSteamID(stid) -- File names cannot contain colons, so we replace them here return string.gsub(stid, ":", "_") end local function formatTimeDifference(time) -- All we have is a number- make it pretty local diff = os.time() - time -- diff will be in seconds local amt = 0 local unit = "" if (diff < 60) then return "less than one minute ago" elseif (diff >= 60 and diff < 3600) then -- 1 minute to 1 hour amt = math.floor(diff / 60) unit = "minute" elseif (diff >= 3600 and diff < 86400) then -- 1 hour to 1 day amt = math.floor(diff / 3600) unit = "hour" elseif (diff >= 86400 and diff < 604800) -- 1 day to 1 week amt = math.floor(diff / 86400) unit = "day" else -- more than 1 week, you get the drill amt = math.floor(diff / 604800) unit = "week" end if (amt > 1) then unit = unit .. "s" end -- Plurals are cool, too return amt .. " " .. unit .. " ago" end local function chatAll(text) for k, v in pairs(player.GetAll()) do v:ChatPrint(text) end end local function GetLastJoinTime(pl) local fname = "jointimes/" .. formatSteamID(pl:SteamID()) .. ".txt" local retval = false if (file.Exists(fname, "DATA")) then retval = true pl.LastJoinTime = tonumber(file.Read(fname, "DATA")) end file.Write(fname, os.time()) return retval end hook.Add("PlayerInitialSpawn", "LastJoinTime", function(pl) if (GetLastJoinTime(pl)) then chatAll(pl:Name() .. " has connected. Last joined " .. formatTimeDifference(pl.LastJoinTime) .. ".") else chatAll(pl:Name() .. " has connected for the first time.") end end)[/lua] Untested, but this should work. Stores timestamps in text files. Not the best method but it's quick and easy. For Christ's sake I hate posting Lua, the forums always manage to fuck me.[/QUOTE] I gonna test it. Anyway it's a really good base! Thanks, man!
Sorry, you need to Log In to post a reply to this thread.