In the [url=http://wiki.garrysmod.com/?title=Gamemode.PlayerAuthed]PlayerAuthed[/url] hook I'm trying to get the player name and print it to the console. This is my test code:
[code]function GM:PlayerAuthed(ply, steamid, uniqid)
ply:PrintMessage(HUD_PRINTCONSOLE, "PlayerAuthed, player name: " .. ply:Name())
end[/code]
When I join the server I then receive this in my console:
[code]PlayerAuthed, player name: [/code]
I've also tried ply:GetName() and ply:Nick() but it looks like those are just aliases.
If I move my code to other hooks that also get passed a player object, it runs fine there. Is there a bug with the PlayerAuthed hook maybe? Or am I being stupid? Thanks in advance.
you're trying to get their name too early
Any suggestion for how I can wait until the name is available? I'd like to be able to log the combination of steamid and name.
Edit: Try this...
[LUA]
function GM:PlayerConnect( pl, steamid )
timer.Simple ( 2, function() if ValidEntity ( pl ) then pl:PrintMessage( HUD_PRINTCONSOLE, "PlayerAuthed, player name: " .. pl:Name().." with SteamID "..pl:SteamID().." has connected" ) end end )
end
[/LUA]
Except that will most likely return STEAM_ID_PENDING.
IIRC, PlayerConnect returns playername, ip
[lua]function GM:PlayerAuthed(pl , steamid , uniqueid)
if not ValidEntity(pl) then
timer.Simple(0.2 , function(p)
p:PrintMessage(HUD_PRINTCONSOLE, "PlayerAuthed, player name: " .. p:Name())
end , pl )
else
pl:PrintMessage(HUD_PRINTCONSOLE, "PlayerAuthed, player name: " .. pl:Name())
end
end
[/lua]
Sorry, you need to Log In to post a reply to this thread.