mirror of
https://github.com/Resxt/Plutonium-IW5-Scripts.git
synced 2025-04-19 12:42:54 +00:00
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
This commit is contained in:
parent
64465a9cc9
commit
2efa784709
@ -497,27 +497,30 @@ FindPlayerByName(name)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
matchs = 0;
|
potentialPlayersFound = 0;
|
||||||
|
foundPlayer = undefined;
|
||||||
|
|
||||||
foreach (player in level.players)
|
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 (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
|
||||||
|
|
||||||
if( matchs == 1)
|
|
||||||
{
|
{
|
||||||
foreach (player in level.players)
|
return foundPlayer;
|
||||||
{
|
|
||||||
if( isSubStr( tolower( player.name), tolower(name ) ))
|
|
||||||
{
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user