Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited DarkRP.findPlayers to cycle from 1 to # #3250

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions gamemode/modules/base/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,27 @@ function DarkRP.findPlayers(info)
-- Playerinfo is always to be treated as UserID when it's a number
-- otherwise people with numbers in their names could get confused with UserID's of other players
if tonumber(PlayerInfo) then
if IsValid(Player(PlayerInfo)) and not found[Player(PlayerInfo)] then
found[Player(PlayerInfo)] = true
local foundPlayer = Player(PlayerInfo)
if IsValid(foundPlayer) and not found[foundPlayer] then
found[foundPlayer] = true
players = players or {}
table.insert(players, Player(PlayerInfo))
table.insert(players, foundPlayer)
end
continue
end

local stringPlayerInfo = string.lower(PlayerInfo)
for _, v in ipairs(pls) do
-- Prevend duplicates
-- Prevent duplicates
if found[v] then continue end
local steamId = v:SteamID()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SteamID was called twice per iteration, changing it to once and storing in a variable ain't much, but it also looks a bit nicer in the already long if-statement below.


-- Find by Steam ID
if (PlayerInfo == v:SteamID() or v:SteamID() == "UNKNOWN") or
if (PlayerInfo == steamId or steamId == "UNKNOWN") or
-- Find by Partial Nick
string.find(string.lower(v:Nick()), string.lower(tostring(PlayerInfo)), 1, true) ~= nil or
string.find(string.lower(v:Nick()), stringPlayerInfo, 1, true) ~= nil or
-- Find by steam name
(v.SteamName and string.find(string.lower(v:SteamName()), string.lower(tostring(PlayerInfo)), 1, true) ~= nil) then
(v.SteamName and string.find(string.lower(v:SteamName()), stringPlayerInfo, 1, true) ~= nil) then
found[v] = true
players = players or {}
table.insert(players, v)
Expand Down
Loading