Retrieving nickname from SteamID?

Is there any way of doing this, when the player is not in the server?

You could do


function player.GetBySteamID( id )
	for _, ply in pairs(player.GetAll()) do
		if ply:SteamID() == id then
			return ply
		end
	end
	return false
end


then do
player.GetBySteamID(STEAM_0:0:000000):Nick()

I don’t think that would work if the player has left?

look into the steamworks.* functions

EDIT:
I hate when you fucking retarded people disagree with me for no fucking reason.


(User was banned for this post ("Flaming / Cares about ratings" - Craptasket))

If you don’t mind player names being potentially out of date, you could write their name when they were connected and their steamid to a database/file and then call that.

Alternatively you could use http://steamcommunity.com/dev/apikey and use the steam api to get their profile in JSON or something.

You will need to use the Steam Web API to get this information when they are not in your server. Can even do it in-game if needed using http.Fetch, and turn the results into a table using util.JSONToTable.

Edit: woops nevermind, turns out steamworks.RequestPlayerInfo works fine clientside, example below will work for a server-side solution though.

Server-side Example
[lua]
local APIKey = “xxx”;

function GetPlayerSummary( steamid64, callback )

local uri = string.format( "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s", tostring( APIKey ), tostring( steamid64 ) );

local onSuccess = function( body, len, headers, code )

	local json = (body and util.JSONToTable( tostring( body ) ) or {});

	if( callback ) then

		local tbl = (json.response.players and json.response.players[1] or {});

		callback( tbl );

	end

end

local onFailure = function( err )

	if( callback ) then

		callback( {} );

	end

end

http.Fetch( uri, onSuccess, onFailure );

end

GetPlayerSummary( “76561197978593283”, function( tbl )

PrintTable( tbl );

end );
[/lua]

[del]The steamworks library only works in the menu environment[/del], no need to flame.

That’s a lie. Only some things in the steamworks are menu state only. I flame because people like you think you know everything but you don’t.

Ah my bad then, I didn’t think any steamworks stuff worked from the client once they were ingame, you were correct.



local function GetPlayerName(steamid, fn)
	local max = 5;
	local i = 0;
	local r;
	function r()
		if(steamworks.GetPlayerName(steamid) ~= "[unknown]") then
			local name = steamworks.GetPlayerName(steamid);
			fn(name);
		else
			i = i + 1;
			if(i >= max) then fn("[unknown]"); end
			steamworks.RequestPlayerInfo(steamid);
			timer.Simple(1, r);
		end
	end
	timer.Simple(1, r);
end

local function SteamIDTo64(stmd)
	local s = stmd:sub(9, 9);
	local s2 = stmd:sub(11);
	local num = ((s2 + s) * 2);
	return "7656119"..(num + 7960265728); -- deal with it 
end

GetPlayerName(SteamIDTo64("STEAM_0:0:44950009"), function(name)
	print(name);
end);


You do realize there’s util.SteamIDTo64 now right?

had no idea, thanks

You could do something like this: https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect_with_list_example.lua.html

for players that have connected; you could also store the list in a file and reload it when the game starts.