Skip to content

Commit

Permalink
Clean up comments and move assignment down
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Jun 16, 2024
1 parent 7d655da commit b4d82d3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gamemode/modules/base/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,37 @@ end

--[[---------------------------------------------------------------------------
Find a player based on given information
Note that there is a searching priority:
* UserID
* SteamID64
* SteamID
* Nick
* SteamName
Note also that there are _separate_ loops. This is to make sure the function
gives the same result, regardless of the order in which players are iterated
over.
---------------------------------------------------------------------------]]
function DarkRP.findPlayer(info)
if not info or info == "" then return nil end
local pls = player.GetAll()

local count = #pls
local numberInfo = tonumber(info)
local lowerInfo = string.lower(tostring(info))

if numberInfo then -- since we'll be doing alot of scanning, need to make sure
-- First check if the input matches a player by UserID or SteamID64. This is
-- only necessary if the input can be parsed as a number.
if numberInfo then
for k = 1, count do
local v = pls[k]

if numberInfo == v:UserID() then -- darkrp relies on this being first
if numberInfo == v:UserID() then
return v
end
end

for k = 1, count do -- this loop could likely be combined with the above loop
for k = 1, count do
local v = pls[k]

if info == v:SteamID64() then
Expand All @@ -83,6 +95,7 @@ function DarkRP.findPlayer(info)
end
end

local lowerInfo = string.lower(tostring(info))
if string.StartsWith(lowerInfo, "steam_") then
for k = 1, count do
local v = pls[k]
Expand Down

0 comments on commit b4d82d3

Please sign in to comment.