How would I access the UniqueID if I only have a player's SteamID to go with (they're not in the server)
That's (one of) the problem(s) with UniqueIDs. You can only get the UniqueID of a player who is on the server. I wonder why Megiddo hasn't updated UTime to use SteamIDs, because UniqueIDs are absolutely horrible.
Lucky for you, I modified UTime to use SteamIDs. It's a bit more complicated than simply changing the UniqueID to a SteamID64 because I wanted to keep my existing players' times. I manually renamed the utime table to utime_old using SqliteBrowser, but that isn't a very good idea (as I learned, by accidentally corrupting my database). Instead, use this code to do it for you:
WARNING: Do NOT do this with players on your server, because there is a strong likelyhood that UTime will try to log someone's time while you are changing the tables and that might mess up your UTime table, maybe even your entire database if you're unlucky. I strongly recommend you password-protect your server while doing this, and do everything from console. If you want to be even more secure, backup your sv.db file before doing any of this. I am not responsible for any damages to your server, you do this at your own risk.
Save this code to a lua file and put it in garrysmod/lua/:
sql.Query( "ALTER TABLE utime RENAME TO utime_old;" )
sql.Query( "DROP INDEX IDX_UTIME_PLAYER;" )
sql.Query( "CREATE INDEX IDX_UTIME_OLD_PLAYER ON utime_old ( player DESC );" )
Then run this command in your console, replacing <filename> with what you saved your file as:
lua_openscript <filename>If you want to, you can check that this worked by opening your sv.db file with an Sqlite browser and checking that there is a utime_old table and a IDX_UTIME_OLD_PLAYER index.
Now, for the actual logging (also don't do this with anyone online):
Change line 13 of garrysmod/addons/utime/lua/autorun/sv_utime.lua from this:
local uid = player:UniqueID()
to this:
local steamid64 = player:SteamID64()
Then change the if statement on lines 17-28 to this (the new if statement should extend to line 37):
if row then
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
end
sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. steamid64 .. ";" )
time = row.totaltime
else
row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime_old WHERE player = " .. uid .. ";" )
if row then
time = row.totaltime
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
end
sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. steamid64 .. ", " .. time .. ", " .. os.time() .. " );" )
else
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" )
end
sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. steamid64 .. ", 0, " .. os.time() .. " );" )
end
end
Here is what the whole onJoin() function should look like at the end:
function onJoin( ply )
local steamid64 = ply:SteamID64()
local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" )
local time = 0
if row then
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
end
sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. steamid64 .. ";" )
time = row.totaltime
else
row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime_old WHERE player = " .. uid .. ";" )
if row then
time = row.totaltime
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
end
sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. steamid64 .. ", " .. time .. ", " .. os.time() .. " );" )
else
if utime_welcome:GetInt() then
ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" )
end
sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. steamid64 .. ", 0, " .. os.time() .. " );" )
end
end
ply:SetUTime( time )
ply:SetUTimeStart( CurTime() )
end
Once you have edited it, save the file and re-upload it to your server. Change the map (ulx map <name> from console, no going on the server yet!) and wait until it has finished loading. Now you can join the server and test it. You should be able to see the new utime table, sorted by SteamID64s, and you should be in it along with your old time.
Feel free to ask me if you have any questions.