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] 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 +}