A way to get an offline player steam name? (100+ people)
10 replies, posted
I didn't code for like half a year now and forgot a lot of things so 'scuse me if this makes no sense or is too easy but..
I've got a list (100+- of people) of Steam IDs and every time a player opens a VGUI I need to get the Steam name of each one of them. I figured that if I just save the name the user can just change it thus it becoming outdated.
I can still save it and pass a check on player spawn if it changed since last time but is there another possible way which I may be missing?
I could also post the 64 ID to a php checker and return the name but that may actually load the server too much if a player spams the VGUI would it not?
Just create a table using their SteamID64 as the key and their name as the value, then when [URL="http://wiki.darkrp.com/index.php/Hooks/server/onplayerchangedname"]this[/URL] is called (if using DarkRP) else when they join using [URL="http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn"]this[/URL] and when they leave using [URL="http://wiki.garrysmod.com/page/GM/PlayerDisconnected"]this[/URL] update the table. Store the table with whatever method you prefer, txt document, MySQL, whatever.
There is a hook for when a player changes their name but I can't be bothered to find it
then all you need to do is tbl[ply:SteamID64()] to get their name.
That is what I thought to do but this has flaws like what if a guy changes the name mid-game without leaving? Also that DarkRP hook is for the /name thing, not steam name
[QUOTE=arcaneex;44939710]That is what I thought to do but this has flaws like what if a guy changes the name mid-game without leaving? Also that DarkRP hook is for the /name thing, not steam name[/QUOTE]
There must be a hook for player name change, TTT kicks you if you change your name, so there is a method of seeing if they change their name.
[QUOTE=AnonTakesOver;44939776]There must be a hook for player name change, TTT kicks you if you change your name, so there is a method of seeing if they change their name.[/QUOTE]
the same way hacks check if there is a player name change, store their id and name in a table upon connect, then check if their name has changed (and id is same)
[LUA]
local playernames = {}
timer.Create( "UpdatePlayerNames", 30, 0, function()
for _, ply in pairs( player.GetAll() ) do
local correct = playernames[ply:SteamID()] == ply:Nick()
if not correct then playernames[ply:SteamID()] = ply:Nick() end
end
end )
[/LUA]
then you can save playernames to whatever and use that
Track players: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect.lua.html[/url]
With the list implemented: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect_with_list_example.lua.html[/url]
There are ways to detect when a player changes their name mid-game using game-events: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/game_event_listeners.lua.html[/url]
For offline users, if you know the Steam you can do an HTTP Fetch for their info.
[QUOTE=Acecool;44939996]Track players: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect.lua.html[/url]
With the list implemented: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect_with_list_example.lua.html[/url]
There are ways to detect when a player changes their name mid-game using game-events: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/game_event_listeners.lua.html[/url]
For offline users, if you know the Steam you can do an HTTP Fetch for their info.[/QUOTE]
table.HasValue is inefficient
[QUOTE=john552;44940042]table.HasValue is inefficient[/QUOTE]
Of course it is, when you're calling it many many times each frame: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html[/url]
Now, if it is only being called when a player connects, then there is no issue. Also, how often do players change names? The table will be a size of 1 most likely. Also, all of the names need to be processed anyway if you want to keep a record of unique names; whether a loop is used to go through all, or table.HasValue is used, it doesn't matter - it is still O( n ).
[QUOTE=john552;44940042]table.HasValue is inefficient[/QUOTE]
if called multiple times very quickly, sure
the performance loss is inconsequential in this context.
there's absolutely no need to tack more code onto this <10 line problem
you're both forgetting the first rule of optimization
-snip, just realised you meant [I]Steam[/I] name-
Sorry, you need to Log In to post a reply to this thread.