mirror of
https://github.com/Resxt/Plutonium-T6-Scripts.git
synced 2025-04-19 21:52:54 +00:00
chat_commands 1.1.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
92761ce822
commit
55c89418c4
@ -520,6 +520,9 @@ FindPlayerByName(name)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
potentialPlayersFound = 0;
|
||||||
|
foundPlayer = undefined;
|
||||||
|
|
||||||
foreach (player in level.players)
|
foreach (player in level.players)
|
||||||
{
|
{
|
||||||
playerName = player.name;
|
playerName = player.name;
|
||||||
@ -529,10 +532,25 @@ FindPlayerByName(name)
|
|||||||
playerName = StrTok(playerName, "]")[1]; // ignore the clantag
|
playerName = StrTok(playerName, "]")[1]; // ignore the clantag
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ToLower(playerName) == ToLower(name))
|
if (ToLower(playerName) == ToLower(name)) // if we get an exact match return the player
|
||||||
{
|
{
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ToLower(GetSubStr(playerName, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user