"Player not found!" error for ambiguous matches or offline playersSolved
In Rust when using /pm it often happens that I get a "Player not found!" error even tho the name or partial name is correct. It seems like this plugin searches in offline players too and if there are multiple matches it'd throw this error as well.

Recently I have had a player called "Nigward" who I couldn't PM, turns out there was another player "NIGWARD" who wasn't online but would be selected as the target, so there was no way for me to PM the online player.

The same happens when a player is called "Simon" and there was another player once on the server called "Simono" then it's impossible to PM Simon as Simono is always selected instead.

I suggest only scanning the active player list and prioritizing exact name matches over partial matches, like so:

// instead of
IPlayer target = covalence.Players.FindPlayer(args[0]);
// use
IPlayer target = BasePlayer.activePlayerList.Select(p => p.IPlayer).Where(p => p.Name == args[0]).FirstOrDefault()
    ?? BasePlayer.activePlayerList.Select(p => p.IPlayer).Where(p => p.Name.ToLower().Contains(args[0].ToLower())).FirstOrDefault();
This will first look for an exact match, to avoid confusion between "Simon" and "Simono", and, if no exact match was found, do a partial match and only use online players to lookup as it makes inherently no sense to PM offline players.
A simple IPlayer.IsConnected check would resolve the issue. Using Rust-specific code isn't a solution, as this plugin is universal.
okay, using FindPlayers in conjunction with IsConnected would solve the lookup of offline players, however to solve ambiguous names such as "Simon" and "Simono" the exact match needs to be executed too.

This is the best I could come up with:

IPlayer[] matches = covalence.Players.FindPlayers(args[0]).Where(p => p.IsConnected).ToArray();
IPlayer target = matches.Length == 1 ? matches[0] : matches.Where(p => p.Name == args[0]).FirstOrDefault();
Now it will only say "Player not found!" if no unique match was found or two players who are online have exactly the same name.

edit: nope I'm dumb, if there's multiple players with exactly the same name, it will select the first one from the list, which is usually the one who joined first, instead of giving an error.
I'll take a look at it when I get around to re-writing the plugin as my own.
This now only checks for people who are connected to the server.
Locked automatically