From 4c424518594de72dc93de5a7ba2c26cd435e9751 Mon Sep 17 00:00:00 2001 From: bryce Date: Fri, 24 May 2024 15:47:13 -0400 Subject: [PATCH] Search by 1 type at a time --- gamemode/modules/base/sh_util.lua | 66 ++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/gamemode/modules/base/sh_util.lua b/gamemode/modules/base/sh_util.lua index 75b5cef98..d2bcec86b 100644 --- a/gamemode/modules/base/sh_util.lua +++ b/gamemode/modules/base/sh_util.lua @@ -58,28 +58,58 @@ end Find a player based on given information ---------------------------------------------------------------------------]] function DarkRP.findPlayer(info) - if not info or info == "" then return nil end - local pls = player.GetAll() - - for k = 1, #pls do -- Proven to be faster than pairs loop. - local v = pls[k] - if tonumber(info) == v:UserID() then - return v - end - - if info == v:SteamID() then - return v - end - - if string.find(string.lower(v:Nick()), string.lower(tostring(info)), 1, true) ~= nil then - return v + 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 + for k = 1, count do + local v = pls[k] + + if numberInfo == v:UserID() then -- darkrp relies on this being first + return v + end end - if string.find(string.lower(v:SteamName()), string.lower(tostring(info)), 1, true) ~= nil then - return v + for k = 1, count do -- this loop could likely be combined with the above loop + local v = pls[k] + + if info == v:SteamID64() then + return v + end end end - return nil + + if string.StartsWith(lowerInfo, "steam_") then + for k = 1, count do + local v = pls[k] + + if info == v:SteamID() then + return v + end + end + end + + for k = 1, count do + local v = pls[k] + + if string.find(string.lower(v:Nick()), lowerInfo, 1, true) ~= nil then + return v + end + end + + for k = 1, count do + local v = pls[k] + + if string.find(string.lower(v:SteamName()), lowerInfo, 1, true) ~= nil then + return v + end + end + + return nil end --[[---------------------------------------------------------------------------