diff --git a/chat_commands/README.md b/chat_commands/README.md index 54107f4..640009e 100644 --- a/chat_commands/README.md +++ b/chat_commands/README.md @@ -22,7 +22,7 @@ You must install at least one command script to be able to use commands. Otherwi - A `commands` command that lists all available commands on the server you're on dynamically (only lists commands you have access to if the permission system is enabled) - A `help` command that explains how to use a given command. For example `help map` (only works on commands you have access to if the permission system is enabled) - `alias` and `aliases` commands that list the available aliases for a command. For example `alias godmode` (only works on commands you have access to if the permission system is enabled) -- All commands that require a target work with `me`. Also it doesn't matter how you type the player's name as long as you type the full name. +- All commands that require a target work with `me`. Also it doesn't matter how you type the player's name as long as you type his full name or type the beginning of his username (has to be unique, see [#3](https://github.com/Resxt/Plutonium-IW5-Scripts/pull/3/commits/2efa784709b5c42811510c67c3e6a2fc5eb3fc70)). - Configurable command prefix. Set to `!` by default - A plugin system to easily allow adding/removing commands. Each command has its own GSC file to easily add/remove/review/configure your commands. This also makes contributing by creating a PR to add a command a lot easier diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index b3b07c0..f39c556 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -497,12 +497,30 @@ FindPlayerByName(name) return self; } + potentialPlayersFound = 0; + foundPlayer = undefined; + foreach (player in level.players) { - if (ToLower(player.name) == ToLower(name)) + if (ToLower(player.name) == ToLower(name)) // if we get an exact match return the player { return player; } + + if (ToLower(GetSubStr(player.name, 0, name.size)) == ToLower(name)) // found a player who's name starts with the given text + { + potentialPlayersFound++; + } + + if (potentialPlayersFound == 1 && !IsDefined(foundPlayer)) // store the first player we find, since we only return one if and only if it only finds one + { + foundPlayer = player; + } + } + + if (potentialPlayersFound == 1) // we only found one player who's name starts with the given text so it's safe to return the player we found + { + return foundPlayer; } } @@ -739,4 +757,4 @@ DebugIsOn() PermissionIsEnabled() { return GetDvarInt("cc_permission_enabled"); -} \ No newline at end of file +}