Finding a player by name?

Seems dead simple, but I can’t figure it out at the moment. If I give part of a player’s name, what’s the best way to take that player’s name, and for every player that matches the string of text, output the entity?

For example, I supply “shan”

There are 2 players on the server, shanda and shank. How would I find that out and then return back the entity?

[lua]
local function PlayerFromName( name )
local players = {}
for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( name ) then
table.insert( players, v )
end
end
return players
end
[/lua]

That’ll return a table of all players with the string in their name…

[lua]
local function PlayerFromName( name )
for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), string.lower( name ) then
return v
end
end
end
[/lua]

That’ll return a single player.

:3:

Thanks a ton, really helps now :slight_smile:

(I had a request to make a “ragequit” plugin for my server…)

You missed a ) in both of your examples.

[lua]if string.find(string.lower(v:Nick()), string.lower(name))[/lua]

oops… remind me to keep out of the lua section when I’m tired