From 64465a9cc9425636e660677ffd98a1193e24ed0f Mon Sep 17 00:00:00 2001 From: Chenterito <64875738+Chenterito@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:41:20 -0500 Subject: [PATCH 1/3] Update chat_commands.gsc Improve the "FindPlayerByName" function, the current one only finds the full name of the player and this is not practical in reality because players usually have long and difficult to write names, however the new function looks for a substring that matches the name of the player, which makes it much easier to search for the player's name as long as a unique substring is provided within the player's name. --- chat_commands/chat_commands.gsc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index b3b07c0..da9e20c 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -497,11 +497,26 @@ FindPlayerByName(name) return self; } + matchs = 0; + foreach (player in level.players) { - if (ToLower(player.name) == ToLower(name)) + if( isSubStr( tolower( player.name), tolower(name ) )) { - return player; + matchs++; + } + } + + wait 0.05; + + if( matchs == 1) + { + foreach (player in level.players) + { + if( isSubStr( tolower( player.name), tolower(name ) )) + { + return player; + } } } } @@ -739,4 +754,4 @@ DebugIsOn() PermissionIsEnabled() { return GetDvarInt("cc_permission_enabled"); -} \ No newline at end of file +} From 2efa784709b5c42811510c67c3e6a2fc5eb3fc70 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Mon, 9 Oct 2023 06:33:17 +0200 Subject: [PATCH 2/3] chat_commands 1.4.2 Added the ability to find players by typing a part of their name (starting from the beginning of their names) instead of having to type their full names all the time. For example to kill Resxt you can now just type !kill res If there is a player named Resxt and another named Resxtola then typing !kill resxt will kill Resxt because we got an exact match. If you type !kill Resx it won't kill anyone because there are two potential players found so we can't be sure who the command should be run on. If you type !kill Resxto it will kill Resxtola --- chat_commands/chat_commands.gsc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index da9e20c..f39c556 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -497,27 +497,30 @@ FindPlayerByName(name) return self; } - matchs = 0; + potentialPlayersFound = 0; + foundPlayer = undefined; foreach (player in level.players) { - if( isSubStr( tolower( player.name), tolower(name ) )) + if (ToLower(player.name) == ToLower(name)) // if we get an exact match return the player { - matchs++; + 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; } } - wait 0.05; - - if( matchs == 1) + 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 { - foreach (player in level.players) - { - if( isSubStr( tolower( player.name), tolower(name ) )) - { - return player; - } - } + return foundPlayer; } } From dc948d2f5cdb87c5d88d0facbf8deb4c87909823 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Mon, 9 Oct 2023 06:40:08 +0200 Subject: [PATCH 3/3] Update README.md --- chat_commands/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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