Clientside GM:PlayerConnect to log SteamIDs

Using GM:PlayerConnect, would it be possible to log player names and SteamIDs to a .txt file on a clientside basis? I’m pretty new with Lua, but I’ve had a bit of experience with PHP and Javascript, and I fiddle with E2 from time to time, but I’m struggling to work out how I’d achieve this. PlayerConnect seems to be the only hook that I can find that gives any information about a player connection at all. Is there another function that might be better?

EDIT: Just to clarify, what I want to achieve is a clientside script that automatically saves the SteamID and the name attached to each player upon their connection to the current server, and then adds that to a .txt file

Why would you want their steam id’s clientside?

PlayerConnect is shared anyway. It works on both Client & Server.

Well, my main goal is to achieve automatic SteamID logging for when players connect to a server. This means that I don’t have to constantly type status and condump to achieve the aforementioned goal. I’m an administrator on a large server, and this would be an incredibly convenient alternative to checking previous players and then finding a SteamID converter.

Unfortunately, I don’t know how I would achieve such a script, and I’m wondering if somebody could, essentially, teach me how to achieve that, be it with GM:PlayerConnect or with some other hook or function.

[lua]
require(“glon”)
LOG_STEAMID = {}
LOG_LOGFILE = “SteamIDs/log.txt”
function LoadSteamIds()
if file.Exists(LOG_LOGFILE) then
LOG_STEAMID = glon.decode(file.Read(LOG_LOGFILE)) or {}
end
end
LoadSteamIds()

function SaveSteamIds()
file.Write(LOG_LOGFILE,glon.encode(LOG_STEAMID))
end

function IsDuplicateSteamId(name,steamid)
for k,v in pairs(LOG_STEAMID) do
if v[‘steamid’] == steamid and v[‘name’] ~= name then
v[‘name’] = name;
return true;
end
if v[‘name’] == name then
return true;
end
end
return false;
end

local function LogSteamID(ply)
if IsDuplicateSteamId(steamid) then return; end
local NewLog = {}
NewLog[‘name’] = ply:Name()
NewLog[‘steamid’] = ply:SteamID()
table.insert(LOG_STEAMID,NewLog)
SaveSteamIds()
end
hook.Add(“PlayerInitialSpawn”,“LogSteamID”,LogSteamID)

local function FindNameFromId(ply,cmd,args)
if args[1] == nil then return; end
for k,v in pairs(LOG_STEAMID) do
if v[‘steamid’] == args[1] then
ply:ChatPrint(v[‘name’] … "'s SteamID is " … v[‘steamid’])
return;
end
end
ply:ChatPrint("Could not find a name for " … args[1])
end
concommand.Add(“stmidlog_namefromid”,FindNameFromId)

local function FindIdFromName(ply,cmd,args)
if args[1] == nil then return; end
for k,v in pairs(LOG_STEAMID) do
if v[‘name’] == args[1] then
ply:ChatPrint(v[‘name’] … "'s SteamID is " … v[‘steamid’])
return;
end
end
ply:ChatPrint("Could not find a steamid for " … args[1])
end
concommand.Add(“stmidlog_idfromname”,FindIdFromName)
[/lua]
Got bored, wrote that for you.



] stmidlog_idfromname "Gbps [DTH]"
Gbps [DTH]'s SteamID is STEAM_0:0:19027612

] stmidlog_namefromid "STEAM_0:0:19027612"
Gbps [DTH]'s SteamID is STEAM_0:0:19027612


[editline]03:39PM[/editline]

The script is serverside, but the commands are clientside. I’m sure this is what you’re looking for, as this is the only practical reason of using this.

Those last two functions will be handy.
So this script runs serverside, but logs the SteamIDs on the server, and allows each client to access the SteamID or name attached to the SteamID by calling either of those two functions? That’d actually be reeeeaalllly handy. Thanks a lot. I gave you a love heart because I pretty much love you for writing this up, especially on Christmas. Cheers man.