Add player.GetBySteamID and player.GetBySteamID64 #888

Merged
merged 1 commit into from Apr 18, 2015

Projects

None yet

4 participants

@bmwalters
Contributor

We already have player.GetByUniqueID; having these functions is nice.
Unlike #846, the implementation of these functions is not subjective.

@TheFreeman193 TheFreeman193 commented on an outdated diff Mar 6, 2015
garrysmod/lua/includes/extensions/player.lua
@@ -52,7 +52,43 @@ function player.GetByUniqueID( ID )
if ( IsValid( pl ) && pl:IsPlayer() && pl:UniqueID() == ID ) then
return pl
end
-
+
+ end
+
+ return false
+
+end
+
+function player.GetBySteamID( ID )
+
+ ID = string.upper( ID )
+
+ assert( string.find( ID, "STEAM_" ), "player.GetBySteamID: passed string '" .. ID .. "' is not a valid steamid!" )
@TheFreeman193
TheFreeman193 Mar 6, 2015 Contributor

I recommend you use ID:StartWith("STEAM_") here; it's more relevant to SteamIDs, and it's also considerably quicker.

@bmwalters
Contributor

ID:StartWith("STEAM_") or string.find(ID, "^STEAM_")?

@TheFreeman193
Contributor

The former; I see no need for patterns/regex here since we're only looking for absolute text values.

@willox
Collaborator
willox commented Mar 6, 2015

If GetByUniqueID doesn't emit errors I believe GetBySteamID and GetBySteamID64 shouldn't either.

IsValid( pl ) && pl:IsPlayer() 

These checks aren't really necessary either.

@bmwalters
Contributor

Squashed commits.

@robotboy655 robotboy655 merged commit 9a21532 into garrynewman:master Apr 18, 2015
@bmwalters bmwalters deleted the unknown repository branch Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment